This commit is contained in:
parent
0d9ed8874f
commit
cccddb3172
@ -1,6 +1,6 @@
|
|||||||
FROM golang:1.14 as builder
|
FROM golang:1.14 as builder
|
||||||
|
|
||||||
WORKDIR /go/src/git.eeqj.de/sneak/hntransparencylog
|
WORKDIR /go/src/git.eeqj.de/sneak/orangesite
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
#RUN make lint && make build
|
#RUN make lint && make build
|
||||||
@ -16,9 +16,9 @@ FROM alpine
|
|||||||
|
|
||||||
RUN mkdir -p /app/bin
|
RUN mkdir -p /app/bin
|
||||||
|
|
||||||
COPY --from=builder /go/src/git.eeqj.de/sneak/hntransparencylog/server /app/bin/server
|
COPY --from=builder /go/src/git.eeqj.de/sneak/orangesite/server /app/bin/server
|
||||||
# FIXME figure out how to embed these stupid templates
|
# FIXME figure out how to embed these stupid templates
|
||||||
COPY --from=builder /go/src/git.eeqj.de/sneak/hntransparencylog/view /app/view
|
COPY --from=builder /go/src/git.eeqj.de/sneak/orangesite/view /app/view
|
||||||
|
|
||||||
# put the source in there too for safekeeping
|
# put the source in there too for safekeeping
|
||||||
COPY --from=builder /go/go-src.tgz /usr/local/src/go-src.tgz
|
COPY --from=builder /go/go-src.tgz /usr/local/src/go-src.tgz
|
||||||
|
2
Makefile
2
Makefile
@ -10,7 +10,7 @@ BUILDHOST := $(shell hostname -s)
|
|||||||
BUILDARCH := $(shell uname -m)
|
BUILDARCH := $(shell uname -m)
|
||||||
|
|
||||||
FN := server
|
FN := server
|
||||||
IMAGENAME := sneak/hntransparencylog
|
IMAGENAME := sneak/orangesite
|
||||||
|
|
||||||
UNAME_S := $(shell uname -s)
|
UNAME_S := $(shell uname -s)
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"git.eeqj.de/sneak/hntransparencylog/hn"
|
"git.eeqj.de/sneak/orangesite/hn"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Version string
|
var Version string
|
||||||
|
@ -12,8 +12,6 @@ import (
|
|||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SQLITE_NULL_DATETIME = "0001-01-01 00:00:00+00:00"
|
|
||||||
|
|
||||||
func NewFetcher(db *gorm.DB) *Fetcher {
|
func NewFetcher(db *gorm.DB) *Fetcher {
|
||||||
f := new(Fetcher)
|
f := new(Fetcher)
|
||||||
f.db = db
|
f.db = db
|
||||||
@ -99,14 +97,18 @@ func (f *Fetcher) StoreFrontPage() error {
|
|||||||
// disabled for now
|
// disabled for now
|
||||||
//f.db.Create(&s)
|
//f.db.Create(&s)
|
||||||
|
|
||||||
|
//FIXME check to see if the same HNID was already on the frontpage
|
||||||
|
//or not so we don't spam the db
|
||||||
|
|
||||||
// check to see if the item was on the frontpage already or not
|
// check to see if the item was on the frontpage already or not
|
||||||
var c int
|
var c int
|
||||||
f.db.Model(&HNFrontPage{}).Where("hn_id = ? and disappeared is ?", id, SQLITE_NULL_DATETIME).Count(&c)
|
f.db.Model(&HNFrontPage{}).Where("hn_id = ?", id).Count(&c)
|
||||||
if c == 0 {
|
if c == 0 {
|
||||||
// first appearance on frontpage
|
// first appearance on frontpage
|
||||||
r := HNFrontPage{
|
r := HNFrontPage{
|
||||||
HNID: uint(id),
|
HNID: uint(id),
|
||||||
Appeared: t,
|
Appeared: t,
|
||||||
|
Disappeared: time.Time{},
|
||||||
HighestRank: uint(i + 1),
|
HighestRank: uint(i + 1),
|
||||||
Rank: uint(i + 1),
|
Rank: uint(i + 1),
|
||||||
Title: item.Title,
|
Title: item.Title,
|
||||||
@ -122,11 +124,10 @@ func (f *Fetcher) StoreFrontPage() error {
|
|||||||
Str("url", item.URL).
|
Str("url", item.URL).
|
||||||
Msg("HN new story on frontpage")
|
Msg("HN new story on frontpage")
|
||||||
} else {
|
} else {
|
||||||
// it's still here, compare its ranking
|
// it's still here, (or back)
|
||||||
var old HNFrontPage
|
var old HNFrontPage
|
||||||
f.db.Model(&HNFrontPage{}).Where("hn_id = ? and disappeared is ?", id, SQLITE_NULL_DATETIME).First(&old)
|
f.db.Model(&HNFrontPage{}).Where("hn_id = ?", id).First(&old)
|
||||||
// FIXME update highestrank if new is lower
|
|
||||||
needSave := false
|
|
||||||
if old.Rank != uint(i+1) {
|
if old.Rank != uint(i+1) {
|
||||||
f.log.Info().
|
f.log.Info().
|
||||||
Uint("hnid", uint(id)).
|
Uint("hnid", uint(id)).
|
||||||
@ -138,7 +139,6 @@ func (f *Fetcher) StoreFrontPage() error {
|
|||||||
Msg("HN story rank changed, recording new rank")
|
Msg("HN story rank changed, recording new rank")
|
||||||
old.Rank = uint(i + 1)
|
old.Rank = uint(i + 1)
|
||||||
old.Score = uint(item.Score)
|
old.Score = uint(item.Score)
|
||||||
needSave = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if old.HighestRank > uint(i+1) {
|
if old.HighestRank > uint(i+1) {
|
||||||
@ -148,24 +148,22 @@ func (f *Fetcher) StoreFrontPage() error {
|
|||||||
Uint("newrecord", uint(i+1)).
|
Uint("newrecord", uint(i+1)).
|
||||||
Msg("recording new record high rank for story")
|
Msg("recording new record high rank for story")
|
||||||
old.HighestRank = uint(i + 1)
|
old.HighestRank = uint(i + 1)
|
||||||
needSave = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if old.Score != uint(item.Score) {
|
if old.Score != uint(item.Score) {
|
||||||
old.Score = uint(item.Score)
|
old.Score = uint(item.Score)
|
||||||
needSave = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if needSave {
|
// in any case it's here now
|
||||||
f.db.Save(&old)
|
old.Disappeared = time.Time{}
|
||||||
}
|
f.db.Save(&old)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME iterate over frontpage items still active in DB and note any
|
// FIXME iterate over frontpage items still active in DB and note any
|
||||||
// that are no longer on the scrape
|
// that are no longer on the scrape
|
||||||
fpitems, err := f.db.Model(&HNFrontPage{}).Where("disappeared is ?", SQLITE_NULL_DATETIME).Rows()
|
fpitems, err := f.db.Model(&HNFrontPage{}).Where("disappeared is ?", time.Time{}).Rows()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
f.log.Error().
|
f.log.Error().
|
||||||
Err(err)
|
Err(err)
|
||||||
@ -196,8 +194,8 @@ func (f *Fetcher) StoreFrontPage() error {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fpitems.Close() // close tx before we do the update
|
fpitems.Close() // close result before we do the update
|
||||||
f.db.Model(&HNFrontPage{}).Where("disappeared is ? and hn_id in (?)", SQLITE_NULL_DATETIME, toupdate).Update("Disappeared", t)
|
f.db.Model(&HNFrontPage{}).Where("disappeared is ? and hn_id in (?)", time.Time{}, toupdate).Update("Disappeared", t)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -10,18 +10,20 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type RequestHandlerSet struct {
|
type RequestHandlerSet struct {
|
||||||
db *gorm.DB
|
db *gorm.DB
|
||||||
|
version string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRequestHandlerSet(db *gorm.DB) *RequestHandlerSet {
|
func NewRequestHandlerSet(version string, db *gorm.DB) *RequestHandlerSet {
|
||||||
rhs := new(RequestHandlerSet)
|
rhs := new(RequestHandlerSet)
|
||||||
rhs.db = db
|
rhs.db = db
|
||||||
|
rhs.version = version
|
||||||
return rhs
|
return rhs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RequestHandlerSet) indexHandler(c echo.Context) error {
|
func (r *RequestHandlerSet) indexHandler(c echo.Context) error {
|
||||||
var fpi []HNFrontPage
|
var fpi []HNFrontPage
|
||||||
r.db.Where("disappeared is not ?", SQLITE_NULL_DATETIME).Order("disappeared desc").Find(&fpi)
|
r.db.Where("disappeared is not ?", time.Time{}).Order("disappeared desc").Find(&fpi)
|
||||||
|
|
||||||
type fprow struct {
|
type fprow struct {
|
||||||
Duration string
|
Duration string
|
||||||
@ -63,7 +65,7 @@ func (r *RequestHandlerSet) indexHandler(c echo.Context) error {
|
|||||||
var currentfp []rowtwo
|
var currentfp []rowtwo
|
||||||
|
|
||||||
var cur []HNFrontPage
|
var cur []HNFrontPage
|
||||||
r.db.Where("disappeared is ?", SQLITE_NULL_DATETIME).Order("rank asc").Find(&cur)
|
r.db.Where("disappeared is ?", time.Time{}).Order("rank asc").Find(&cur)
|
||||||
|
|
||||||
for _, item := range cur {
|
for _, item := range cur {
|
||||||
currentfp = append(currentfp, rowtwo{
|
currentfp = append(currentfp, rowtwo{
|
||||||
@ -82,13 +84,15 @@ func (r *RequestHandlerSet) indexHandler(c echo.Context) error {
|
|||||||
"time": time.Now().UTC().Format(time.RFC3339Nano),
|
"time": time.Now().UTC().Format(time.RFC3339Nano),
|
||||||
"exits": fprows,
|
"exits": fprows,
|
||||||
"current": currentfp,
|
"current": currentfp,
|
||||||
|
"gitrev": r.version,
|
||||||
}
|
}
|
||||||
return c.Render(http.StatusOK, "index.html", tc)
|
return c.Render(http.StatusOK, "index.html", tc)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RequestHandlerSet) aboutHandler(c echo.Context) error {
|
func (r *RequestHandlerSet) aboutHandler(c echo.Context) error {
|
||||||
tc := pongo2.Context{
|
tc := pongo2.Context{
|
||||||
"time": time.Now().UTC().Format(time.RFC3339Nano),
|
"time": time.Now().UTC().Format(time.RFC3339Nano),
|
||||||
|
"gitrev": r.version,
|
||||||
}
|
}
|
||||||
return c.Render(http.StatusOK, "about.html", tc)
|
return c.Render(http.StatusOK, "about.html", tc)
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ func (a *App) runForever() int {
|
|||||||
}
|
}
|
||||||
a.e.Renderer = r
|
a.e.Renderer = r
|
||||||
|
|
||||||
rhs := NewRequestHandlerSet(a.db)
|
rhs := NewRequestHandlerSet(a.version, a.db)
|
||||||
|
|
||||||
// Routes
|
// Routes
|
||||||
a.e.GET("/", rhs.indexHandler)
|
a.e.GET("/", rhs.indexHandler)
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<div class="col-lg-12">
|
<div class="col-lg-12">
|
||||||
<h1>About This Site</h1>
|
<h1>About This Site</h1>
|
||||||
|
|
||||||
<h2>IMPORTANT</h2>
|
<h2>⚠️ Important!</h2>
|
||||||
|
|
||||||
<p>This is a third-party site, not affiliated in any way with HN,
|
<p>This is a third-party site, not affiliated in any way with HN,
|
||||||
provided for informational purposes only. <b>Do not</b> contact or
|
provided for informational purposes only. <b>Do not</b> contact or
|
||||||
@ -24,12 +24,9 @@
|
|||||||
|
|
||||||
<h2>How?</h2>
|
<h2>How?</h2>
|
||||||
|
|
||||||
<p><a href="https://git.eeqj.de/sneak/hntransparencylog">Go</a> and the
|
<p>Go and the
|
||||||
graciously provided <a href="https://github.com/HackerNews/API">HN
|
graciously provided <a href="https://github.com/HackerNews/API">HN
|
||||||
API</a>.</p>
|
API</a>.</p>
|
||||||
|
|
||||||
<h2>Who?</h2>
|
|
||||||
|
|
||||||
<p><a href="mailto:sneak@sneak.berlin">@sneak</a>.</p>
|
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -13,14 +13,7 @@
|
|||||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
body {
|
{% include "style.css" %}
|
||||||
background: #f6f6ef;
|
|
||||||
}
|
|
||||||
|
|
||||||
#pagebody {
|
|
||||||
margin-top: 4em;
|
|
||||||
}
|
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
10
view/bodyfooter.html
Normal file
10
view/bodyfooter.html
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<footer>
|
||||||
|
<small>
|
||||||
|
A project by <a href="https://sneak.berlin">@sneak</a>.
|
||||||
|
|
||||||
|
<code>{{gitrev}}</code>
|
||||||
|
|
||||||
|
<a href="http://git.eeqj.de/sneak/orangesite">source</a> (<a
|
||||||
|
href="https://en.wikipedia.org/wiki/WTFPL">WTFPL</a>)
|
||||||
|
</small>
|
||||||
|
</footer>
|
@ -61,8 +61,5 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<small>{{ time }}</small>
|
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -12,4 +12,5 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% include "bodyfooter.html" %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
18
view/style.css
Normal file
18
view/style.css
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
body {
|
||||||
|
background: #f6f6ef;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pagebody {
|
||||||
|
margin-top: 4em;
|
||||||
|
}
|
||||||
|
|
||||||
|
footer {
|
||||||
|
padding-left: 1em;
|
||||||
|
padding-top: 2em;
|
||||||
|
padding-bottom: 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1,h2,h3,h4 {
|
||||||
|
padding-top: 1em;
|
||||||
|
padding-bottom: 0.25em;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user