diff --git a/__pycache__/classes.cpython-39.pyc b/__pycache__/classes.cpython-39.pyc new file mode 100644 index 0000000..082ff92 Binary files /dev/null and b/__pycache__/classes.cpython-39.pyc differ diff --git a/__pycache__/constants.cpython-39.pyc b/__pycache__/constants.cpython-39.pyc new file mode 100644 index 0000000..39b6f8f Binary files /dev/null and b/__pycache__/constants.cpython-39.pyc differ diff --git a/classes.py b/classes.py new file mode 100644 index 0000000..2f7bcff --- /dev/null +++ b/classes.py @@ -0,0 +1,5 @@ +class User: + def __init__ (self, user_id, username): + self.user_id = user_id + self.username = username + self.number_messages = 1 # Start with one, as user only added if spoken in channel diff --git a/constants.py b/constants.py new file mode 100644 index 0000000..2b2d1c7 --- /dev/null +++ b/constants.py @@ -0,0 +1,5 @@ +USER_ID = 0 +USERNAME = 1 +DATE = 2 +MESSAGE = 3 +REACTIONS = 5 \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..c0865b4 --- /dev/null +++ b/main.py @@ -0,0 +1,63 @@ +import csv +import constants as v +import classes as c + +# Date MM-dd-yyyy HH:mm:ss + + +# Reads from specified CSV file (specified in settings file) +# Outputs analysis to output file +def parse_file(): + temp_user = c.User('0','0') + user_array = [] + + print('Loading from CSV channel.csv') + file = open('channel2.csv', encoding="utf8") + with file as csv_file: + csv_reader = csv.reader(csv_file, delimiter=',') + line_count = 0 + + for row in csv_reader: + if line_count == 0: + line_count += 1 + else: + parse_user(row, user_array) + line_count +=1 + print(f'Done. {line_count} messages read') + print(f'Users found: {len(user_array)}') + + for user in user_array: + percentage = user.number_messages / line_count + print(f'Username: {user.username} Messages: {user.number_messages} Contribution: {percentage * 100}%') + + +# Parses current line stats and updates user_array accordingly +def parse_user(current_row, user_array): + user_id = current_row[v.USER_ID] + user_index = 0 + user_found = 0 + for user in user_array: + if user.user_id == user_id: + user_found = 1 + break + user_index += 1 + + if user_found: + # Update user stats + user_array[user_index].number_messages += 1 + else: + # If user not found, add them to array + user_array.append(c.User(user_id, current_row[v.USERNAME])) + + +# Loads settings file. +# Configures what information should be calculated and printed to output file +def load_settings(): + print('settings placeholder') + + +# Press the green button in the gutter to run the script. +if __name__ == '__main__': + parse_file() + +