final
This commit is contained in:
parent
c487077c09
commit
8db780914b
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
last_check
|
2
Pipfile
2
Pipfile
@ -12,4 +12,4 @@ feedparser = "*"
|
||||
[dev-packages]
|
||||
|
||||
[requires]
|
||||
python_version = "3.11"
|
||||
python_version = "3.13"
|
||||
|
1012
Pipfile.lock
generated
1012
Pipfile.lock
generated
File diff suppressed because it is too large
Load Diff
16
README.md
16
README.md
@ -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
|
||||
- firefish
|
||||
- hometown
|
||||
- akkoma
|
||||
- gotosocial
|
||||
- [neovim](https://github.com/neovim/neovim)
|
||||
- [mastodon](https://github.com/mastodon/mastodon)
|
||||
- [hometown](https://github.com/hometown-fork/hometown)
|
||||
- [glitch-soc](https://github.com/glitch-soc/mastodon)
|
||||
- [gotosocial](https://github.com/superseriousbusiness/gotosocial)
|
||||
|
||||
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.
|
||||
|
@ -1 +1 @@
|
||||
2023-09-27 19:37:16.347097
|
||||
2024-11-22 18:22:21.608793+00:00
|
90
main.py
90
main.py
@ -1,44 +1,74 @@
|
||||
import dotenv
|
||||
import requests
|
||||
from dotenv import load_dotenv
|
||||
from requests import get,post,put
|
||||
from discord import SyncWebhook
|
||||
from datetime import datetime as dt
|
||||
import feedparser
|
||||
from datetime import datetime as dt, timezone as tz
|
||||
from time import mktime
|
||||
from feedparser import parse
|
||||
from os import getenv
|
||||
from json import loads
|
||||
from time import mktime
|
||||
|
||||
# initialise variables
|
||||
new_ts = dt.now()
|
||||
new_ts = dt.now(tz.utc)
|
||||
old_ts = ''
|
||||
|
||||
# read in old timestamp if it exists
|
||||
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:
|
||||
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
|
||||
dotenv.load_dotenv()
|
||||
conf = dotenv.dotenv_values()
|
||||
discord_user = conf['DISCORD_USERNAME']
|
||||
dicord_webhook_url = conf['DISCORD_WEBHOOK_TEST']
|
||||
webhook = SyncWebhook.from_url(conf['DISCORD_WEBHOOK_TEST'])
|
||||
load_dotenv()
|
||||
discord_user = getenv('DISCORD_USERNAME')
|
||||
dicord_webhook_url = getenv('DISCORD_WEBHOOK_TEST')
|
||||
webhook = SyncWebhook.from_url(getenv('DISCORD_WEBHOOK_TEST'))
|
||||
github_token = getenv('GITHUB_TOKEN')
|
||||
|
||||
# list with urls to check
|
||||
the_urls = [
|
||||
'https://github.com/mastodon/mastodon/releases.atom',
|
||||
'https://github.com/hometown-fork/hometown/releases.atom',
|
||||
'https://git.joinfirefish.org/firefish/firefish/tags?format=atom',
|
||||
'https://akkoma.dev/AkkomaGang/akkoma/releases.atom',
|
||||
'https://github.com/superseriousbusiness/gotosocial/releases.atom'
|
||||
]
|
||||
# list of repos to check
|
||||
repos = [
|
||||
'neovim/neovim',
|
||||
'mastodon/mastodon',
|
||||
'hometown-fork/hometown',
|
||||
'glitch-soc/mastodon',
|
||||
'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
|
||||
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.
|
||||
with open('last_check','w') as last_check:
|
||||
print(new_ts, file=last_check)
|
||||
def get_latest_releases():
|
||||
for repo in repos:
|
||||
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='')
|
||||
|
Loading…
Reference in New Issue
Block a user