Add a button to Search page to scrape search results
This commit is contained in:
parent
925f36c33a
commit
a65937d6e4
@ -93,6 +93,25 @@ func (app *Application) Search(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Actual search
|
||||||
|
// 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.Search(search_text, 1) // TODO: parameterizable
|
||||||
|
if err != nil {
|
||||||
|
app.ErrorLog.Print(err)
|
||||||
|
// TOOD: show error in UI
|
||||||
|
}
|
||||||
|
app.Profile.SaveTweetTrove(trove, false)
|
||||||
|
go app.Profile.SaveTweetTrove(trove, true)
|
||||||
|
}
|
||||||
|
|
||||||
c, err := persistence.NewCursorFromSearchQuery(search_text)
|
c, err := persistence.NewCursorFromSearchQuery(search_text)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.error_400_with_message(w, err.Error())
|
app.error_400_with_message(w, err.Error())
|
||||||
|
@ -2,22 +2,31 @@
|
|||||||
|
|
||||||
{{define "main"}}
|
{{define "main"}}
|
||||||
<div class="search-header">
|
<div class="search-header">
|
||||||
|
<div class="row spread">
|
||||||
|
<div class="dummy"></div> {{/* Extra div to take up a slot in the `row` */}}
|
||||||
<h1>Search results: {{.SearchText}}</h1>
|
<h1>Search results: {{.SearchText}}</h1>
|
||||||
|
<div class="user-feed-buttons-container">
|
||||||
|
<a class="unstyled-link quick-link" target="_blank" href="https://twitter.com/search?q={{.SearchText}}&src=typed_query&f=top" title="Open on twitter.com">
|
||||||
|
<img class="svg-icon" src="/static/icons/external-link.svg" width="24" height="24" />
|
||||||
|
</a>
|
||||||
|
<a class="unstyled-link quick-link" hx-get="?scrape" hx-target="body" hx-indicator=".search-header" title="Refresh">
|
||||||
|
<img class="svg-icon" src="/static/icons/refresh.svg" width="24" height="24" />
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="row tabs-container">
|
<div class="row tabs-container">
|
||||||
<a
|
<a class="tab unstyled-link {{if (not .IsUsersSearch)}}active-tab{{end}}" href="?type=tweets">
|
||||||
class="tab unstyled-link {{if (not .IsUsersSearch)}}active-tab{{end}}"
|
|
||||||
href="?type=tweets"
|
|
||||||
>
|
|
||||||
<span class="tab-inner">Tweets</span>
|
<span class="tab-inner">Tweets</span>
|
||||||
</a>
|
</a>
|
||||||
<a
|
<a class="tab unstyled-link {{if .IsUsersSearch}}active-tab{{end}}" href="?type=users">
|
||||||
class="tab unstyled-link {{if .IsUsersSearch}}active-tab{{end}}"
|
|
||||||
href="?type=users"
|
|
||||||
>
|
|
||||||
<span class="tab-inner">Users</span>
|
<span class="tab-inner">Users</span>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="htmx-spinner-container">
|
||||||
|
<div class="htmx-spinner-background"></div>
|
||||||
|
<img class="svg-icon htmx-spinner" src="/static/icons/spinner.svg" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{if .IsUsersSearch}}
|
{{if .IsUsersSearch}}
|
||||||
{{template "list" (dict "UserIDs" .UserIDs)}}
|
{{template "list" (dict "UserIDs" .UserIDs)}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user