Skip to content

Instantly share code, notes, and snippets.

@tzangms
Created November 21, 2012 02:59
Show Gist options
  • Save tzangms/4122748 to your computer and use it in GitHub Desktop.
Save tzangms/4122748 to your computer and use it in GitHub Desktop.
put.io upload
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)
@tzangms
Copy link
Author

tzangms commented Nov 21, 2012

you can execute this script within safari

pythonista://PutIOUpload.py?actiion=run&argv=http://the_file_url_for_download

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment