-
Notifications
You must be signed in to change notification settings - Fork 23
/
url_shortener.py
40 lines (25 loc) · 1.14 KB
/
url_shortener.py
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
import subprocess
import os
from github_config import *
example_url = github_url + "/this_right_here"
print("what url do you want to shorten?")
url_to_shorten = input("url to be shortened: http(s)://")
shortened_url = input("shorten to " + github_url + "/")
to_write = path_to_repo + "/" + shortened_url + "/index.html"
if os.path.exists(to_write) or os.path.exists(path_to_repo + "/" + shortened_url):
print("unfortunately you have already shortened something to that url :(")
os.mkdir(path_to_repo + "/" + shortened_url)
index = open(to_write, "w+")
index.write("<meta http-equiv=\"refresh\" content=\"0; URL=\'http://" +
url_to_shorten + "\'\" />")
index.close()
print("doing some stuff....")
current_directory = os.getcwd()
os.chdir(path_to_repo)
os.system("git add . > /dev/null 2>&1")
os.system("git commit -m " + "\"shortening " + url_to_shorten +
" to " + github_url + "/" + shortened_url + "/\" > /dev/null 2>&1")
os.system("git push > /dev/null 2>&1")
os.chdir(current_directory)
print("url has been shortened to:", github_url + "/" + shortened_url + "/")
print("it might take ~5 mins for the link to become active")