This commit is contained in:
Camille Frantz 2024-11-22 12:28:35 -06:00
parent c487077c09
commit 8db780914b
Signed by: fyrfli
SSH Key Fingerprint: SHA256:cyNGncrLxKXAgYC96dYNROnQKikLInzrpiMraZdqyhY
6 changed files with 667 additions and 456 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
last_check

View File

@ -12,4 +12,4 @@ feedparser = "*"
[dev-packages] [dev-packages]
[requires] [requires]
python_version = "3.11" python_version = "3.13"

1012
Pipfile.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,13 @@
# fedi platform release bot # release checker bot
this program will run at a pre-defined interval to check for releases on the following platform repositories: this program will run at a pre-defined interval to check for releases on the following repositories:
- mastodon - [neovim](https://github.com/neovim/neovim)
- firefish - [mastodon](https://github.com/mastodon/mastodon)
- hometown - [hometown](https://github.com/hometown-fork/hometown)
- akkoma - [glitch-soc](https://github.com/glitch-soc/mastodon)
- gotosocial - [gotosocial](https://github.com/superseriousbusiness/gotosocial)
other repositories can and will be added later. other repositories can and will be added later.
once a new release is discovered, the link and title will be posted to discord in a channel that can be subscribed to from other places. once a new release is discovered, the name of the release, link, and title will be posted to discord in a channel that can be subscribed to from other places.

View File

@ -1 +1 @@
2023-09-27 19:37:16.347097 2024-11-22 18:22:21.608793+00:00

90
main.py
View File

@ -1,44 +1,74 @@
import dotenv from dotenv import load_dotenv
import requests from requests import get,post,put
from discord import SyncWebhook from discord import SyncWebhook
from datetime import datetime as dt from datetime import datetime as dt, timezone as tz
import feedparser from time import mktime
from feedparser import parse
from os import getenv
from json import loads
from time import mktime
# initialise variables # initialise variables
new_ts = dt.now() new_ts = dt.now(tz.utc)
old_ts = '' old_ts = ''
# read in old timestamp if it exists # read in old timestamp if it exists
try: try:
old_ts = dt.strptime(open('last_check','r').read().rstrip(),'%Y-%m-%d %H:%M:%S.%f') old_ts = dt.strptime(open('last_check','r').read().split(".")[0],'%Y-%m-%d %H:%M:%S')
except: except:
old_ts = dt.strptime('20230101000000','%Y%m%d%H%M%S') old_ts = dt.strptime('20230101000000','%Y-%m-%d %H:%M:%S')
# load in the relevant .env variables # load in the relevant .env variables
dotenv.load_dotenv() load_dotenv()
conf = dotenv.dotenv_values() discord_user = getenv('DISCORD_USERNAME')
discord_user = conf['DISCORD_USERNAME'] dicord_webhook_url = getenv('DISCORD_WEBHOOK_TEST')
dicord_webhook_url = conf['DISCORD_WEBHOOK_TEST'] webhook = SyncWebhook.from_url(getenv('DISCORD_WEBHOOK_TEST'))
webhook = SyncWebhook.from_url(conf['DISCORD_WEBHOOK_TEST']) github_token = getenv('GITHUB_TOKEN')
# list with urls to check # list of repos to check
the_urls = [ repos = [
'https://github.com/mastodon/mastodon/releases.atom', 'neovim/neovim',
'https://github.com/hometown-fork/hometown/releases.atom', 'mastodon/mastodon',
'https://git.joinfirefish.org/firefish/firefish/tags?format=atom', 'hometown-fork/hometown',
'https://akkoma.dev/AkkomaGang/akkoma/releases.atom', 'glitch-soc/mastodon',
'https://github.com/superseriousbusiness/gotosocial/releases.atom' 'superseriousbusiness/gotosocial'
] ]
github_api = 'https://api.github.com/repos'
headers = {
'Accept': 'application/vnd.github+json',
'Authorization': f'Bearer {github_token}',
'X-GitHub-Api-Version': '2022-11-28'
}
# loop through urls for latest release # loop through urls for latest release
for url in the_urls:
release = feedparser.parse(url)
release_date = dt.strptime(release['entries'][0]['updated'], '%Y-%m-%dT%H:%M:%SZ')
release_version = release['entries'][0]['title']
release_link = release['entries'][0]['link']
if release_date > old_ts:
webhook.send('new release: ' + release_version + '\n' + release_link)
# write out current check timestamp to file for next check. def get_latest_releases():
with open('last_check','w') as last_check: for repo in repos:
print(new_ts, file=last_check) release_url = f'{github_api}/{repo}/releases/latest'
# print(release_url)
latest_release = get(release_url, headers=headers)
if latest_release.status_code == 200:
release_details = loads(latest_release.text)
if mktime(dt.strptime(release_details['published_at'], '%Y-%m-%dT%H:%M:%SZ').timetuple()) > mktime(old_ts.timetuple()):
print(
release_details['tag_name'],
release_details['name'],
release_details['published_at'],
release_details['html_url']
)
webhook.send(f"{release_details['name']}: {release_details['tag_name']}\n{release_details['html_url']}")
else:
print(latest_release.status_code, latest_release.reason)
else:
return False
## return true if the function didn't terminate abnormally before
return True
if __name__ == "__main__":
results_sent = get_latest_releases()
if results_sent:
with open('last_check','w') as f:
print(new_ts, file=f, end='')