diff --git a/cron.sh b/cron.sh new file mode 100644 index 0000000..6055043 --- /dev/null +++ b/cron.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -xe + +cd /home/ekzyis/hnbot +sqlite3 hnbot.sqlite3 < hacker_news.csv.sql +venv/bin/python plot.py +mv hn_*.png plots/ +rsync plots/* vps:/var/www/files/public/hn/ + diff --git a/hacker_news.csv.sql b/hacker_news.csv.sql new file mode 100644 index 0000000..1ff8bd8 --- /dev/null +++ b/hacker_news.csv.sql @@ -0,0 +1,7 @@ +.headers on +.mode csv +.output hacker_news.csv +SELECT id, created_at, time, title, url, author, ndescendants, score, rank +FROM hn_items +WHERE id IN (SELECT hn_id FROM sn_items) +ORDER BY id, created_at DESC; diff --git a/plot.py b/plot.py index 0d4e8bc..4a5f3ca 100644 --- a/plot.py +++ b/plot.py @@ -58,3 +58,6 @@ for [hn_id], group in grouped: plt.tight_layout() plt.savefig(f'hn_{hn_id}.png') + plt.close() + + print(f'Saved hn_{hn_id}.png') diff --git a/sn.go b/sn.go index b47ef91..d1ee6e7 100644 --- a/sn.go +++ b/sn.go @@ -84,7 +84,8 @@ func PostStoryToStackerNews(story *Story, options PostStoryOptions) (int, error) SendStackerNewsEmbedToDiscord(story.Title, parentId) comment := fmt.Sprintf( - "This link was posted by [%s](%s) %s on [HN](%s). It received %d points and %d comments.", + "This link was posted by [%s](%s) %s on [HN](%s). It received %d points and %d comments.\n\n"+ + fmt.Sprintf("https://files.ekzyis.com/public/hn/hn_%d.png", story.ID), story.By, HackerNewsUserLink(story.By), humanize.Time(time.Unix(int64(story.Time), 0)),