Compare commits

..

No commits in common. "master" and "2.0" have entirely different histories.
master ... 2.0

3 changed files with 4 additions and 2 deletions

View File

@ -3,6 +3,8 @@
[![Build Status](https://drone.deadbeef.codes/api/badges/steven/covid19-edmonton/status.svg)](https://drone.deadbeef.codes/steven/covid19-edmonton)
Currently deployed at https://edmonton.deadbeef.codes
I was bored and want to keep tabs on this in my area. Will download latest stats from alberta government website for COVID-19 and output the number of total and active cases in my area. Here's an example, it runs and nearly instantaneous spits out the current numbers.
![alt text][logo]

BIN
covid19-edmonton.exe Normal file

Binary file not shown.

View File

@ -136,7 +136,7 @@ func getUpdatedData() (*Cache, error) {
return nil, fmt.Errorf("failed to parse data as json: %v", err)
}
cache := &Cache{UpdatedDate: time.Now().Add(-time.Hour * 6)}
cache := &Cache{UpdatedDate: time.Now()}
// count the cases
for i := range data[2] {
@ -163,7 +163,7 @@ func homePageHandler(w http.ResponseWriter, r *http.Request) {
log.Printf("unable to serve page due to no cached data, possibly due to application still starting up, or AB government site down, or changed formatting - may need to review how page is parsed")
return
}
if time.Now().Add(-time.Hour * 6).After(cache.UpdatedDate.Add(cacheTimeout)) {
if time.Now().After(cache.UpdatedDate.Add(cacheTimeout)) {
w.WriteHeader(http.StatusOK)
tempCache, err := getUpdatedData() // Hold tempCache in case there's an error, we don't want to nullify our pointer to a working cache that has aged. We will proceed with aged data.
if err != nil {