Merged github and gitio, pending rewrite
This commit is contained in:
parent
d69feb68d8
commit
d5ddc72a53
|
@ -1,6 +1,6 @@
|
|||
from util import hook, http
|
||||
import json
|
||||
import gitio
|
||||
import urllib2
|
||||
|
||||
shortcuts = {"cloudbot": "ClouDev/CloudBot"}
|
||||
|
||||
|
@ -64,3 +64,52 @@ def ghissues(inp):
|
|||
return fmt1 % (number, state, user, title, gitiourl)
|
||||
else:
|
||||
return fmt % (number, state, user, title, summary, gitiourl)
|
||||
|
||||
|
||||
@hook.command
|
||||
def gitio(inp):
|
||||
"gitio <url> [code] -- Shorten Github URLs with git.io. [code] is" \
|
||||
" a optional custom short code."
|
||||
split = inp.split(" ")
|
||||
url = split[0]
|
||||
|
||||
try:
|
||||
code = split[1]
|
||||
except:
|
||||
code = None
|
||||
|
||||
# if the first 8 chars of "url" are not "https://" then append
|
||||
# "https://" to the url, also convert "http://" to "https://"
|
||||
if url[:8] != "https://":
|
||||
if url[:7] != "http://":
|
||||
url = "https://" + url
|
||||
else:
|
||||
url = "https://" + url[7:]
|
||||
url = 'url=' + str(url)
|
||||
if code:
|
||||
url = url + '&code=' + str(code)
|
||||
req = urllib2.Request(url='http://git.io', data=url)
|
||||
|
||||
# try getting url, catch http error
|
||||
try:
|
||||
f = urllib2.urlopen(req)
|
||||
except urllib2.HTTPError:
|
||||
return "Failed to get URL!"
|
||||
urlinfo = str(f.info())
|
||||
|
||||
# loop over the rows in urlinfo and pick out location and
|
||||
# status (this is pretty odd code, but urllib2.Request is weird)
|
||||
for row in urlinfo.split("\n"):
|
||||
if row.find("Status") != -1:
|
||||
status = row
|
||||
if row.find("Location") != -1:
|
||||
location = row
|
||||
|
||||
print status
|
||||
if not "201" in status:
|
||||
return "Failed to get URL!"
|
||||
|
||||
# this wont work for some reason, so lets ignore it ^
|
||||
|
||||
# return location, minus the first 10 chars
|
||||
return location[10:]
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
# Plugin by neersighted and Lukeroge
|
||||
from util import hook
|
||||
import urllib2
|
||||
|
||||
|
||||
@hook.command
|
||||
def gitio(inp):
|
||||
"gitio <url> [code] -- Shorten Github URLs with git.io. [code] is" \
|
||||
" a optional custom short code."
|
||||
split = inp.split(" ")
|
||||
url = split[0]
|
||||
|
||||
try:
|
||||
code = split[1]
|
||||
except:
|
||||
code = None
|
||||
|
||||
# if the first 8 chars of "url" are not "https://" then append
|
||||
# "https://" to the url, also convert "http://" to "https://"
|
||||
if url[:8] != "https://":
|
||||
if url[:7] != "http://":
|
||||
url = "https://" + url
|
||||
else:
|
||||
url = "https://" + url[7:]
|
||||
url = 'url=' + str(url)
|
||||
if code:
|
||||
url = url + '&code=' + str(code)
|
||||
req = urllib2.Request(url='http://git.io', data=url)
|
||||
|
||||
# try getting url, catch http error
|
||||
try:
|
||||
f = urllib2.urlopen(req)
|
||||
except urllib2.HTTPError:
|
||||
return "Failed to get URL!"
|
||||
urlinfo = str(f.info())
|
||||
|
||||
# loop over the rows in urlinfo and pick out location and
|
||||
# status (this is pretty odd code, but urllib2.Request is weird)
|
||||
for row in urlinfo.split("\n"):
|
||||
if row.find("Status") != -1:
|
||||
status = row
|
||||
if row.find("Location") != -1:
|
||||
location = row
|
||||
|
||||
print status
|
||||
if not "201" in status:
|
||||
return "Failed to get URL!"
|
||||
|
||||
# this wont work for some reason, so lets ignore it ^
|
||||
|
||||
# return location, minus the first 10 chars
|
||||
return location[10:]
|
Reference in a new issue