Skip to content

Instantly share code, notes, and snippets.

@andreiw
Last active December 22, 2016 05:34
Show Gist options
  • Save andreiw/d445dcd6aae8218728aa13d5c3d23b77 to your computer and use it in GitHub Desktop.
Save andreiw/d445dcd6aae8218728aa13d5c3d23b77 to your computer and use it in GitHub Desktop.
Pythonista extension to import URL as Python script
import appex
import clipboard
import urllib3
import os
def main():
if not appex.is_running_extension():
print('This script is intended to be run from the sharing extension.')
return
url = appex.get_url()
if not url:
print('No URL?')
return
fname = url.split('/')[-1]
fname, fext = os.path.splitext(fname)
if fext != ".py":
fext = ".py"
fname = fname + fext
fname = os.path.join(os.path.expanduser('~/Documents'), fname)
http = urllib3.PoolManager()
response = http.request('GET', url)
with open(fname, 'wb') as f:
f.write(response.data)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment