-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.go
66 lines (56 loc) · 1.69 KB
/
data.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package data
import (
"fmt"
. "github.com/woojiahao/govid-19/pkg/utility"
"gopkg.in/src-d/go-git.v4"
"os"
)
type RepoPath string
const (
Root RepoPath = "tmp"
DailyReports RepoPath = "tmp/csse_covid_19_data/csse_covid_19_daily_reports"
TimeSeries RepoPath = "tmp/csse_covid_19_data/csse_covid_19_time_series"
ConfirmedTimeSeries = TimeSeries + "/time_series_covid19_confirmed_global.csv"
DeathsTimeSeries = TimeSeries + "/time_series_covid19_deaths_global.csv"
RecoveredTimeSeries = TimeSeries + "/time_series_covid19_recovered_global.csv"
)
// Load the repository into /tmp.
func load() {
_, err := git.PlainClone(string(Root), false, &git.CloneOptions{
URL: "https://github.com/CSSEGISandData/COVID-19.git",
Progress: os.Stdout,
})
Check(err)
}
// Update the repository to the latest changes.
func update() {
r, err := git.PlainOpen(string(Root))
Check(err)
w, err := r.Worktree()
Check(err)
err = w.Pull(&git.PullOptions{
RemoteName: "origin",
Progress: os.Stdout,
})
if err != nil {
if err == git.NoErrAlreadyUpToDate {
fmt.Println("Repository is up-to-date")
} else {
panic(err)
}
}
}
// If the current instance already contains the repository, pull the latest changes from the repository
// If the current instance does not contain the repository, clone the repository
func Update() {
if _, err := os.Stat(string(Root)); os.IsNotExist(err) {
tmp := os.Mkdir(string(Root), 0755)
Check(tmp)
load()
} else {
update()
}
}
func Load() (Series, Series, Series) {
return getTimeSeries(Confirmed), getTimeSeries(Recovered), getTimeSeries(Deaths)
}