itransferwee.py: Address flake8 warnings/errors - 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 d6c2f12ba0e84b963b1528bf061579665aee00a5 /r/transferwee/commit/d6c2f12ba0e84b963b1528bf061579665aee00a5.gph tccr.it 70 1parent 70f63eeb899a215c897ea0a8fb7cefd3945d27c6 /r/transferwee/commit/70f63eeb899a215c897ea0a8fb7cefd3945d27c6.gph tccr.it 70 hAuthor: Leonardo Taccari URL:mailto:iamleot@gmail.com tccr.it 70 iDate: Sun, 13 May 2018 23:44:19 +0200 Err tccr.it 70 i Err tccr.it 70 itransferwee.py: Address flake8 warnings/errors Err tccr.it 70 i Err tccr.it 70 iDiffstat: Err tccr.it 70 i M transferwee.py | 59 +++++++++++++++++-------------- Err tccr.it 70 i Err tccr.it 70 i1 file changed, 33 insertions(+), 26 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@@ -63,8 +63,8 @@ def download_url(url: str) -> str: Err tccr.it 70 i """Given a wetransfer.com download URL download return the downloadable URL. Err tccr.it 70 i Err tccr.it 70 i The URL should be of the form `https://we.tl/' or Err tccr.it 70 i- `https://wetransfer.com/downloads/'. If it is a short URL (i.e. `we.tl') the Err tccr.it 70 i- redirect is followed in order to retrieve the corresponding Err tccr.it 70 i+ `https://wetransfer.com/downloads/'. If it is a short URL (i.e. `we.tl') Err tccr.it 70 i+ the redirect is followed in order to retrieve the corresponding Err tccr.it 70 i `wetransfer.com/downloads/' URL. Err tccr.it 70 i Err tccr.it 70 i The following type of URLs are supported: Err tccr.it 70 i@@ -98,7 +98,8 @@ def download_url(url: str) -> str: Err tccr.it 70 i } Err tccr.it 70 i if recipient_id: Err tccr.it 70 i j["recipient_id"] = recipient_id Err tccr.it 70 i- r = requests.post(WETRANSFER_DOWNLOAD_URL.format(transfer_id=transfer_id), json=j) Err tccr.it 70 i+ r = requests.post(WETRANSFER_DOWNLOAD_URL.format(transfer_id=transfer_id), Err tccr.it 70 i+ json=j) Err tccr.it 70 i Err tccr.it 70 i j = r.json() Err tccr.it 70 i return j.get('direct_link') Err tccr.it 70 i@@ -124,7 +125,7 @@ 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 the email upload. Err tccr.it 70 i- 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 j = { Err tccr.it 70 i@@ -141,7 +142,7 @@ def _prepare_email_upload(filenames: List[str], message: str, Err tccr.it 70 i Err tccr.it 70 i def _prepare_link_upload(filenames: List[str], message: str) -> str: Err tccr.it 70 i """Given a list of filenames and a message prepare for the link upload. Err tccr.it 70 i- 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 j = { Err tccr.it 70 i@@ -167,7 +168,8 @@ def _prepare_file_upload(transfer_id: str, file: str) -> str: Err tccr.it 70 i "size": filesize Err tccr.it 70 i } Err tccr.it 70 i Err tccr.it 70 i- r = requests.post(WETRANSFER_FILES_URL.format(transfer_id=transfer_id), json=j) 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 i Err tccr.it 70 i Err tccr.it 70 i@@ -195,25 +197,24 @@ def _upload_chunks(transfer_id: str, file_id: str, file: str, Err tccr.it 70 i } Err tccr.it 70 i Err tccr.it 70 i r = requests.post( Err tccr.it 70 i- WETRANSFER_PART_PUT_URL.format(transfer_id=transfer_id, file_id=file_id), Err tccr.it 70 i- json=j Err tccr.it 70 i- ) Err tccr.it 70 i+ WETRANSFER_PART_PUT_URL.format(transfer_id=transfer_id, Err tccr.it 70 i+ file_id=file_id), Err tccr.it 70 i+ json=j) Err tccr.it 70 i url = r.json().get('url') Err tccr.it 70 i r = requests.options(url, Err tccr.it 70 i- headers={ Err tccr.it 70 i- 'Origin': 'https://wetransfer.com', Err tccr.it 70 i- 'Access-Control-Request-Method': 'PUT', Err tccr.it 70 i- } Err tccr.it 70 i- ) Err tccr.it 70 i+ headers={ Err tccr.it 70 i+ 'Origin': 'https://wetransfer.com', Err tccr.it 70 i+ 'Access-Control-Request-Method': 'PUT', Err tccr.it 70 i+ }) Err tccr.it 70 i r = requests.put(url, data=chunk) Err tccr.it 70 i Err tccr.it 70 i j = { Err tccr.it 70 i 'chunk_count': chunk_number Err tccr.it 70 i } Err tccr.it 70 i r = requests.put( Err tccr.it 70 i- WETRANSFER_FINALIZE_MPP_URL.format(transfer_id=transfer_id, file_id=file_id), Err tccr.it 70 i- json=j Err tccr.it 70 i- ) Err tccr.it 70 i+ WETRANSFER_FINALIZE_MPP_URL.format(transfer_id=transfer_id, Err tccr.it 70 i+ file_id=file_id), Err tccr.it 70 i+ json=j) Err tccr.it 70 i Err tccr.it 70 i return r.json() Err tccr.it 70 i Err tccr.it 70 i@@ -235,8 +236,8 @@ def upload(files: List[str], message: str = '', sender: str = None, Err tccr.it 70 i Also accepts optional parameters: Err tccr.it 70 i - `message': message used as a description of the transfer Err tccr.it 70 i - `sender': email address used to receive an ACK if the upload is Err tccr.it 70 i- successfull. For every download by the recipients an email will Err tccr.it 70 i- be also sent Err tccr.it 70 i+ successfull. For every download by the recipients an email Err tccr.it 70 i+ will be also sent Err tccr.it 70 i - `recipients': list of email addresses of recipients. When the upload Err tccr.it 70 i succeed every recipients will receive an email with a link Err tccr.it 70 i Err tccr.it 70 i@@ -251,8 +252,9 @@ def upload(files: List[str], message: str = '', sender: str = None, Err tccr.it 70 i if not os.path.exists(f): Err tccr.it 70 i return None Err tccr.it 70 i Err tccr.it 70 i- # Check that there are no duplicates filenames (despite different dirname()) Err tccr.it 70 i- filenames = [ os.path.basename(f) for f in files ] Err tccr.it 70 i+ # Check that there are no duplicates filenames Err tccr.it 70 i+ # (despite possible different dirname()) Err tccr.it 70 i+ filenames = [os.path.basename(f) for f in files] Err tccr.it 70 i if len(files) != len(set(filenames)): Err tccr.it 70 i return None Err tccr.it 70 i Err tccr.it 70 i@@ -283,15 +285,20 @@ if __name__ == '__main__': Err tccr.it 70 i Err tccr.it 70 i # download subcommand Err tccr.it 70 i dp = sp.add_parser('download', help='download files') Err tccr.it 70 i- dp.add_argument('-g', action='store_true', help='only print the direct link (without downloading it)') Err tccr.it 70 i- dp.add_argument('url', nargs='+', type=str, metavar='url', help='URL (we.tl/... or wetransfer.com/downloads/...)') Err tccr.it 70 i+ dp.add_argument('-g', action='store_true', Err tccr.it 70 i+ help='only print the direct link (without downloading it)') Err tccr.it 70 i+ dp.add_argument('url', nargs='+', type=str, metavar='url', Err tccr.it 70 i+ help='URL (we.tl/... or wetransfer.com/downloads/...)') Err tccr.it 70 i Err tccr.it 70 i # upload subcommand Err tccr.it 70 i up = sp.add_parser('upload', help='upload files') Err tccr.it 70 i- up.add_argument('-m', type=str, default='', metavar='message', help='message description for the transfer') Err tccr.it 70 i+ up.add_argument('-m', type=str, default='', metavar='message', Err tccr.it 70 i+ help='message description for the transfer') Err tccr.it 70 i up.add_argument('-f', type=str, metavar='from', help='sender email') Err tccr.it 70 i- up.add_argument('-t', nargs='+', type=str, metavar='to', help='recipient emails') Err tccr.it 70 i- up.add_argument('files', nargs='+', type=str, metavar='file', help='files to upload') Err tccr.it 70 i+ up.add_argument('-t', nargs='+', type=str, metavar='to', Err tccr.it 70 i+ help='recipient emails') Err tccr.it 70 i+ up.add_argument('files', nargs='+', type=str, metavar='file', Err tccr.it 70 i+ help='files to upload') Err tccr.it 70 i Err tccr.it 70 i args = ap.parse_args() Err tccr.it 70 i Err tccr.it 70 .