Skip to content

Commit

Permalink
autogen: using the original URL when downloading PDF fails
Browse files Browse the repository at this point in the history
  • Loading branch information
lonng committed Jun 2, 2024
1 parent f604358 commit ff03dfb
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions autogen/autogen.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,23 +242,32 @@ func convert(opt *options) error {

// Download the paper is not exists
if _, err := os.Stat(path); os.IsNotExist(err) {
paper, err := http.Get(r.url)
if err != nil {
return err
fetch := func() error {
paper, err := http.Get(r.url)
if err != nil {
return err
}

fmt.Println("Download Paper", r.title)
fmt.Println(padding(2), "url", r.url)
fmt.Println(padding(2), "path", path)

data, err := io.ReadAll(paper.Body)
if err != nil {
return err
}

// Write to file
if err := os.WriteFile(path, data, 0644); err != nil {
return err
}

return nil
}

fmt.Println("Download Paper", r.title)
fmt.Println(padding(2), "url", r.url)
fmt.Println(padding(2), "path", path)

data, err := io.ReadAll(paper.Body)
if err != nil {
return err
}

// Write to file
if err := os.WriteFile(path, data, 0644); err != nil {
return err
if err := fetch(); err != nil {
fmt.Println(padding(2), "failed to download paper", err)
url = r.url
}
}

Expand Down

0 comments on commit ff03dfb

Please sign in to comment.