This code is a script that imports JSON data from a Telegram chat, performs data analysis on the messages, and exports the results to an Excel file. The script uses the Python programming language and several libraries, including Pandas, Xlsxwriter, and tqdm.
In order to run this code, you will need to have Python installed on your computer. You will also need to install the required libraries by running the following command in your terminal or command prompt:
pip install -r requirements.txt
- Copy the JSON file into the folder named 'data' and rename it
result.json
- Open the terminal in the script folder and type
python main.py
- Follow the prompts in the terminal or command prompt to complete the analysis.
The main function of the code is main()
. It starts by loading the JSON data from the file and storing it in a variable called chat_data
. Then, it calls several functions to perform different tasks, such as data analysis, exporting to Excel, filtering, and partioning.
The convert_json_to_excel()
function takes the messages data and exports it to an Excel file. It allows you to choose the time interval for the data analysis, and it also provides an option to perform Fourier analysis.
The filter_messages()
function filters the messages based on a keyword.
The partition_messages()
function partitions the messages into separate groups based on specific criteria.
The fourier_analysis()
function performs Fourier analysis on the data and creates a graph of the results.
The get_unique_titles()
, get_authors_count()
, get_unique_micronations()
, and get_unique_locations()
functions are used to extract information from the messages and display it in the terminal.
This code is a basic example of how to perform data analysis on Telegram chat data. It is provided as-is and is not intended to be used for production purposes. Some limitations of this code include:
- It assumes that the JSON file follows the standard Telegram format.
- It does not handle all possible message formats, such as media messages.
- It does not provide any security features, such as encryption or authentication.
This code is licensed under the MIT License. You can view the full license text in the LICENSE
file.
If you would like to contribute to this project, feel free to open a pull request with your changes. Make sure to update the README and other documentation as needed.