Compare commits

...

5 Commits

Author SHA1 Message Date
74c08b191a Update 'README.md'
All checks were successful
continuous-integration/drone/push Build is passing
2020-04-28 18:17:54 +00:00
10d78b7497 remove artifcats
All checks were successful
continuous-integration/drone/push Build is passing
2020-04-25 01:57:27 -06:00
ecfa12d3ed time zone
All checks were successful
continuous-integration/drone/push Build is passing
2020-04-25 01:50:38 -06:00
4b70470a86 remove redundant output
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2020-04-25 01:41:45 -06:00
aa52e42d9e update example 2020-04-25 01:41:36 -06:00
4 changed files with 2 additions and 5 deletions

View File

@ -3,8 +3,6 @@
[![Build Status](https://drone.deadbeef.codes/api/badges/steven/covid19-edmonton/status.svg)](https://drone.deadbeef.codes/steven/covid19-edmonton) [![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. 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] ![alt text][logo]

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.8 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View File

@ -93,7 +93,6 @@ func main() {
if err != nil { if err != nil {
log.Fatalf("failed to get data from alberta government website: %v", err) log.Fatalf("failed to get data from alberta government website: %v", err)
} }
fmt.Printf("As of %s Mountain Time (the real time)\n\n", cache.UpdatedDate.Format("2006 Jan 02 15:04:05"))
// CLI mode, print output to stdout // CLI mode, print output to stdout
fmt.Println("Edmonton Active: ", cache.Data.ActiveCasesEdmonton) fmt.Println("Edmonton Active: ", cache.Data.ActiveCasesEdmonton)
fmt.Println("Edmonton Total: ", cache.Data.TotalCasesEdmonton) fmt.Println("Edmonton Total: ", cache.Data.TotalCasesEdmonton)
@ -137,7 +136,7 @@ func getUpdatedData() (*Cache, error) {
return nil, fmt.Errorf("failed to parse data as json: %v", err) return nil, fmt.Errorf("failed to parse data as json: %v", err)
} }
cache := &Cache{UpdatedDate: time.Now()} cache := &Cache{UpdatedDate: time.Now().Add(-time.Hour * 6)}
// count the cases // count the cases
for i := range data[2] { for i := range data[2] {
@ -164,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") 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 return
} }
if time.Now().After(cache.UpdatedDate.Add(cacheTimeout)) { if time.Now().Add(-time.Hour * 6).After(cache.UpdatedDate.Add(cacheTimeout)) {
w.WriteHeader(http.StatusOK) 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. 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 { if err != nil {