-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
135 lines (104 loc) · 4.37 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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import os
import json
import re
import threading
import time
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from pprint import pprint
import emoji
from colorama import Fore, Style
from pyfiglet import Figlet
import helper_function
import review
plt.style.use('Solarize_Light2')
messages_df = None
def loading_animation():
animation = ['⣾', '⣷', '⣯', '⣟', '⡿', '⢿', '⣻', '⣽']
while not loading_complete:
for frame in animation:
print(Fore.CYAN + f"\r{frame}" + Style.RESET_ALL + " Loading the messages... " + Style.RESET_ALL, end="", flush=True)
time.sleep(0.1)
def main():
# Printing the title
print( "\n" )
print("☆.。.:*・°☆.。.:*・°☆.。.:*・°☆.。.:*・°☆.。.:*・°☆." + Style.RESET_ALL)
print(Figlet().renderText('Instagram Wrapped'))
print("☆.。.:*・°☆.。.:*・°☆.。.:*・°☆.。.:*・°☆.。.:*・°☆." + Style.RESET_ALL)
print("\n")
# Root directory where all user folders are located
# Columns to drop and users to drop
# User's Instagram name
root_directory = os.path.join(os.getcwd(), './inbox')
columns_to_drop = ['call_duration', 'sticker', 'is_geoblocked_for_viewer']
users_to_drop = []
your_instagram_name = 'Adam'
# Loading the messages DataFrame and time it
global loading_complete
loading_complete = False
start_time = time.time()
print(Fore.GREEN + "Loading the messages DataFrame... " + Style.RESET_ALL, end="", flush=True)
print("")
loading_thread = threading.Thread(target=loading_animation)
loading_thread.start()
error_flag = False, None
try:
messages_df, user_count = helper_function.load_messages(root_directory, columns_to_drop, users_to_drop)
except Exception as e:
error_flag = True, e
loading_complete = True
loading_thread.join()
if error_flag[0]:
print(Fore.RED + "\nError loading the messages DataFrame: " + Style.RESET_ALL + str(error_flag[1]))
return
print(Fore.GREEN + "Done in " + f"{(time.time() - start_time):.2f}" + " secs!" + Style.RESET_ALL)
print(Fore.GREEN + "\nNumber of users: " + Style.RESET_ALL + str(user_count))
messages_df = messages_df
# Give statistics about the data loaded such as how many rows (messages were loaded, etc)
### ~~~~~~~~~~~ 2023 Review ~~~~~~~~ ###
# New DataFrame for the year 2023
# messages_2023_df = messages_df[messages_df['year'] == 2023]
## Number of messages sent by each user
# message_count_by_user = messages_2023_df['sender_name'].value_counts()
# print(Fore.GREEN + "\nNumber of messages sent by each user in 2023: " + Style.RESET_ALL)
# print(message_count_by_user[0:10])
"""
"""
review_menu(messages_df)
def review_menu(messages_df):
# Ask if this is the user
# users_name = messages_df['sender_name'].value_counts()[0:1].index[0]
# print(Fore.GREEN + "\nIs this you? " + Style.RESET_ALL + users_name)
# user_input = input(Fore.GREEN + "\nAre you " + Style.RESET_ALL + users_name + Fore.GREEN + "? "+ Style.RESET_ALL )
# if user_input == "yes":
# print("Thank you!")
# else:
# print("Well this is awkward...")
while (True):
print(Fore.GREEN + "\nReview Menu" + Style.RESET_ALL)
print(Fore.CYAN + "\t1. Review this year" + Style.RESET_ALL)
print(Fore.BLUE + "\t2. Review previous year" + Style.RESET_ALL)
print(Fore.YELLOW + "\t3. Total Review" + Style.RESET_ALL)
print(Fore.RED + "\t4. Quit" + Style.RESET_ALL)
print("\n")
user_input = input(Fore.GREEN + "Enter your choice: " + Style.RESET_ALL)
match user_input:
case "1":
# review_this_year()
pass
case "2":
# review_previous_year()
pass
case "3":
# total_review()
review.analyze_messages(messages_df)
pass
case "4":
break
case _:
print(Fore.RED + "Invalid input!" + Style.RESET_ALL)
continue
print(Fore.GREEN + "Thank you!" + Style.RESET_ALL)
if __name__ == '__main__':
main()