Skip to content

Commit 4f4605c

Browse files
committed
fix for missing today swisscovid export
1 parent ef6e053 commit 4f4605c

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.DS_Store
12
*.bin
23
out
34
build

download.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ func Download(workDir, app string) error {
2626
return err
2727
}
2828

29-
latest, _ := dwln.GetLatestExport()
29+
latest, err := dwln.GetLatestExport()
30+
if err != nil {
31+
return err
32+
}
3033
latestURL := dwln.GetURL(latest)
3134

3235
filepath := filepath.Join(workDir, app, latest)

downloader.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,27 @@ type SwissCovidDownloader struct{}
6565

6666
// GetLatestExport returns the latest SwissCovid export
6767
func (d SwissCovidDownloader) GetLatestExport() (string, error) {
68-
now := time.Now()
69-
nowMidnight := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.UTC)
70-
return strconv.Itoa(int(nowMidnight.Unix() * 1000)), nil
68+
retry := 0
69+
70+
for retry < 3 {
71+
now := time.Now()
72+
nowMidnight := time.Date(now.Year(), now.Month(), now.Day()-retry, 0, 0, 0, 0, time.UTC)
73+
latestExport := strconv.Itoa(int(nowMidnight.Unix() * 1000))
74+
75+
url := d.GetURL(latestExport)
76+
resp, err := http.Get(url)
77+
if err != nil {
78+
return "", err
79+
}
80+
resp.Body.Close()
81+
82+
if resp.StatusCode == http.StatusOK {
83+
return latestExport, nil
84+
}
85+
retry++
86+
}
87+
88+
return "", fmt.Errorf("error getting latest swisscovid export")
7189
}
7290

7391
// GetURL returns the SwissCovid URL where to download the export

0 commit comments

Comments
 (0)