-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitio.py
More file actions
51 lines (36 loc) · 954 Bytes
/
gitio.py
File metadata and controls
51 lines (36 loc) · 954 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#-*- Coded By SadCode -*-
import requests
import argparse
import sys
API_URL = "https://git.io/create"
HOME_URL = "https://git.io/"
######### Errors #########
ERROR = "Must be a GitHub.com URL."
INVALID_URL = "Invalid url:"
##########################
def shorten(url):
# Note to self: test the "code" data to add a custom code
try:
data = requests.post(API_URL, data={"url":url}).text
except:
print("Please check your internet conection.")
exit()
if data == ERROR:
print(data)
elif INVALID_URL in data:
print(data)
else:
print(HOME_URL + data)
def main():
parser = argparse.ArgumentParser(description = "Create short GitHub url from the terminal")
parser.add_argument("-u", "--url",
type=str,
required=True,
help = "GitHub url")
args = parser.parse_args()
if len(sys.argv) == 1: # if argument is given then show help
parser.print_help()
elif args.url:
shorten(args.url)
if __name__=="__main__":
main()