summaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
authorMark Powers <mark@marks.kitchen>2020-09-05 02:03:17 +0000
committerMark Powers <mark@marks.kitchen>2020-09-05 02:03:17 +0000
commit16e0997184c71d54ed2e1702e887bd1d17604dcf (patch)
tree6fc8f2d5618179e1aa7e844271096d78b55743ba /main.py
parent9f0acb950d9c85b5701760ecf7aafbfe3374341c (diff)
parente1084ea7e1aa2d4f72a5f2c5fd67a05910610e29 (diff)
Merge conflictsHEADmaster
Diffstat (limited to 'main.py')
-rw-r--r--main.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/main.py b/main.py
index 28d4086..df34f4f 100644
--- a/main.py
+++ b/main.py
@@ -7,17 +7,22 @@ import requests
import datetime
import json
+# Constant URL to Hacker News
base_url = "https://news.ycombinator.com/"
+# Calculate the date 10 years ago as %Y-%m%d
year = int(date.today().strftime("%Y")) - 10
today = str(year) + date.today().strftime("-%m-%d")
+# Request the page
r = requests.get('https://news.ycombinator.com/front?day='+today)
+# Parse the html
soup = BeautifulSoup(r.text, features="lxml")
+# Get the post specified by the first argument
items = soup.find_all("tr", "athing")[:3]
-
index = int(sys.argv[1])
item = items[index]
-
story = item.find("a", "storylink")
+
+# Parse the title and link from the post
title = story.text
link = story["href"]
if "http" not in link:
@@ -38,18 +43,19 @@ except:
+# Find the comments link from the row
comment_el = item.next_sibling
comment_link = base_url + comment_el.find_all("a")[-1]["href"]
if comment_link == link:
comment_link = ""
+# Format the final string
toot_content = title + "\n" + link + "\n"+comment_link
+# Connect to Mastodon and send a toot
mastodon = Mastodon(
access_token = '/home/mark/hndecade/hndecade_usercred.secret',
api_base_url = 'https://botsin.space'
)
-print(toot_content)
-#mastodon.toot(toot_content)
-
+mastodon.toot(toot_content)