-
-
Save martinandersen3d/e63e194991c707f1ea28824d733526a1 to your computer and use it in GitHub Desktop.
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
import urllib2 | |
import json | |
import sys | |
import os | |
from Tkinter import Tk | |
URL="https://api.github.com/gists" | |
TOKEN="" | |
args = sys.argv[:] | |
args.pop(0) | |
files = {} | |
if len(args)>0: | |
for filename in args: | |
with open(filename,'rb') as file: | |
files[os.path.split(filename)[1]] = {"content": file.read()} | |
else: | |
good = False | |
tk = Tk() | |
tk.withdraw() | |
try: | |
cb = tk.clipboard_get() | |
files[""] = {"content": cb} # sys.stdin.read() | |
good = True | |
except: | |
pass | |
tk.destroy() | |
if not good: | |
print('not normal text') | |
import win32clipboard as c | |
c.OpenClipboard() | |
try: | |
format = c.RegisterClipboardFormat('FileName') | |
if c.IsClipboardFormatAvailable(format): | |
filename = c.GetClipboardData(format)[:-1] # hacks | |
with open(filename,'rb') as file: | |
files[os.path.split(filename)[1]] = {"content": file.read()} | |
good = True | |
except: | |
pass | |
c.CloseClipboard() | |
if not good: | |
print('noon') | |
exit(1) | |
o = { | |
"description": "", | |
"public": False, | |
"files": files | |
} | |
req = urllib2.Request(URL,json.dumps(o)) | |
req.add_header('Authorization','token '+TOKEN) | |
resp = urllib2.urlopen(req) | |
r = json.load(resp) | |
resp.close() | |
url = r['html_url'] | |
print(url) | |
tk = Tk() | |
tk.withdraw() | |
tk.clipboard_clear() | |
tk.clipboard_append(url) | |
tk.destroy() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment