Created
December 21, 2018 04:17
-
-
Save paultopia/abb046ca191651cd59b79aec04b28b33 to your computer and use it in GitHub Desktop.
download_file_to_icloud.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# simple pythonista/shortcuts file download to stream big files to disk from the phone | |
# 1. create a "downloads" directory in your icloud folder in the pythonista app. | |
# 2. install this shortcut: https://www.icloud.com/shortcuts/d397a0fedef74d29a5b735c371c11f89 | |
# 3. save this script in your local files in pythonista | |
# then you can long press on a url and have pythonista download it and dump it in icloud. | |
import shutil, os, requests, sys, uuid | |
from urllib.parse import urlparse | |
url = sys.argv[-1] | |
dir = "/private/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents/downloads/" | |
def get_filename(url): | |
filename = os.path.basename(urlparse(url).path) | |
return dir + filename | |
def get_uiid_filename(url): | |
filename = os.path.basename(urlparse(url).path) | |
return dir + uuid.uuid4().hex + filename | |
def download_url(url): | |
response = requests.get(url, stream=True) | |
filename = get_filename(url) | |
if os.path.exists(filename): | |
filename = get_uiid_filename(url) | |
with open(filename, 'wb') as out_file: | |
shutil.copyfileobj(response.raw, out_file) | |
del response | |
if __name__ == '__main__': | |
download_url(url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment