summaryrefslogtreecommitdiff
path: root/rhimport
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-03-10 18:34:18 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-03-10 18:34:18 (GMT)
commit1e2ba79b90cba21688667f14e1cc340cdb11870d (patch)
treeb8169f979b91f48db6e3ede3b465abb0afd1516f /rhimport
parent83feaa69a8bb4cb341d7f6f98b651cb660bc11c8 (diff)
generating archiv file string from uri
Diffstat (limited to 'rhimport')
-rw-r--r--rhimport/fetcher.go43
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)