-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
62 lines (49 loc) · 1.84 KB
/
main.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
import os
import sys
import print_data
import users
import metadata_chat
# Returns the content of the file path
def get_content(file_path):
if not os.path.isfile(file_path):
print("The file doesn't exists")
sys.exit()
else:
f = open(file_path, 'r', encoding="utf8")
content = f.readlines()
f.close()
return content
if __name__ == '__main__':
# Check if the user has entered a file_path to the image
if(len(sys.argv) > 1):
if(sys.argv[1] == '--help' or sys.argv[1] == '-h'):
print(
'\nMPD Help: You must enter a file path as an argument like\n\t$> main.py chat.txt\n')
sys.exit()
content = get_content(sys.argv[1])
metadata = metadata_chat.main(content)
users = users.main(content, metadata)
if('--get-list-word' in sys.argv):
f = open('./chats/words.txt', 'w', encoding='utf8')
for user in users:
f.write(user + '\n')
f.write(
str(users[user]['most_common_word']).strip('[]') + '\n')
f.close()
if ('--save-users-messages' in sys.argv):
folder = "users-messages"
if os.path.exists(folder):
os.system("rm -r " + folder)
os.mkdir(folder)
with open(folder + "/messages.txt", "w", encoding='utf-8') as fd:
for user in users:
fd.write(user + ":")
for m in users[user]["messages"]:
if "<Multimedia omitido>" not in m:
fd.write(m.replace('\n', '') + ". ")
fd.write("\n")
print_data.print_metadata(metadata)
print_data.print_info_table(users)
else:
print("You must enter a file path as an argument")
sys.exit()