misc fixes

This commit is contained in:
Paul 2020-03-30 01:05:25 +02:00
parent 8bdad9cbd2
commit 26dbbc08e1
3 changed files with 18 additions and 17 deletions

View File

@ -20,11 +20,6 @@ func main() {
log.Fatalln(err) log.Fatalln(err)
} }
cr, err = coronafana.GetData(cfg)
if err != nil {
log.Fatalln(err)
}
db, err := sqlx.Connect("mysql", db, err := sqlx.Connect("mysql",
fmt.Sprintf("%s:%s@tcp(%s)/%s", fmt.Sprintf("%s:%s@tcp(%s)/%s",
cfg.DbUsername, cfg.DbUsername,
@ -35,28 +30,33 @@ func main() {
log.Fatalln(err) log.Fatalln(err)
} }
_, err = db.Exec(cfg.DbSchemaGlobal)
if err != nil {
log.Fatalln(err)
}
_, err = db.Exec(cfg.DbSchemaPays)
if err != nil {
log.Fatalln(err)
}
cr, err = coronafana.GetData(cfg)
if err != nil {
log.Fatalln(err)
}
err = cr.GetMaxDates(cfg, *db) err = cr.GetMaxDates(cfg, *db)
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)
} }
// Processes data for 'Global' // Processes data for 'Global'
_, err = db.Exec(cfg.DbSchemaGlobal)
if err != nil {
log.Fatalln(err)
}
err = cr.InsertGlobalData(cfg, *db) err = cr.InsertGlobalData(cfg, *db)
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)
} }
// Processes data for 'Pays' // Processes data for 'Pays'
_, err = db.Exec(cfg.DbSchemaPays)
if err != nil {
log.Fatalln(err)
}
err = cr.InsertPaysData(cfg, *db) err = cr.InsertPaysData(cfg, *db)
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)

View File

@ -56,7 +56,7 @@ func (config *Config) GetConfig() (err error) {
ON DUPLICATE KEY UPDATE date=:date,infection=:infection, deces=:deces, guerisons=:guerisons, tauxdeces=:tauxdeces, tauxguerison=:tauxguerison, tauxinfection=:tauxinfection; ON DUPLICATE KEY UPDATE date=:date,infection=:infection, deces=:deces, guerisons=:guerisons, tauxdeces=:tauxdeces, tauxguerison=:tauxguerison, tauxinfection=:tauxinfection;
` `
config.DbMaxDateGlobal = `SELECT max(date) FROM coronaglobaldata;` config.DbMaxDateGlobal = `SELECT IFNULL(MAX(date),"0001-01-01 00:00:00") FROM coronaglobaldata;`
config.DbSchemaPays = ` config.DbSchemaPays = `
CREATE TABLE IF NOT EXISTS coronapaysdata CREATE TABLE IF NOT EXISTS coronapaysdata
@ -79,7 +79,7 @@ func (config *Config) GetConfig() (err error) {
VALUES (:date, :pays, :infection, :deces, :guerisons, :tauxdeces, :tauxguerison, :tauxinfection) VALUES (:date, :pays, :infection, :deces, :guerisons, :tauxdeces, :tauxguerison, :tauxinfection)
ON DUPLICATE KEY UPDATE date=:date, pays=:pays,infection=:infection, deces=:deces, guerisons=:guerisons, tauxdeces=:tauxdeces, tauxguerison=:tauxguerison, tauxinfection=:tauxinfection;` ON DUPLICATE KEY UPDATE date=:date, pays=:pays,infection=:infection, deces=:deces, guerisons=:guerisons, tauxdeces=:tauxdeces, tauxguerison=:tauxguerison, tauxinfection=:tauxinfection;`
config.DbMaxDatePays = `SELECT max(date) FROM coronapaysdata;` config.DbMaxDatePays = `SELECT IFNULL(MAX(date),"0001-01-01 00:00:00") FROM coronapaysdata;`
return return
} }

View File

@ -118,6 +118,7 @@ func (cr *Coronafana) ReplacePaysQuotes() (err error) {
for _, pdata := range cr.PaysData { for _, pdata := range cr.PaysData {
pdata.Pays = strings.Replace(pdata.Pays, `'`, `\'`, -1) pdata.Pays = strings.Replace(pdata.Pays, `'`, `\'`, -1)
} }
return return
} }