Compare commits

..

No commits in common. "e7a3230f93c8637fcd3d579d5fb1fd41320d7c07" and "028fb71fb3e750312d7516999c61a44771c13ecf" have entirely different histories.

7 changed files with 24 additions and 62 deletions

View file

@ -203,4 +203,4 @@
* November: [Daniel Suarez "Daemon: Die Welt ist nur ein Spiel"](https://www.buchhandel.de/buch/9783499256431) * November: [Daniel Suarez "Daemon: Die Welt ist nur ein Spiel"](https://www.buchhandel.de/buch/9783499256431)
* Dezember: [William Gibson "Quellcode"](https://www.buchhandel.de/buch/9783453526808) * Dezember: [William Gibson "Quellcode"](https://www.buchhandel.de/buch/9783453526808)
## 2009 ## 2009

View file

@ -88,6 +88,4 @@
* September: [Denis Bajram "Death Experience"](https://www.buchhandel.de/buch/9783958390270) * September: [Denis Bajram "Death Experience"](https://www.buchhandel.de/buch/9783958390270)
* Oktober: [Christophe Arleston "Morea"](https://www.buchhandel.de/buch/9783939823902) * Oktober: [Christophe Arleston "Morea"](https://www.buchhandel.de/buch/9783939823902)
* November: [Neil Gaiman "American Gods"](https://www.buchhandel.de/buch/9783962196004) * November: [Neil Gaiman "American Gods"](https://www.buchhandel.de/buch/9783962196004)
* Dezember: [Christophe Bec "Olympus Mons"](https://www.buchhandel.de/buch/9783962190200) * Dezember: [Christophe Bec "Olympus Mons"](https://www.buchhandel.de/buch/9783962190200)
## 2017

View file

@ -12,47 +12,33 @@ import (
) )
type Item struct { type Item struct {
ISBN string ISBN string
FileExtension string Author string
Author string Title string
Title string Filename string
Filename string Date string
Date string
} }
func (i Item) ImageURL(extension string) string { func (i Item) ImageURL() string {
return "https://medien.umbreitkatalog.de/bildzentrale_original/" + return "https://medien.umbreitkatalog.de/bildzentrale_original/" +
i.ISBN[0:3] + "/" + i.ISBN[0:3] + "/" +
i.ISBN[3:6] + "/" + i.ISBN[3:6] + "/" +
i.ISBN[6:9] + "/" + i.ISBN[6:9] + "/" +
i.ISBN[9:13] + i.ISBN[9:13] +
"." + extension ".jpg"
} }
func (i Item) targetFilename(extension string) string { func (i Item) targetFilename() string {
return "covers/" + i.ISBN + "." + extension return "covers/" + i.ISBN + ".jpg"
} }
func (i Item) downloadCover() error { func (i Item) downloadCover() error {
extension := "jpg" resp, err := http.Get(i.ImageURL())
fmt.Printf("Downloading %v ...\n", i.ImageURL(extension))
resp, err := http.Get(i.ImageURL(extension))
if err != nil { if err != nil {
return err return err
} }
// TODO: refactor later ...
if resp.StatusCode == 404 {
extension = "png"
fmt.Printf("Downloading %v ...\n", i.ImageURL(extension))
resp, err = http.Get(i.ImageURL(extension))
if err != nil {
return err
}
}
defer func(Body io.ReadCloser) { defer func(Body io.ReadCloser) {
err := Body.Close() err := Body.Close()
if err != nil { if err != nil {
@ -64,7 +50,7 @@ func (i Item) downloadCover() error {
return fmt.Errorf("HTTP status code is %d", resp.StatusCode) return fmt.Errorf("HTTP status code is %d", resp.StatusCode)
} }
out, err := os.Create(i.targetFilename(extension)) out, err := os.Create(i.targetFilename())
if err != nil { if err != nil {
return err return err
} }
@ -127,18 +113,12 @@ func getItems(filename string) []Item {
if len(matches) == 4 { if len(matches) == 4 {
currentMonth++ currentMonth++
extension, err := getFileExtension(matches[3])
if err != nil {
log.Printf("%v", err)
}
yearBucket = append(yearBucket, Item{ yearBucket = append(yearBucket, Item{
ISBN: matches[3], Author: strings.Trim(matches[1], " "),
FileExtension: extension, Title: strings.Trim(matches[2], " "),
Author: strings.Trim(matches[1], " "), ISBN: matches[3],
Title: strings.Trim(matches[2], " "), Date: fmt.Sprintf("01-%02d-%s", currentMonth, currentYear),
Filename: filename, Filename: filename,
Date: fmt.Sprintf("01-%02d-%s", currentMonth, currentYear),
}) })
} }
} }
@ -151,23 +131,6 @@ func getItems(filename string) []Item {
return items return items
} }
func getFileExtension(isbn string) (string, error) {
// List all files in covers directory
// TODO: Cache this line
files, err := os.ReadDir("covers/")
if err != nil {
log.Fatal("Can not read the covers directory")
return "", err
}
for _, file := range files {
if strings.HasPrefix(file.Name(), isbn) {
return strings.Split(file.Name(), ".")[1], nil
}
}
return "", fmt.Errorf("File not found for ISBN: %v", isbn)
}
func getTemplate(sourceFile string, templateFilename string, w http.ResponseWriter) { func getTemplate(sourceFile string, templateFilename string, w http.ResponseWriter) {
// Get all items from the git repo // Get all items from the git repo
items := getItems(sourceFile) items := getItems(sourceFile)
@ -204,11 +167,12 @@ func main() {
items := getItems(filename) items := getItems(filename)
for _, item := range items { for _, item := range items {
fmt.Printf("Downloading %v ...\n", item.ImageURL())
err := item.downloadCover() err := item.downloadCover()
if err != nil { if err != nil {
fmt.Printf("%v", err) fmt.Printf("%v", err)
fmt.Printf("ERROR: File %s not found\n", item.ImageURL("jpg")) fmt.Printf("ERROR: File %s not found\n", item.ImageURL())
} }
} }
}) })

View file

@ -24,7 +24,7 @@
<div id="covers"> <div id="covers">
{{ range .Items }} {{ range .Items }}
<div class="cover-item"> <div class="cover-item">
<a target="_blank" href="https://www.buchhandel.de/buch/{{ .ISBN }}"><img src="/covers/{{ .ISBN }}.{{ .FileExtension }}" alt="{{ .Author | html }} - {{ .Title | html }}" title="zu buchhandel.de" /></a> <a target="_blank" href="https://www.buchhandel.de/buch/{{ .ISBN }}"><img src="/covers/{{ .ISBN }}.jpg" alt="{{ .Author | html }} - {{ .Title | html }}" title="zu buchhandel.de" /></a>
</div> </div>
{{ end }} {{ end }}
</div> </div>

View file

@ -18,7 +18,7 @@
<summary>{{ .Author | html }} - "{{ .Title | html }}</summary> <summary>{{ .Author | html }} - "{{ .Title | html }}</summary>
<content type="xhtml"> <content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml"> <div xmlns="http://www.w3.org/1999/xhtml">
<img src="https://buchdesmonats.okoyono.de/covers/{{ .ISBN }}.{{ .FileExtension }}"/> <img src="https://buchdesmonats.okoyono.de/covers/{{ .ISBN }}.jpg"/>
</div> </div>
</content> </content>
</entry> </entry>

View file

@ -19,7 +19,7 @@
<div id="covers"> <div id="covers">
{{ range .Items }} {{ range .Items }}
<div class="cover-item"> <div class="cover-item">
<a target="_blank" href="https://www.buchhandel.de/buch/{{ .ISBN }}"><img src="/covers/{{ .ISBN }}.{{ .FileExtension }}" alt="{{ .Author | html }} - {{ .Title | html }}" title="zu buchhandel.de" /></a> <a target="_blank" href="https://www.buchhandel.de/buch/{{ .ISBN }}"><img src="/covers/{{ .ISBN }}.jpg" alt="{{ .Author | html }} - {{ .Title | html }}" title="zu buchhandel.de" /></a>
</div> </div>
{{ end }} {{ end }}
</div> </div>

View file

@ -18,7 +18,7 @@
<summary>{{ .Author | html }} - "{{ .Title | html }}"</summary> <summary>{{ .Author | html }} - "{{ .Title | html }}"</summary>
<content type="xhtml"> <content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml"> <div xmlns="http://www.w3.org/1999/xhtml">
<img src="https://comicdesmonats.okoyono.de/covers/{{ .ISBN }}.{{ .FileExtension }}"/> <img src="https://comicdesmonats.okoyono.de/covers/{{ .ISBN }}.jpg"/>
</div> </div>
</content> </content>
</entry> </entry>