mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Make code re-useable
This commit is contained in:
parent
d37f436c4c
commit
a067f1d519
@ -9,7 +9,7 @@ from xml.sax.saxutils import escape, quoteattr
|
|||||||
|
|
||||||
from calibre.utils.iso8601 import parse_iso8601
|
from calibre.utils.iso8601 import parse_iso8601
|
||||||
|
|
||||||
module_version = 4 # needed for live updates
|
module_version = 5 # needed for live updates
|
||||||
pprint
|
pprint
|
||||||
|
|
||||||
|
|
||||||
@ -185,15 +185,12 @@ def extract_html(soup):
|
|||||||
return json_to_html(raw)
|
return json_to_html(raw)
|
||||||
|
|
||||||
|
|
||||||
def download_url(url=None, br=None):
|
def download_url_from_wayback(category, url, br=None):
|
||||||
# Get the URL from the Wayback machine
|
|
||||||
from mechanize import Request
|
from mechanize import Request
|
||||||
host = 'http://localhost:8090'
|
host = 'http://localhost:8090'
|
||||||
host = 'https://wayback1.calibre-ebook.com'
|
host = 'https://wayback1.calibre-ebook.com'
|
||||||
if url is None:
|
|
||||||
url = sys.argv[-1]
|
|
||||||
rq = Request(
|
rq = Request(
|
||||||
host + '/nytimes',
|
host + '/' + category,
|
||||||
data=json.dumps({"url": url}),
|
data=json.dumps({"url": url}),
|
||||||
headers={'User-Agent': 'calibre', 'Content-Type': 'application/json'}
|
headers={'User-Agent': 'calibre', 'Content-Type': 'application/json'}
|
||||||
)
|
)
|
||||||
@ -204,6 +201,13 @@ def download_url(url=None, br=None):
|
|||||||
return br.open_novisit(rq, timeout=3 * 60).read()
|
return br.open_novisit(rq, timeout=3 * 60).read()
|
||||||
|
|
||||||
|
|
||||||
|
def download_url(url=None, br=None):
|
||||||
|
# Get the URL from the Wayback machine
|
||||||
|
if url is None:
|
||||||
|
url = sys.argv[-1]
|
||||||
|
return download_url_from_wayback('nytimes', url, br)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
f = sys.argv[-1]
|
f = sys.argv[-1]
|
||||||
raw = open(f).read()
|
raw = open(f).read()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user