iAdjust `.../email' and `.../link' uploads _prepare_{email,link}_upload() - transferwee - Download/upload file via wetransfer.com Err tccr.it 70 hgit clone https://github.com/iamleot/transferwee URL:https://github.com/iamleot/transferwee tccr.it 70 1Log /r/transferwee/log.gph tccr.it 70 1Files /r/transferwee/files.gph tccr.it 70 1Refs /r/transferwee/refs.gph tccr.it 70 1README /r/transferwee/file/README.md.gph tccr.it 70 i--- Err tccr.it 70 1commit 2f96ab33a51812a830e4d36a8d60982b3cdd73f9 /r/transferwee/commit/2f96ab33a51812a830e4d36a8d60982b3cdd73f9.gph tccr.it 70 1parent 15e83d26b305044188428e9d17977d99d0d6b513 /r/transferwee/commit/15e83d26b305044188428e9d17977d99d0d6b513.gph tccr.it 70 hAuthor: Leonardo Taccari URL:mailto:iamleot@gmail.com tccr.it 70 iDate: Tue, 26 Mar 2019 19:24:19 +0100 Err tccr.it 70 i Err tccr.it 70 iAdjust `.../email' and `.../link' uploads _prepare_{email,link}_upload() Err tccr.it 70 i Err tccr.it 70 iThe API for `.../email' and `.../link' no longer expects just Err tccr.it 70 ifilenames but a list of files where the files contain their basename Err tccr.it 70 iand their size. Err tccr.it 70 i Err tccr.it 70 iIntroduce a _file_name_and_size() method to return such dict and use it in Err tccr.it 70 i_prepare_{email,link}_upload() and _prepare_file_upload(). Err tccr.it 70 i Err tccr.it 70 iDiffstat: Err tccr.it 70 i M transferwee.py | 29 ++++++++++++++++++----------- Err tccr.it 70 i Err tccr.it 70 i1 file changed, 18 insertions(+), 11 deletions(-) Err tccr.it 70 i--- Err tccr.it 70 1diff --git a/transferwee.py b/transferwee.py /r/transferwee/file/transferwee.py.gph tccr.it 70 i@@ -1,7 +1,7 @@ Err tccr.it 70 i #!/usr/bin/env python3.7 Err tccr.it 70 i Err tccr.it 70 i # Err tccr.it 70 i-# Copyright (c) 2018 Leonardo Taccari Err tccr.it 70 i+# Copyright (c) 2018-2019 Leonardo Taccari Err tccr.it 70 i # All rights reserved. Err tccr.it 70 i # Err tccr.it 70 i # Redistribution and use in source and binary forms, with or without Err tccr.it 70 i@@ -124,6 +124,20 @@ def download(url: str) -> None: Err tccr.it 70 i f.write(chunk) Err tccr.it 70 i Err tccr.it 70 i Err tccr.it 70 i+def _file_name_and_size(file: str) -> dict: Err tccr.it 70 i+ """Given a file, prepare the "name" and "size" dictionary. Err tccr.it 70 i+ Err tccr.it 70 i+ Return a dictionary with "name" and "size" keys. Err tccr.it 70 i+ """ Err tccr.it 70 i+ filename = os.path.basename(file) Err tccr.it 70 i+ filesize = os.path.getsize(file) Err tccr.it 70 i+ Err tccr.it 70 i+ return { Err tccr.it 70 i+ "name": filename, Err tccr.it 70 i+ "size": filesize Err tccr.it 70 i+ } Err tccr.it 70 i+ Err tccr.it 70 i+ Err tccr.it 70 i def _prepare_email_upload(filenames: List[str], message: str, Err tccr.it 70 i sender: str, recipients: List[str]) -> str: Err tccr.it 70 i """Given a list of filenames, message a sender and recipients prepare for Err tccr.it 70 i@@ -132,7 +146,7 @@ def _prepare_email_upload(filenames: List[str], message: str, Err tccr.it 70 i Return the parsed JSON response. Err tccr.it 70 i """ Err tccr.it 70 i j = { Err tccr.it 70 i- "filenames": filenames, Err tccr.it 70 i+ "files": [_file_name_and_size(f) for f in filenames], Err tccr.it 70 i "from": sender, Err tccr.it 70 i "message": message, Err tccr.it 70 i "recipients": recipients, Err tccr.it 70 i@@ -149,7 +163,7 @@ def _prepare_link_upload(filenames: List[str], message: str) -> str: Err tccr.it 70 i Return the parsed JSON response. Err tccr.it 70 i """ Err tccr.it 70 i j = { Err tccr.it 70 i- "filenames": filenames, Err tccr.it 70 i+ "files": [_file_name_and_size(f) for f in filenames], Err tccr.it 70 i "message": message, Err tccr.it 70 i "ui_language": "en", Err tccr.it 70 i } Err tccr.it 70 i@@ -163,14 +177,7 @@ def _prepare_file_upload(transfer_id: str, file: str) -> str: Err tccr.it 70 i Err tccr.it 70 i Return the parsed JSON response. Err tccr.it 70 i """ Err tccr.it 70 i- filename = os.path.basename(file) Err tccr.it 70 i- filesize = os.path.getsize(file) Err tccr.it 70 i- Err tccr.it 70 i- j = { Err tccr.it 70 i- "name": filename, Err tccr.it 70 i- "size": filesize Err tccr.it 70 i- } Err tccr.it 70 i- Err tccr.it 70 i+ j = _file_name_and_size(file) Err tccr.it 70 i r = requests.post(WETRANSFER_FILES_URL.format(transfer_id=transfer_id), Err tccr.it 70 i json=j) Err tccr.it 70 i return r.json() Err tccr.it 70 .