-
Notifications
You must be signed in to change notification settings - Fork 3
/
carbon.py
executable file
·53 lines (44 loc) · 1.49 KB
/
carbon.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
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/python3
from core import Make
import config
import os
# get the link from user
while True:
link = input('insert link which you want to shorten: ')
if link:
break
else:
print('fetal: url should not be blank')
# take a name for shorted url from user
while True:
name = input('short name for url(or just pass it blank to random): ')
if name == 'index':
print('fetal: name should not be index.')
else:
break
# chose user should click to open the link or just redirect it
while True:
click = input('make user click to open the link(y/n)?: ')
if click == 'y':
click = True
break
elif click == 'n':
click = False
break
else:
print('fetal: enter y for yes, and n for no')
# the title for individual link page
title = input('type the title: ')
# any desctiption for individual link page
description = input('describe sotmething before redirection: ')
# copy style dependency
with open(os.path.join(config.DIR, 'style.css'), 'r') as rstyle:
with open(os.path.join(config.PUBLISH_DIR, 'style.css'), 'w') as wstyle:
wstyle.write(rstyle.read())
# generate the page
link = Make(link=link, title=title, desc=description, click=click, name=name)
print(os.path.join(config.BASE_URL, os.path.split(link)[1]))
# copy index
with open(os.path.join(config.DIR, config.INDEX), 'r') as rindex:
with open(os.path.join(config.PUBLISH_DIR, 'index.html'), 'w') as windex:
windex.write(rindex.read())