-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDMReader.py
More file actions
66 lines (62 loc) · 2.45 KB
/
DMReader.py
File metadata and controls
66 lines (62 loc) · 2.45 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
#!/bin/python
from json import load
#we need json.load() function to store json data as a dictionary
"""
################################################################################
# Developed by zanamziry720@gmail.com #
# i only tested this code on one file, im not sure if its gonna work perfectly #
# and sorry for the ugly code, im not a pro programmer tbh LoL #
################################################################################
printConv() function prints the conversation you want to select
because every DM haves a number
for example i had a DM with a friend named tony
and the number of the DM with tony is 1
i need to print jsondata[1]['conversation']
to get the conversation between me and tony
"""
def printConv(jsdata,convNum):
jsdata[convNum]['conversation'].reverse()
if len(jsdata[convNum]['conversation'])<1:
print("Empty")
for i in jsdata[convNum]['conversation']:
if 'media' in i:
print(i['sender'],":",i['media'])
if 'text' in i:
print(i['sender'],":",i['text'])
if 'voice_media' in jsdata[convNum]['conversation']:
print(i['sender'],":",i['voice_media'])
if 'story_share' in jsdata[convNum]['conversation']:
print(i['sender'],":",i['story_share'])
if 'media_share_url' in jsdata[convNum]['conversation']:
print(i['sender'],":",i['media_share_url'])
"""
this function imports all the usernames you DMed from the message.json
and returns a list variable
to get usernames of a conversation you need to print jsondata[num]['participants']
"""
def getNames(jsdata):
users=[]
for i in range(len(jsdata)):
if 'participants' in jsdata[i]:
if len(jsdata[i]['participants'])>2:
groupname='group'+str(i)
users.append(groupname)
elif len(jsdata[i]['participants'])<3 and not 0:
for j in jsdata[i]['participants']:
users.append(j)
un=""
for i in users:
if users.count(i) >= len(jsdata)-1:
un=i
while(users.count(un)>0):
users.remove(un)
return users
if __name__ == '__main__':
js = load(open("messages.json")) #change this to the direction of your json file
DMS = getNames(js)
print("Directs:")
getNames(js)
for i in range(len(DMS)):
print(i,"-",DMS[i])
cn = int(input("choose a Conversation:"))
printConv(js,cn)