Created
November 21, 2012 02:59
-
-
Save tzangms/4122748 to your computer and use it in GitHub Desktop.
put.io upload
This file contains 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
import sys | |
import requests | |
import urllib | |
PUTIO_ACCESS_TOKEN = '<token>' | |
PUTIO_API_URL = 'https://api.put.io/v2/files/upload' | |
url = sys.argv[1] | |
filename = url.rsplit('/', 1)[1] | |
# ============================ | |
# Download and save the file | |
# ============================ | |
print("Download and save the file.") | |
r = requests.get(url) | |
with open(filename, 'w+') as f: | |
f.write(r.content) | |
# ============================ | |
# Upload your file to put.io | |
# ============================ | |
print("Upload your file to put.io") | |
params = urllib.urlencode({'oauth_token': PUTIO_ACCESS_TOKEN}) | |
files = {'file': open(filename, 'rb')} | |
r = requests.post(PUTIO_API_URL + '?' + params, files=files) | |
if r.status_code == 200: | |
print("Finished!") | |
else: | |
print("Upload to put.io failed!\n%s" % r.content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you can execute this script within safari
pythonista://PutIOUpload.py?actiion=run&argv=http://the_file_url_for_download