Last active
November 6, 2020 05:46
-
-
Save Abdisalan/3f39c9eaab31309049c6bf2143755893 to your computer and use it in GitHub Desktop.
Get notified by ABC 2020 Election Results
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import os | |
import requests | |
from bs4 import BeautifulSoup | |
def get_results(): | |
print("checking...") | |
page = requests.get( | |
"https://abcnews.go.com/Elections/2020-us-presidential-election-results-live-map/") | |
soup = BeautifulSoup(page.content, 'html.parser') | |
biden_count = int(soup.select( | |
'div.Candidate--democrat div.Candidate__Votes')[0].text) | |
trump_count = int(soup.select( | |
'div.Candidate--republican div.Candidate__Votes')[0].text) | |
if biden_count >= 270: | |
os.system('say Joe Biden projected to win the election.') | |
print("Biden wins") | |
elif trump_count >= 270: | |
os.system('say Donald Trump projected to win the election.') | |
print("Trump wins") | |
time.sleep(60*15) # 15 minutes | |
while True: | |
get_results() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment