-
Notifications
You must be signed in to change notification settings - Fork 2
/
Logs.py
55 lines (35 loc) · 1.1 KB
/
Logs.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
import os
import time
# Create the directory folder History to save the log files
def create_dir():
if not os.path.exists('History'):
print('Creating the directory History')
os.makedirs('History')
# Write the query log of the user into the txt file in append mode
def write_to_file(user_name, log):
name = 'History/' + str(user_name)
file_name = name + '.txt'
f = open(file_name, 'a+')
f.write(log + '\n')
f.close()
# Computes the logs
def data(user_name, query):
query = str(query + ' ')
query = 'search : ' + query
timestr = str(time.asctime())
log = str(query + timestr)
write_to_file(user_name, log)
# Convert the string into URL . Explicit Encoding the string to URL into UTF-8.
def urlifystring(string):
ythomepage = 'https://www.youtube.com/results?search_query='
string = ythomepage + string
res = ''
start = False
for char in reversed(string):
if char != ' ':
start = True
if char == ' ' and start is True:
res += '+'
else:
res += char
return res[::-1]