Removes the crappy reddit news mentions thingy
This commit is contained in:
parent
82115cd4dd
commit
0e592091f5
@ -34,13 +34,6 @@ func (a *App) pageStyle(w http.ResponseWriter, r *http.Request, vars handlerVars
|
||||
return a.templates["style"].Execute(w, nil)
|
||||
}
|
||||
|
||||
func (a *App) pageNews(w http.ResponseWriter, r *http.Request, vars handlerVars) error {
|
||||
return a.templates["news"].Execute(w, map[string]interface{}{
|
||||
"Reddit": a.news,
|
||||
"Hub": a.hub,
|
||||
})
|
||||
}
|
||||
|
||||
func (a *App) pageServer(w http.ResponseWriter, r *http.Request, vars handlerVars) error {
|
||||
id := vars["id"]
|
||||
server, err := a.store.GetServer(id)
|
||||
|
||||
6
main.go
6
main.go
@ -6,7 +6,6 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/SlyMarbo/rss"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
@ -36,7 +35,6 @@ type App struct {
|
||||
web *http.Server
|
||||
store Storage
|
||||
templates map[string]*template.Template
|
||||
news []*rss.Item
|
||||
hub ServerEntry // TODO: probably needs to be protected with a lock
|
||||
}
|
||||
|
||||
@ -62,7 +60,6 @@ func New(c Conf) (*App, error) {
|
||||
r := mux.NewRouter()
|
||||
r.Handle("/", handler(a.pageIndex))
|
||||
r.Handle("/static/style.css", handler(a.pageStyle))
|
||||
r.Handle("/news", handler(a.pageNews))
|
||||
r.Handle("/server/{id}", handler(a.pageServer))
|
||||
r.Handle("/server/{id}/daily", handler(a.pageDailyChart))
|
||||
r.Handle("/server/{id}/weekly", handler(a.pageWeeklyChart))
|
||||
@ -91,9 +88,6 @@ func (a *App) Run() error {
|
||||
a.Log("Running updater")
|
||||
go a.runUpdater(webClient)
|
||||
|
||||
a.Log("Running reddit watcher")
|
||||
go a.runRedditWatcher(webClient)
|
||||
|
||||
a.Log("Running server on %s", a.conf.WebAddr)
|
||||
return a.web.ListenAndServe()
|
||||
}
|
||||
|
||||
35
reddit.go
35
reddit.go
@ -1,35 +0,0 @@
|
||||
package ss13_se
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/SlyMarbo/rss"
|
||||
)
|
||||
|
||||
const redditURL string = "https://www.reddit.com/r/SS13/search.rss?q=ss13.se&restrict_sr=on&t=year&sort=new"
|
||||
|
||||
func (a *App) runRedditWatcher(webClient *http.Client) {
|
||||
f := func(url string) (*http.Response, error) {
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Add("User-Agent", userAgent)
|
||||
return webClient.Do(req)
|
||||
}
|
||||
|
||||
for {
|
||||
start := time.Now()
|
||||
feed, err := rss.FetchByFunc(f, redditURL)
|
||||
dur := time.Since(start)
|
||||
if err != nil {
|
||||
a.Log("Updated reddit in %s, errors: %v", dur, err)
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
a.news = feed.Items
|
||||
}
|
||||
time.Sleep(a.conf.ScrapeTimeout)
|
||||
}
|
||||
}
|
||||
10
templates.go
10
templates.go
@ -43,7 +43,6 @@ const tmplBase string = `<!DOCTYPE html>
|
||||
<header>
|
||||
<a href="/">ss13.se</a>
|
||||
<a href="/server/{{.Hub.ID}}">Global stats</a>
|
||||
<a href="/news">Latest news</a>
|
||||
<p class="right">Last updated: {{.Hub.LastUpdated}}</p>
|
||||
</header>
|
||||
|
||||
@ -147,15 +146,6 @@ footer {
|
||||
</tbody>
|
||||
</table>
|
||||
{{end}}
|
||||
`,
|
||||
|
||||
"news": `{{define "title"}}News{{end}}
|
||||
{{define "body"}}
|
||||
<h1>Latest mentions on reddit</h1>
|
||||
<ul>{{range .Reddit}}
|
||||
<li><a href="{{.Link}}">{{.Title}}</a></li>
|
||||
{{end}}</ul>
|
||||
{{end}}
|
||||
`,
|
||||
|
||||
"server": `{{define "title"}}{{.Server.Title}}{{end}}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user