-
Notifications
You must be signed in to change notification settings - Fork 0
/
process.py
114 lines (90 loc) · 3.19 KB
/
process.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
from datetime import datetime
from rest import Path_check, download_file, make_zip
from download import final as finalise
import time, os
ending = '</div></div>%#@'
ID = []
NAME = []
def do_rest(thread,client):
uid = client.uid
USER = client.fetchUserInfo(client.uid)[client.uid]
self = USER.name
check = 0
timestampbackup = int(19800 + time.time())*100
data = str(thread).split(" ")
id = data[len(data)-1].split('(')[1].split(')')[0]
logfile = open('log.txt', 'rb')
backup = logfile.read()
backup = backup.split('\n')
for test in backup:
bakupdata = test.split(' ')
if len(bakupdata)>1:
idbackup = bakupdata[0]
if idbackup == id:
timestampbackup = float(bakupdata[1])
backup.remove(test)
break
logfile.close()
logfile = open('log.txt', 'wb')
for test in backup:
logfile.write(test + '\n')
logfile.close()
other = data[1]
name = str(data[1])
if len(data) == 4:
other = data[1] + " " + data[2]
name = str(data[1]) + '_' + str(data[2])
if len(data) == 5:
other = data[1] + " " + data[2] + " " + data[3]
name = data[1] + '_' + data[2] + '_' + data[3]
if len(data) == 6:
other = data[1] + " " + data[2] + " " + data[3] + " " + data[4]
name = data[1] + '_' + data[2] + '_' + data[3] + '_' + data[4]
if str(data[0]) != '<GROUP':
ID.append(id)
NAME.append(other)
check = 1
if other == '' or other == ' ' or name == '' or name == ' ' :
other = 'Group_' + str(id)
name = 'Group_' + str(id)
print "downloading messages from Group/User/Page -: ", other
starting = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>' + other + '- Messages</title> <link rel="stylesheet" href="../../style.css" type="text/css" /></head><body> <div class="contents"><h1>' + other +'</h1> <div class="thread"> Total number of messages = ' + str(thread.message_count) + '____\n'
Testing = Path_check(other)
folder_name = "Data/" + other
log_file = folder_name+"/" + name + ".txt"
Log_file = open(log_file, 'wb')
filename = folder_name+"/html/" + name + ".htm"
filenametxt = folder_name+"/html/" + name + ".txt"
file = open(filenametxt, 'wb')
flag = 100
num = 0
timestamp = int(19800 + time.time())*1000
log = str(id) + ' ' + str(timestamp-19800) + '\n'
while( flag > 99):
messages = client.fetchThreadMessages(thread_id=id, limit=100, before=timestamp)
timestamp = messages[len(messages)-1].timestamp
flag = len(messages)
num += flag
finalise(messages, timestampbackup, file, Log_file, check, uid, self, folder_name, other)
print num, " messages had been downloaded from today till - ",datetime.utcfromtimestamp(float(timestamp)/1000).strftime('%d-%m-%Y')
file.close()
logfile = open('log.txt', 'a')
logfile.write(log)
logfile.close()
file = open(filenametxt, 'rb')
latest = file.read()
final = latest
file.close()
if os.path.exists(filename):
file_htm = open(filename, 'rb')
final = file_htm.read()
final = final.split('</h1> <div class="thread"> Total number of messages = ')[1]
final = final.split('____\n')[1]
final = final.split(ending)[0]
final = latest + final
file_htm.close()
file_htm = open(filename, 'wb')
file_htm.write(starting)
file_htm.write(final)
file_htm.write(ending)
file_htm.close()