diff options
-rw-r--r-- | rhimport/fetcher.go | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/rhimport/fetcher.go b/rhimport/fetcher.go index 5c26637..9d5280b 100644 --- a/rhimport/fetcher.go +++ b/rhimport/fetcher.go @@ -158,10 +158,41 @@ func fetchFileCurl(ctx *Context, res *Result, uri *url.URL) (err error) { return } -func generateArchivFilePath(uri string) (file, path string, err error) { - //TODO: parse date/time from uri and create filename - file = "2016-02-29-1500.ogg" - path = "/srv/archiv/2016/02-Februar/29-Montag" +var months = [...]string{ + "Jänner", + "Februar", + "März", + "April", + "Mai", + "Juni", + "Juli", + "August", + "September", + "Oktober", + "November", + "Dezember", +} + +var weekdays = [...]string{ + "Sonntag", + "Montag", + "Dienstag", + "Mittwoch", + "Donnerstag", + "Freitag", + "Samstag", +} + +func generateArchivFilePath(uri *url.URL) (file, path string, err error) { + var t time.Time + + if t, err = time.Parse("2006/01/02/15", fmt.Sprintf("%s%s", uri.Host, uri.Path)); err != nil { + return + } + + file = t.Format("2006-01-02-15") + "00.ogg" + // TODO: make basepath configurable + path = fmt.Sprintf("/srv/archiv/%04d/%02d-%s/%02d-%s", t.Year(), t.Month(), months[t.Month()-1], t.Day(), weekdays[t.Weekday()]) return } @@ -170,7 +201,7 @@ func fetchFileArchiv(ctx *Context, res *Result, uri *url.URL) (err error) { rhdl.Printf("archiv fetcher called for '%s'", ctx.SourceUri) var srcfile, srcpath string - if srcfile, srcpath, err = generateArchivFilePath(ctx.SourceUri); err != nil { + if srcfile, srcpath, err = generateArchivFilePath(uri); err != nil { res.ResponseCode = http.StatusBadRequest res.ErrorString = fmt.Sprintf("date/time is invalid: %s", err) return nil @@ -204,7 +235,7 @@ func fetchFileArchiv(ctx *Context, res *Result, uri *url.URL) (err error) { easy.Setopt(curl.OPT_PROGRESSFUNCTION, curlProgressCallback) easy.Setopt(curl.OPT_PROGRESSDATA, cbdata) - rhdl.Printf("importing archiv file using from %s", scpuri) + rhdl.Printf("importing archiv file from %s", scpuri) if err = easy.Perform(); err != nil { if cbdata.file != nil { rhdl.Printf("Removing stale file: %s", cbdata.filename) |