From 00d3d759acb064214c94d1d91eab0a3a9498d018 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Sun, 17 Mar 2024 21:16:21 +0000 Subject: [PATCH] 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 --- cron.sh | 10 ++++++++++ hacker_news.csv.sql | 7 +++++++ plot.py | 3 +++ sn.go | 3 ++- 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 cron.sh create mode 100644 hacker_news.csv.sql 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)),