Skip to content

Instantly share code, notes, and snippets.

@zeffii
Forked from anonymous/send_mult_gist.py
Created December 14, 2013 16:37
Show Gist options
  • Save zeffii/7961519 to your computer and use it in GitHub Desktop.
Save zeffii/7961519 to your computer and use it in GitHub Desktop.
import json
from urllib.request import urlopen
def main_upload_function(gists):
gist1, gist2 = gists
gist_post_data = { 'description': 'webdiff gists',
'public': True,
'files': { 'wdiff1': {'content': gist1},
'wdiff2': {'content': gist2}}
}
json_post_data = json.dumps(gist_post_data).encode('utf-8')
def get_gist_url(found_json):
wfile = json.JSONDecoder()
wjson = wfile.decode(found_json)
gist_url = 'https://gist.github.com/' + wjson['id']
import webbrowser
print(gist_url)
webbrowser.open(gist_url)
# or just copy url to clipboard?
def upload_gist():
print('sending')
url = 'https://api.github.com/gists'
json_to_parse = urlopen(url, data=json_post_data)
print('received response from server')
found_json = json_to_parse.readall().decode()
get_gist_url(found_json)
upload_gist()
gist_body_1 = "this is \ngist body 1"
gist_body_2 = "this is \ngist body 2"
gists = gist_body_1, gist_body_2
main_upload_function(gists)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment