-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_update.py
More file actions
77 lines (61 loc) · 2.4 KB
/
data_update.py
File metadata and controls
77 lines (61 loc) · 2.4 KB
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
from groupy import Client
import json
def save_json(obj, name):
with open('obj/'+ name + '.json', 'w') as f:
f.write(json.dumps(obj))
def load_json(name):
with open('obj/'+ name + '.json', 'r') as f:
return json.loads(f.read())
def get_name_from_member_id(id, id_to_member, stats):
if id in id_to_member:
return id_to_member[id]
return f"Removed Member: {stats}"
def save_obj(obj, name ):
with open('obj/'+ name + '.pkl', 'wb') as f:
pickle.dump(obj, f, pickle.HIGHEST_PROTOCOL)
def load_obj(name):
with open('obj/' + name + '.pkl', 'rb') as f:
return pickle.load(f)
def load_rest(name):
with open('obj/' + name + '.txt', 'rb') as f:
file_text = f.readlines()
json_dt = json.loads(file_text[1])
return file_text[0].decode("utf-8")[:-1], json_dt, file_text[2], file_text[3]
people = load_json("people_data")
for person in people:
people[person] = (people[person][0], people[person][1], set(people[person][2]))
group_name, id_to_member, total_messages, last_message_id = load_rest("additional_data")
init_data = open("init_info.txt", "r").readlines()
api_token = init_data[0][:-1]
client = Client.from_token(api_token)
groups = list(client.groups.list())
print(groups)
group_list = list(filter(lambda x: x.name == group_name, groups))
if len(group_list) == 0:
print("Couldn't find a group by that name, sorry!")
exit()
group = group_list[0]
print(type(group))
messages_to_update = list(group.messages.list_since(last_message_id))
print(messages_to_update)
for message in messages_to_update:
person = message.user_id
if not message.name == "GroupMe":
like_list = message.favorited_by
if person in like_list:
like_list.remove(person)
likes = len(like_list)
if not person in people:
people[person] = (0,0,set([]))
s = people[person][2]
s.add(message.name)
people[person] = (people[person][0] + likes, people[person][1]+1, s)
for person in people:
people[person] = (people[person][0], people[person][1], list(people[person][2]))
save_json(people, "people_data")
data_file = open("obj/additional_data.txt", 'w')
data_file.write(group_name + "\n")
data_file.write(json.dumps(id_to_member))
data_file.write("\n" + str(int(total_messages) + len(messages_to_update)))
data_file.write("\n" + str(messages_to_update[-1].id))
print("Saved data to files")