Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/lowJ/CovidAlerts
Browse files Browse the repository at this point in the history
  • Loading branch information
Vakhshoori101 committed Aug 5, 2020
2 parents d24fbe2 + df45df1 commit b0e0570
Showing 1 changed file with 54 additions and 14 deletions.
68 changes: 54 additions & 14 deletions covidalerts/app/signup/update.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,61 @@
import csv
import urllib.request as request
import time
import sms
import db_interface
import data_processing

#updated live file
r = request.urlopen("https://raw.githubusercontent.com/nytimes/covid-19-data/master/live/us-counties.csv").read().decode('utf8').split("\n")
reader = csv.reader(r)
#Helper to send text message
def sendMessage(phone, state, county):
r = data_processing.getday(state, county)
if r is None:
to_send = f"Could not find {county}, {state} in database."
else:
cases, deaths = r
to_send = f"Todays confirmed cases in {county} {state}: " + str(cases) + " confirmed deaths: " + str(deaths)

with open("live-us-counties.csv", "w", newline="") as csvfile:
writer = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
for line in reader:
writer.writerow(line)
sms.send_message(phone, to_send)


def update():
try:
#updated live file
r = request.urlopen("https://raw.githubusercontent.com/nytimes/covid-19-data/master/live/us-counties.csv").read().decode('utf8').split("\n")
reader = csv.reader(r)

#update the past file
r2 = request.urlopen("https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv").read().decode('utf8').split("\n")
reader2 = csv.reader(r2)
with open("live-us-counties.csv", "w", newline="") as csvfile:
writer = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
for line in reader:
writer.writerow(line)

with open("ago-us-counties.csv", "w", newline="") as csvfile2:
writer2 = csv.writer(csvfile2, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
for line in reader2:
writer2.writerow(line)
#update the past file
r2 = request.urlopen("https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv").read().decode('utf8').split("\n")
reader2 = csv.reader(r2)

with open("ago-us-counties.csv", "w", newline="") as csvfile2:
writer2 = csv.writer(csvfile2, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
for line in reader2:
writer2.writerow(line)

#Sends out texts to all users if update was successful
db_interface.call_on_all_phone_num(sendMessage)
return True

except:
return False



if __name__ == "__main__":
mins = 0
update()

#Continues to run the script until it is able to update
while update() != True:
#Keeps track of each min that passes
time.sleep(60)
mins += 1

#Runs the script again every 5 mins
if mins % 5 == 0:
update()

0 comments on commit b0e0570

Please sign in to comment.