Revisit your file counter script. Instead of writing the logs of each run to a file, you'll set it up to write to an SQL database instead.
Info: If you need a refresher on interacting with a database using Python, check out the previous section on Working with Databases in Python section of the linked course.
Collect the same information you saved to a CSV file before putting it into a database instead. You can use a file-based SQLite database or a server-based database such as PostgreSQL or MySQL.
Additionally, look into Python's datetime module and attempt to track the times when you ran your script.
Data Analysis
Once your script is set up to save its run data into your database, you'll next write a script to analyze your collected desktop statistics.
Use your Python skills to calculate:
- The total number of files that have been on your desktop since you started tracking it
- The total number for each file type
- On what day you had the most items on your desktop
- The most common file type ever to clutter your desktop
Write your results to a new table in your database and set your analysis script up so that it keeps updating this table on each execution.
Tasks
- Write a script that stores the information returned from your file counter script in an SQL database.
- Read the saved data from your database and analyze it.
- Write the results of your analysis to another table in your database.
Your program should move away from using CSV or JSON files, but you should still be able to track your data over multiple executions.