Explanation of Main Code - phaticusthiccy/Telegram-Activity GitHub Wiki

The code in gui.py is a Python script that creates a graphical user interface (GUI) application using the Tkinter library. The purpose of this application is to monitor running games on the user's computer and update the user's Telegram profile status accordingly.

The application takes input from the user in the form of game names. The user can add games to a list by typing the game name in an entry field and clicking the "Add" button or pressing Enter. The user can also remove games from the list by selecting a game and clicking the "Remove" button or pressing the Delete key.

The main output of the application is the user's Telegram profile status, which is updated to reflect the game they are currently playing and the elapsed time since they started playing it. If no game is being played, the profile status is set to a default biography entered by the user.


To achieve its purpose, the code follows this logic:

The user interface is created using Tkinter, with various widgets such as entry fields, listboxes, and buttons.

The user adds game names to the list, which are stored in the added_games list.

The code loads a mapping of game names to their corresponding process names from a JSON file (process_mapping.json).

The application continuously checks if any of the games in the added_games list are running on the user's computer using the psutil library.

If a game is running, the application calculates the elapsed time since the game started and updates the user's Telegram profile status using the Telethon library.

If no game is running, the application sets the user's Telegram profile status to the default biography entered by the user. The application runs in an asynchronous event loop, updating the Telegram profile status every 60 seconds and periodically updating the GUI to keep it responsive.


Important logic flows and data transformations:

The find_process_name function is used to find the process name corresponding to a given game name by searching through the loaded process mapping.

The get_process_name and get_friendly_name functions are used to convert between game names and their corresponding process names, using the loaded process mapping.

The is_game_running function checks if a game with a given name is currently running on the user's computer by iterating over the running processes and comparing their names.

The update_status function is an asynchronous function that updates the user's Telegram profile status based on the currently running game and the elapsed time.

The main function is the core of the application, running in an asynchronous event loop and continuously checking for running games and updating the Telegram profile status accordingly.

The code also includes helper functions for handling user input, displaying messages, and managing the GUI window.