-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathURL.py
33 lines (29 loc) · 776 Bytes
/
URL.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
from random import randint
from tokenize import String
import DataStore
import Error
'''
Method for generating and storing the longURL, shortURL
'''
def ShortUrl(longUrl, tokens)->String:
shortUrl = "https://short/"
for i in range(8):
shortUrl += tokens[randint(0, len(tokens)-1)]
#Storing in Database
DataStore.store(shortUrl, longUrl)
#Return ShortUrl
return shortUrl
'''
Method for getting LongURL
@params : shortUrl -> String
'''
def getLongUrl(shortUrl)->String:
longUrl = DataStore.getlongUrl(shortUrl.rstrip().lstrip())
return longUrl
'''
Methos for getting shortURL
@params : longUrl -> String
'''
def getShortUrl(longUrl) -> String:
shortUrl = DataStore.getshortUrl(longUrl.lstrip().rstrip())
return shortUrl