Better file name detection.
This commit is contained in:
@@ -3,6 +3,7 @@ import sys
|
|||||||
|
|
||||||
import bs4
|
import bs4
|
||||||
import requests
|
import requests
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from reportlab.pdfgen import canvas
|
from reportlab.pdfgen import canvas
|
||||||
|
|
||||||
@@ -13,11 +14,14 @@ def parse_args():
|
|||||||
parser = argparse.ArgumentParser(description=descr)
|
parser = argparse.ArgumentParser(description=descr)
|
||||||
parser.add_argument('url', metavar='url', nargs=1,
|
parser.add_argument('url', metavar='url', nargs=1,
|
||||||
help='the URL to slurp')
|
help='the URL to slurp')
|
||||||
parser.add_argument('--output', '-o', default='out.pdf',
|
parser.add_argument('--output', '-o', default=None,
|
||||||
help='the file to write to (default: out.pdf)')
|
help='the file to write to (default: out.pdf)')
|
||||||
|
|
||||||
return parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
if not args.output:
|
||||||
|
path = urlparse(args.url[0]).path
|
||||||
|
args.output = '%s.pdf'%path[path.find('/', 1) + 1:]
|
||||||
|
return args
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
@@ -31,7 +35,8 @@ def main():
|
|||||||
img_url = img.attrs["data-full"]
|
img_url = img.attrs["data-full"]
|
||||||
page_width, page_height = c._pagesize
|
page_width, page_height = c._pagesize
|
||||||
c.setPageRotation(90)
|
c.setPageRotation(90)
|
||||||
c.drawImage(img_url, 0, 0, page_height, page_width, preserveAspectRatio=True)
|
c.drawImage(img_url, 0, 0, page_height, page_width,
|
||||||
|
preserveAspectRatio=True)
|
||||||
c.showPage()
|
c.showPage()
|
||||||
c.save()
|
c.save()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user