PK!3Vodocsend/__init__.pyfrom .docsend import DocSend PK!^Fx$$docsend/cli.pyimport click from docsend import DocSend @click.command() @click.argument('doc_id') @click.option('-e', '--email', default=None, help='Email to authorize with') @click.option('-f', '--format', type=click.Choice(['pdf', 'png']), default='pdf', help='Save as PDF (default) or image sequence') @click.option('-o', '--output', default=None, help='Output file name') def main(doc_id, email, format, output): ds = DocSend(doc_id) ds.fetch_meta() if email: ds.authorize(email) ds.fetch_images() if output is None: output = f'docsend_{doc_id}.pdf' if format == 'pdf' else f'docsend_{doc_id}' if format == 'pdf': ds.save_pdf(output) elif format == 'png': ds.save_images(output) print(f'saved to {output}') if __name__ == '__main__': main() PK! G&&docsend/docsend.pyfrom concurrent.futures import ThreadPoolExecutor from io import BytesIO from pathlib import Path from PIL import Image from requests_html import HTMLSession class DocSend: def __init__(self, doc_id): self.doc_id = doc_id.rpartition('/')[-1] self.url = f'https://docsend.com/view/{doc_id}' self.s = HTMLSession() self.pool = ThreadPoolExecutor(16) def fetch_meta(self): r = self.s.get(self.url) r.raise_for_status() self.auth_token = r.html.find('input[@name="authenticity_token"]')[0].attrs['value'] self.pages = int(r.html.find('.document-thumb-container')[-1].attrs['data-page-num']) def authorize(self, email): form = { 'utf8': '✓', '_method': 'patch', 'authenticity_token': self.auth_token, 'link_auth_form[email]': email, 'commit': 'Continue', } f = self.s.post(self.url, data=form) f.raise_for_status() def fetch_images(self): self.image_urls = [] pool = ThreadPoolExecutor(self.pages) self.images = list(pool.map(self._fetch_image, range(1, self.pages + 1))) def _fetch_image(self, page): meta = self.s.get(f'{self.url}/page_data/{page}') meta.raise_for_status() data = self.s.get(meta.json()['imageUrl']) data.raise_for_status() return Image.open(BytesIO(data.content)) def save_pdf(self, name=None): self.images[0].save( name, format='PDF', append_images=self.images[1:], save_all=True ) def save_images(self, name): path = Path(name) path.mkdir(exist_ok=True) for page, image in enumerate(self.images, start=1): image.save(path / f'{page}.png', format='PNG') PK!HFR(,(docsend-0.1.3.dist-info/entry_points.txtN+I/N.,()JO.NKz9Vy\\PK!HlUTdocsend-0.1.3.dist-info/WHEEL HM K-*ϳR03rOK-J,/R(O-)T0343 /, (-JLR()*M IL*4KM̫PK!H52 docsend-0.1.3.dist-info/METADATAN0~=X)QZQ6(?gl]SԷ)ąwhw5̳ FpBGf Kh w5d+n?p tN p֣Hn´c"(>w&sQXȴ[cKxaڣDq%bIQ>J.]RM9-feɍ 7x@Yr=iY&0eeL)ϙ}O;t>l&fIuAD'ּGIubrw֫6rBY?PK!HZ8Udocsend-0.1.3.dist-info/RECORDu=w0὿hTq*h-]r(DBJ_t7mƙ D.s{ޠ:~^E-جUvME;hB2XeJ`>; Z.2D@5SKY'TO#wø41 sP;Z{femJFݼ4g=w*`]f2#`I=ИiFwTL^9/hL#ݣ%ڣX:vc% [x a%wٵ(P\b⥢<PK!3Vodocsend/__init__.pyPK!^Fx$$Ndocsend/cli.pyPK! G&&docsend/docsend.pyPK!HFR(,( docsend-0.1.3.dist-info/entry_points.txtPK!HlUTb docsend-0.1.3.dist-info/WHEELPK!H52  docsend-0.1.3.dist-info/METADATAPK!HZ8UG docsend-0.1.3.dist-info/RECORDPK