Add link to chart

* Added SQL file to export CSV
* Updated plot.py to close figures due to RuntimeWarning shown
* hnbot now includes link to chart in comment
* charts are generated and copied to files.ekzyis.com using a cronjob
This commit is contained in:
ekzyis 2024-03-17 21:16:21 +00:00
parent c993978384
commit 00d3d759ac
4 changed files with 22 additions and 1 deletions

10
cron.sh Normal file
View File

@ -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/

7
hacker_news.csv.sql Normal file
View File

@ -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;

View File

@ -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')

3
sn.go
View File

@ -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)),