Make Bookmarks scrapable from web UI
This commit is contained in:
parent
c52960759e
commit
7244bf51e9
@ -5,11 +5,31 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"gitlab.com/offline-twitter/twitter_offline_engine/pkg/persistence"
|
"gitlab.com/offline-twitter/twitter_offline_engine/pkg/persistence"
|
||||||
|
"gitlab.com/offline-twitter/twitter_offline_engine/pkg/scraper"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (app *Application) Bookmarks(w http.ResponseWriter, r *http.Request) {
|
func (app *Application) Bookmarks(w http.ResponseWriter, r *http.Request) {
|
||||||
app.traceLog.Printf("'Bookmarks' handler (path: %q)", r.URL.Path)
|
app.traceLog.Printf("'Bookmarks' handler (path: %q)", r.URL.Path)
|
||||||
|
|
||||||
|
// Run a scrape if needed
|
||||||
|
if r.URL.Query().Has("scrape") {
|
||||||
|
if app.IsScrapingDisabled {
|
||||||
|
app.InfoLog.Printf("Would have scraped: %s", r.URL.Path)
|
||||||
|
http.Error(w, "Scraping is disabled (are you logged in?)", 401)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run scraper
|
||||||
|
trove, err := scraper.GetBookmarks(300) // TODO: parameterizable
|
||||||
|
if err != nil && !errors.Is(err, scraper.END_OF_FEED) {
|
||||||
|
app.ErrorLog.Print(err)
|
||||||
|
panic(err) // Return a toast
|
||||||
|
}
|
||||||
|
|
||||||
|
app.Profile.SaveTweetTrove(trove, false)
|
||||||
|
go app.Profile.SaveTweetTrove(trove, true)
|
||||||
|
}
|
||||||
|
|
||||||
c := persistence.NewUserFeedBookmarksCursor(app.ActiveUser.Handle)
|
c := persistence.NewUserFeedBookmarksCursor(app.ActiveUser.Handle)
|
||||||
err := parse_cursor_value(&c, r)
|
err := parse_cursor_value(&c, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -104,7 +104,7 @@ func (app *Application) Search(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// Run scraper
|
// Run scraper
|
||||||
trove, err := scraper.Search(search_text, 1) // TODO: parameterizable
|
trove, err := scraper.Search(search_text, 1) // TODO: parameterizable
|
||||||
if err != nil {
|
if err != nil && !errors.Is(err, scraper.END_OF_FEED) {
|
||||||
app.ErrorLog.Print(err)
|
app.ErrorLog.Print(err)
|
||||||
// TOOD: show error in UI
|
// TOOD: show error in UI
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,24 @@
|
|||||||
|
|
||||||
{{define "main"}}
|
{{define "main"}}
|
||||||
<div class="bookmarks-feed-header">
|
<div class="bookmarks-feed-header">
|
||||||
|
<div class="row row--spread">
|
||||||
|
<div class="dummy"></div> {{/* Extra div to take up a slot in the `row` */}}
|
||||||
<h1>Bookmarks</h1>
|
<h1>Bookmarks</h1>
|
||||||
|
<div class="row">
|
||||||
|
<a class="button" target="_blank" href="https://twitter.com/i/bookmarks" title="Open on twitter.com">
|
||||||
|
<img class="svg-icon" src="/static/icons/external-link.svg" width="24" height="24" />
|
||||||
|
</a>
|
||||||
|
<a class="button" hx-get="?scrape" hx-target="body" hx-indicator=".bookmarks-feed-header" title="Refresh">
|
||||||
|
<img class="svg-icon" src="/static/icons/refresh.svg" width="24" height="24" />
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="htmx-spinner">
|
||||||
|
<div class="htmx-spinner__fullscreen-forcer">
|
||||||
|
<div class="htmx-spinner__background"></div>
|
||||||
|
<img class="svg-icon htmx-spinner__icon" src="/static/icons/spinner.svg" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="timeline">
|
<div class="timeline">
|
||||||
{{template "timeline" .Feed}}
|
{{template "timeline" .Feed}}
|
||||||
|
@ -24,10 +24,12 @@
|
|||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="htmx-spinner">
|
<div class="htmx-spinner">
|
||||||
|
<div class="htmx-spinner__fullscreen-forcer">
|
||||||
<div class="htmx-spinner__background"></div>
|
<div class="htmx-spinner__background"></div>
|
||||||
<img class="svg-icon htmx-spinner__icon" src="/static/icons/spinner.svg" />
|
<img class="svg-icon htmx-spinner__icon" src="/static/icons/spinner.svg" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
{{if .IsUsersSearch}}
|
{{if .IsUsersSearch}}
|
||||||
{{template "list" (dict "UserIDs" .UserIDs)}}
|
{{template "list" (dict "UserIDs" .UserIDs)}}
|
||||||
{{else}}
|
{{else}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user