Python script to convert tweets to Hugo data, so you can use it in templates. No JS, no hassle. ♥
https://tuxstash.de/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
961 B
36 lines
961 B
import requests
|
|
from pathlib import Path
|
|
from platform import system
|
|
from json import load as j_load
|
|
from mail import mail
|
|
|
|
get_last_id_url = "https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=GothSeidank&count=1&trim_user=1"
|
|
# get_tweet_url = "https://api.twitter.com/2/tweets/1324994969590001666"
|
|
|
|
|
|
if system().lower() == "windows":
|
|
path = Path("bearer.json")
|
|
else:
|
|
path = Path("/etc/twpng/bearer.json")
|
|
|
|
try:
|
|
with path.open('r') as fp:
|
|
credentials = j_load(fp)
|
|
except FileNotFoundError:
|
|
mail("Could not find bearer token file! Script was discontinued.")
|
|
exit(1)
|
|
|
|
try:
|
|
header = {
|
|
"Authorization": f"Bearer {credentials['bearer']}"
|
|
}
|
|
|
|
r = requests.get(url=get_last_id_url, headers=header)
|
|
r.raise_for_status()
|
|
|
|
except Exception as e:
|
|
message = f"The api call to twitter failed and requests said:\n'{e}'. Script was discontinued."
|
|
mail(message)
|
|
exit(1)
|
|
|
|
|
|
|