Kubis10 / CounterForMessenger

Counter for Messenger - First and most extensive free desktop application made in Python with tkinter
https://kubis10.github.io/CounterForMessengerPage/
Other
20 stars 26 forks source link

Add a new feature and close issue #41 #44

Closed Coder2Mo closed 10 months ago

Coder2Mo commented 10 months ago

what i made is just automatically find the username by counting the number of messages sent by each participant in the available message data. The sender with the highest message count is assumed to be the username. If no username is found, it defaults to 'N/A !

def find_username(self):
    username_counts = Counter()

    for conversation in listdir(self.directory):
        try:
            for file in glob.glob(f'{self.directory}{conversation}/*.json'):
                with open(file, 'r') as f:
                    data = json.load(f)

                    for message in data.get('messages', []):
                        sender = message['sender_name'].encode('iso-8859-1').decode('utf-8')
                        username_counts[sender] += 1
            most_frequent_sender, most_messages = username_counts.most_common(1)[0]

            return most_frequent_sender

        except Exception as e:
            print("Error in loading: " + str(e))
    return 'N/A'

self.username = self.find_username()
Kubis10 commented 10 months ago

What with this?

Coder2Mo commented 10 months ago

What with this?

i am adding the feature for : find the username by counting the number of messages sent by each participant in the available message data. The sender with the highest message count is assumed to be the username. If no username is found, it defaults to 'N/A !