Refactor again
This commit is contained in:
parent
79f847316c
commit
682aa72031
5
app.py
5
app.py
@ -52,5 +52,6 @@ def admin():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app_debug = environ.get('FLASK_ENV', 'production') is 'development'
|
app_debug = environ.get('FLASK_ENV', 'production') == 'development'
|
||||||
app.run('0.0.0.0', debug=app_debug)
|
app_port = environ.get('FLASK_PORT', 5000)
|
||||||
|
app.run('0.0.0.0', app_port, app_debug)
|
||||||
|
@ -23,7 +23,7 @@ class Connector(ABC):
|
|||||||
self.category = category
|
self.category = category
|
||||||
self.data = []
|
self.data = []
|
||||||
self.is_more = False
|
self.is_more = False
|
||||||
self.on_error = False
|
self.on_error = True
|
||||||
self.page = page
|
self.page = page
|
||||||
self.return_type = return_type
|
self.return_type = return_type
|
||||||
|
|
||||||
@ -32,19 +32,18 @@ class Connector(ABC):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def __search(self):
|
def search(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
def get_history(self):
|
||||||
def __get_history(self):
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
if not len(self.data):
|
if self.on_error:
|
||||||
if self.return_type is ConnectorReturn.SEARCH:
|
if self.return_type is ConnectorReturn.SEARCH:
|
||||||
self.__search()
|
self.search()
|
||||||
elif self.return_type is ConnectorReturn.HISTORY:
|
elif self.return_type is ConnectorReturn.HISTORY:
|
||||||
self.__get_history()
|
self.get_history()
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def curl_content(self, url, params=None, ajax=False):
|
def curl_content(self, url, params=None, ajax=False):
|
||||||
@ -116,10 +115,11 @@ class Nyaa(Connector):
|
|||||||
to_query = '(%s vf)|(%s vostfr)|(%s multi)|(%s french)' % (self.query, self.query, self.query, self.query)
|
to_query = '(%s vf)|(%s vostfr)|(%s multi)|(%s french)' % (self.query, self.query, self.query, self.query)
|
||||||
return '%s/?f=0&c=1_3&s=%s&o=desc&q=%s&p=%s' % (self.base_url, sort_type, to_query, self.page)
|
return '%s/?f=0&c=1_3&s=%s&o=desc&q=%s&p=%s' % (self.base_url, sort_type, to_query, self.page)
|
||||||
|
|
||||||
def __get_history(self):
|
def get_history(self):
|
||||||
self.__search()
|
self.search()
|
||||||
|
|
||||||
def __search(self):
|
def search(self):
|
||||||
|
if self.on_error:
|
||||||
response = self.curl_content(self.get_full_search_url())
|
response = self.curl_content(self.get_full_search_url())
|
||||||
|
|
||||||
if response['http_code'] is 200:
|
if response['http_code'] is 200:
|
||||||
@ -156,7 +156,8 @@ class Nyaa(Connector):
|
|||||||
'name': self.boldify(url.string),
|
'name': self.boldify(url.string),
|
||||||
'comment': str(urls[0]).replace('/view/',
|
'comment': str(urls[0]).replace('/view/',
|
||||||
'%s%s' % (self.base_url, '/view/')) if has_comment else '',
|
'%s%s' % (self.base_url, '/view/')) if has_comment else '',
|
||||||
'link': tds[2].decode_contents().replace('/download/', '%s%s' % (self.base_url, '/download/')),
|
'link': tds[2].decode_contents().replace('/download/',
|
||||||
|
'%s%s' % (self.base_url, '/download/')),
|
||||||
'size': tds[3].string,
|
'size': tds[3].string,
|
||||||
'date': '%s:00' % tds[4].string,
|
'date': '%s:00' % tds[4].string,
|
||||||
'seeds': check_seeds,
|
'seeds': check_seeds,
|
||||||
@ -165,9 +166,8 @@ class Nyaa(Connector):
|
|||||||
'class': 'is-%s' % tr['class'][0]
|
'class': 'is-%s' % tr['class'][0]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
self.on_error = False
|
||||||
self.is_more = valid_trs is not len(trs)
|
self.is_more = valid_trs is not len(trs)
|
||||||
else:
|
|
||||||
self.on_error = True
|
|
||||||
|
|
||||||
|
|
||||||
class Pantsu(Connector):
|
class Pantsu(Connector):
|
||||||
@ -184,10 +184,11 @@ class Pantsu(Connector):
|
|||||||
to_query = '(%s vf)|(%s vostfr)|(%s multi)|(%s french)' % (self.query, self.query, self.query, self.query)
|
to_query = '(%s vf)|(%s vostfr)|(%s multi)|(%s french)' % (self.query, self.query, self.query, self.query)
|
||||||
return '%s/search/%s?c=3_13&order=false&q=%s&sort=%s' % (self.base_url, self.page, to_query, sort_type)
|
return '%s/search/%s?c=3_13&order=false&q=%s&sort=%s' % (self.base_url, self.page, to_query, sort_type)
|
||||||
|
|
||||||
def __get_history(self):
|
def get_history(self):
|
||||||
self.__search()
|
self.search()
|
||||||
|
|
||||||
def __search(self):
|
def search(self):
|
||||||
|
if self.on_error:
|
||||||
response = self.curl_content(self.get_full_search_url())
|
response = self.curl_content(self.get_full_search_url())
|
||||||
|
|
||||||
if response['http_code'] is 200:
|
if response['http_code'] is 200:
|
||||||
@ -229,9 +230,8 @@ class Pantsu(Connector):
|
|||||||
'class': 'is-%s' % tr['class'][0]
|
'class': 'is-%s' % tr['class'][0]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
self.on_error = False
|
||||||
self.is_more = valid_trs is not len(trs)
|
self.is_more = valid_trs is not len(trs)
|
||||||
else:
|
|
||||||
self.on_error = True
|
|
||||||
|
|
||||||
|
|
||||||
class YggTorrent(Connector):
|
class YggTorrent(Connector):
|
||||||
@ -249,13 +249,11 @@ class YggTorrent(Connector):
|
|||||||
self.base_url, sort_type, self.category, self.query, self.page
|
self.base_url, sort_type, self.category, self.query, self.page
|
||||||
)
|
)
|
||||||
|
|
||||||
def __get_history(self):
|
def get_history(self):
|
||||||
self.__search()
|
self.search()
|
||||||
|
|
||||||
def __search(self):
|
def search(self):
|
||||||
if self.category is None:
|
if self.category and self.on_error:
|
||||||
self.on_error = True
|
|
||||||
else:
|
|
||||||
response = self.curl_content(self.get_full_search_url())
|
response = self.curl_content(self.get_full_search_url())
|
||||||
|
|
||||||
if response['http_code'] is 200:
|
if response['http_code'] is 200:
|
||||||
@ -285,8 +283,9 @@ class YggTorrent(Connector):
|
|||||||
'name': self.boldify(url.string),
|
'name': self.boldify(url.string),
|
||||||
'comment': '<a href="%s#comm" target="_blank"><i class="fa fa-comments-o"></i>%s</a>' %
|
'comment': '<a href="%s#comm" target="_blank"><i class="fa fa-comments-o"></i>%s</a>' %
|
||||||
(url['href'], tds[3].string),
|
(url['href'], tds[3].string),
|
||||||
'link': '<a href="%s/engine/download_torrent?id=%s"><i class="fa fa-fw fa-download"></i></a>' %
|
'link': '<a href="%s/engine/download_torrent?id=%s">'
|
||||||
(self.base_url, re.search(r'/(\d+)', url['href']).group(1)),
|
'<i class="fa fa-fw fa-download"></i>'
|
||||||
|
'</a>' % (self.base_url, re.search(r'/(\d+)', url['href']).group(1)),
|
||||||
'size': tds[5].string,
|
'size': tds[5].string,
|
||||||
'date': datetime.fromtimestamp(int(tds[4].div.string)).strftime('%Y-%m-%d %H:%M:%S'),
|
'date': datetime.fromtimestamp(int(tds[4].div.string)).strftime('%Y-%m-%d %H:%M:%S'),
|
||||||
'seeds': check_seeds,
|
'seeds': check_seeds,
|
||||||
@ -295,9 +294,8 @@ class YggTorrent(Connector):
|
|||||||
'class': ''
|
'class': ''
|
||||||
})
|
})
|
||||||
|
|
||||||
|
self.on_error = False
|
||||||
self.is_more = valid_trs is not len(trs)
|
self.is_more = valid_trs is not len(trs)
|
||||||
else:
|
|
||||||
self.on_error = True
|
|
||||||
|
|
||||||
|
|
||||||
class AnimeUltime(Connector):
|
class AnimeUltime(Connector):
|
||||||
@ -317,7 +315,8 @@ class AnimeUltime(Connector):
|
|||||||
|
|
||||||
return '%s/%s-0-1/%s' % (self.base_url, sort_type, from_date)
|
return '%s/%s-0-1/%s' % (self.base_url, sort_type, from_date)
|
||||||
|
|
||||||
def __search(self):
|
def search(self):
|
||||||
|
if self.on_error:
|
||||||
response = self.curl_content(self.get_full_search_url(), {'search': self.query})
|
response = self.curl_content(self.get_full_search_url(), {'search': self.query})
|
||||||
|
|
||||||
if response['http_code'] is 200:
|
if response['http_code'] is 200:
|
||||||
@ -351,14 +350,15 @@ class AnimeUltime(Connector):
|
|||||||
|
|
||||||
self.data.append({
|
self.data.append({
|
||||||
'lang': 'jp',
|
'lang': 'jp',
|
||||||
'href': '%s%s' % (self.get_file_url(), player[0]['data-serie']),
|
'href': '%s/file-0-1/%s' % (self.base_url, player[0]['data-serie']),
|
||||||
'name': self.boldify(name[0].string),
|
'name': self.boldify(name[0].string),
|
||||||
'type': ani_type[0].string.replace(':', '')
|
'type': ani_type[0].string.replace(':', '')
|
||||||
})
|
})
|
||||||
else:
|
|
||||||
self.on_error = True
|
|
||||||
|
|
||||||
def __get_history(self):
|
self.on_error = False
|
||||||
|
|
||||||
|
def get_history(self):
|
||||||
|
if self.on_error:
|
||||||
response = self.curl_content(self.get_full_search_url())
|
response = self.curl_content(self.get_full_search_url())
|
||||||
|
|
||||||
if response['http_code'] is 200:
|
if response['http_code'] is 200:
|
||||||
@ -381,12 +381,14 @@ class AnimeUltime(Connector):
|
|||||||
|
|
||||||
self.data.append({
|
self.data.append({
|
||||||
'lang': 'jp',
|
'lang': 'jp',
|
||||||
'href': '%s%s' % (self.get_full_search_url('file'), link['href']),
|
'href': '%s/%s' % (self.base_url, link['href']),
|
||||||
'name': link.string,
|
'name': link.string,
|
||||||
'type': tds[4].string,
|
'type': tds[4].string,
|
||||||
'date': release_date
|
'date': release_date
|
||||||
})
|
})
|
||||||
|
|
||||||
|
self.on_error = False
|
||||||
|
|
||||||
|
|
||||||
class Other(Connector):
|
class Other(Connector):
|
||||||
color = 'is-danger'
|
color = 'is-danger'
|
||||||
@ -396,8 +398,8 @@ class Other(Connector):
|
|||||||
def get_full_search_url(self):
|
def get_full_search_url(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def __search(self):
|
def search(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def __get_history(self):
|
def get_history(self):
|
||||||
pass
|
pass
|
||||||
|
@ -5,11 +5,12 @@ services:
|
|||||||
build: .
|
build: .
|
||||||
ports:
|
ports:
|
||||||
- "5000:5000"
|
- "5000:5000"
|
||||||
entrypoint: flask run -h 0.0.0.0
|
entrypoint: python3 app.py
|
||||||
working_dir: /app
|
working_dir: /app
|
||||||
environment:
|
environment:
|
||||||
FLASK_APP: app.py
|
FLASK_APP: app.py
|
||||||
FLASK_ENV: development
|
FLASK_ENV: development
|
||||||
|
FLASK_PORT: 5000
|
||||||
MYSQL_USER: root
|
MYSQL_USER: root
|
||||||
MYSQL_PASSWORD: root
|
MYSQL_PASSWORD: root
|
||||||
MYSQL_DATABASE: www
|
MYSQL_DATABASE: www
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
{% for connector in connectors %}
|
{% for connector in connectors %}
|
||||||
{% for torrent in connector.data %}
|
{% for torrent in connector.data %}
|
||||||
|
|
||||||
{% enfor %}
|
{% endfor %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
</tbody>
|
</tbody>
|
||||||
|
Reference in New Issue
Block a user