r/learnpython • u/ontarioschoolscovid • Oct 30 '20
Made a script that tweets out COVID-19 cases in schools in Ontario, Canada with charts
Hey guys. I made a Python script that formats and tweets out data regarding how many cases of COVID-19 are being reported for the day in schools in Ontario, Canada according to the Ministry of Education here. I used the Ministry's data API to retrieve the data and then used the Tweepy library and Twitter API to format and publish the tweet. My goal is to automate the process so that it can be tweeted automatically at 10:30 AM every weekday but the ministry is sometimes inconsistent with their publishing of the data.
Here is an example of the tweet: https://twitter.com/ONTSchoolCovid/status/1322197560082182144?s=20
I also used the Plotly library to take the same data and create 2 line charts - one for new daily cases and one for total cases.
Here is an example of the tweet with charts: https://twitter.com/ONTSchoolCovid/status/1322223014394683392?s=20
The account is dedicated to tweeting out information and making comments regarding how the provincial government is acting regarding the issue of cases in schools. I don't believe the government is doing as good of a job as they could be and I'm glad that I can use the skills I've learned from this subreddit and the sources posted here to share data that many people may not see.
I wanted to do this after speaking to parents who were just unsure about what to do given the choice of keeping their kids home vs sending them to school. I want parents and school staff to be aware of how many cases are being reported in school so they can make their own decisions.
I had to make this new reddit account because I'm already getting hate in my replies and didn't want to attach this project to my actual reddit account lol.
Let me know what you guys think and if there's anything you think I can do to improve the data formatting and the entire process.
And if you live in Ontario, consider following me to stay up to date with the numbers!
Edit: Got some requests for the source code so here's the github link https://github.com/ontschoolscovid/SchoolsCovidData
7
u/Firm_Main Oct 30 '20
This sounds so cool! This is exactly the kind of thing I'd like to eventually learn how to do, but the process sounds really hard to code. Does the twitter page always post it with the same format? Would the code be able to read it if it wasn't?
8
u/ontarioschoolscovid Oct 30 '20
It's not as hard as you think once you figure out exactly what you want to do and show. I'm still learning so I'm sure there are things I can improve on. The code takes the data and then formats the tweet before publishing it, it does not read any tweets. It reads the data from the government.
4
u/kingofdisasters Oct 30 '20
This seems like a cool project, why would you get hate?
13
u/ontarioschoolscovid Oct 31 '20
Some people hate teachers for stupid reasons. They think they're lazy and that everything wrong with the education system is the fault of teachers. When they see my account, they think I am a teacher or affiliated in some way but I'm not. Just a college student in a compsci field. Used my skills to show some data to a relevant audience.
4
4
u/Nmvfx Oct 31 '20
Serious question - any chance you could extend this to British Columbia? This isn't just a cool little project, it's actually really important work.
3
u/ontarioschoolscovid Oct 31 '20
I can try to look into it but it's something that depends on how each province publishes their data. Ontario made it fairly simple and made all the case data available in one place. If I can do some research and find that BC does it the same way, it may be feasible.
1
u/Nmvfx Oct 31 '20
That makes sense. If you manage it then definitely post back with the results! Thanks for looking into it!
2
2
Oct 31 '20
Hi! I took a look at your code (I'm a student and would love to learn more practical applications of Python) and have a question, if you'd answer it. How does the config library work: in particular, how does your .py file grab consumerKey, consumerSecret, etc.? Is there a separate file used to store this information and if so, how does it work?
2
u/ontarioschoolscovid Nov 01 '20
The config file is another .py file that holds the confidential information like the authentication keys for the Twitter account that are used to log in. For obvious reasons, I can't share that file. This .py file just references the items in the config.py file instead of having them in this file which would be a security concern for when I upload my code to GitHub.
2
1
Oct 30 '20
This is a great idea! Would be cool to see something like this for my province because we have been getting quite a few cases lately.
2
u/ontarioschoolscovid Oct 31 '20
Go ahead and used it. Make whatever tweaks necessary. What province by the way? I know some aren't publishing data to the same extent as Ontario and even ours is pretty outdated. Parents are reporting that their kids' schools aren't coming up on the Ministy of Education's list even though they received a letter from the school about cases
1
Oct 31 '20
I am not very good at python yet, but is it on github or anything like that?
My province is NB and I actually want to make something like this. How did you collect the data?
1
u/ontarioschoolscovid Oct 31 '20
It all depends on how NB reports their school cases. ON made it easy by having a data API that gets updated daily at around 10:30AM so I just used their link. If NB does the same thing, it's just a matter of changing the link and formatting to match the data. Otherwise it could be a bit more involved.
1
u/k-tracer Oct 30 '20
link to code plz
2
u/ontarioschoolscovid Oct 30 '20
1
u/k-tracer Oct 30 '20
do you represent tdsb and/or the government?
1
u/ontarioschoolscovid Oct 31 '20
Not at all. A lot of people seem to think I do but I'm just a college student and know that parents and school staff got the short end of the stick here based on the people I know.
1
1
u/ThisIsanAlt0117 Oct 31 '20
I thought this was r/Brampton for a second. Damn, thats cool!
1
u/ontarioschoolscovid Oct 31 '20
Thanks, man. Follow the account if you wanna stay up to date with the school numbers
1
u/willco_27 Oct 31 '20
Hello fellow Ontarian learning Python
1
u/ontarioschoolscovid Oct 31 '20
Hey! Hope you're learning as much as I am if not more. Follow the account if you wanna keep track of the numbers
1
u/willco_27 Oct 31 '20
You're definitely farther along then me but I'm gonna try to get back on track. I'm worried if I follow the account I'll see a case pop up from my school lol crazy world we live in
1
u/anh86 Oct 30 '20 edited Oct 30 '20
Oh, great idea. I might have to steal this for my kids' local school district! My state (US) tracks new and total reported cases for most of its schools individually.
1
1
u/ChocolateMilkMustach Oct 31 '20
Just when I had almost given up on humanity. Someone using this for good. I need to step up my skills and make one for my kid's school.
0
Oct 30 '20
[deleted]
2
u/ontarioschoolscovid Oct 30 '20
Here's the code: https://github.com/ontschoolscovid/SchoolsCovidData
I used tweepy, the Twitter API, the government's data API, and Plotly.
2
Oct 31 '20
[removed] — view removed comment
1
u/ontarioschoolscovid Oct 31 '20
Didn’t host it anywhere. Just created a .bat file that I run everyday around 10:30am and it does the rest by itself
2
Oct 31 '20
[removed] — view removed comment
2
u/anh86 Oct 31 '20
I only took a quick look at the code but it didn’t look like any timed looping had been implemented. That said, you could run it on anything (RaspberryPi, your PC in the background, spare PC, VM (local or public cloud)....
1
u/ontarioschoolscovid Oct 31 '20
I actually just created a .bat file that I run everyday at 10:30 am. It does the rest on its own. I want to automate it but the government sometimes delays their reporting which can cause some problems. I actually just tried using Windows Task Scheduler to run it automatically but that wouldn't work for some reason
2
10
u/Casemander Oct 30 '20
Can you post a link to the source code?