-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
82 lines (53 loc) · 1.73 KB
/
example.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from Shortner.shortner import Shortner
sh = Shortner()
#-------------------------------------------------------------------
# Register a new user
username = 'admin'
password = 'root'
if sh.register(username=username, password=password):
print("User registered successfully.")
else:
print("Username not available")
#-------------------------------------------------------------------
#-------------------------------------------------------------------
# Login
if sh.login(username=username, password=password):
print("Logged in successfully.")
else:
print("User doesn't exist")
#-------------------------------------------------------------------
#-------------------------------------------------------------------
# Check a back-half
bk_hlf = 'abcd'
if sh.check_back_half(back_half=bk_hlf):
print("Back-half available")
else:
print("Back-half not available")
#-------------------------------------------------------------------
# Custom back-half
bk_hlf = 'a'
url = 'https://youtu.be/dQw4w9WgXcQ'
short = sh.shorten(url=url, custom_back_half=bk_hlf)
if short:
print('Custom shortened url is ', short)
else:
print('Back-half not available')
#-------------------------------------------------------------------
# Random back-half
url = 'https://youtu.be/dQw4w9WgXcQ'
short = sh.shorten(url=url)
if short:
print('Random shortened url is ', short)
else:
print('Back-half not available')
#-------------------------------------------------------------------
# List user urls
print('\n')
urls = sh.list_urls()
print('Urls shortened are,')
for url in urls:
print(url)
choice = int(input('Enter 1 to delete all urls or 0 to exit : '))
if choice == 1:
for url in urls:
sh.delete_url(url[0])