57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
import time
|
|
import feedparser
|
|
import requests
|
|
|
|
# Koji RSS feed URL
|
|
KOJI_RSS_URL = "http://koji.koozali.org/koji/recentbuilds?feed=rss"
|
|
# Rocket.Chat webhook URL
|
|
ROCKET_CHAT_URL = "https://chat.koozali.org/hooks/66d24441effca216c2ca309f/KJLaNwc5vyHwqz5MhRDpBkKWnQuAfsCX3xZMHxPhpuqmFgBn"
|
|
|
|
# Function to send message to Rocket.Chat
|
|
def send_to_rocket_chat(message_title, message_link, message_description):
|
|
payload = {
|
|
"alias": "Koji",
|
|
"text": message_title,
|
|
"attachments": [
|
|
{
|
|
"title": message_title,
|
|
"title_link": message_link,
|
|
"text": message_description,
|
|
# "image_url": "https://chat.koozali.org/images/integration-attachment-example.png",
|
|
"color": "#764FA5"
|
|
}
|
|
]
|
|
}
|
|
response = requests.post(ROCKET_CHAT_URL, json=payload)
|
|
if response.status_code == 200:
|
|
print(f"Message ({title}) sent successfully!")
|
|
else:
|
|
print(f"Failed to send message: {response.status_code} - {response.text}")
|
|
|
|
# Function to fetch and parse the Koji RSS feed
|
|
def fetch_koji_feed():
|
|
feed = feedparser.parse(KOJI_RSS_URL)
|
|
if feed.entries:
|
|
latest_build = feed.entries[0]
|
|
title = latest_build.title.strip()
|
|
link = latest_build.link
|
|
description = latest_build.description.strip().replace("<pre>", "").replace("</pre>", "")
|
|
return title, link, description
|
|
return None, None, None
|
|
|
|
# Main polling loop
|
|
def main():
|
|
last_title = None
|
|
|
|
while True:
|
|
title, link, description = fetch_koji_feed()
|
|
|
|
if title and title != last_title:
|
|
send_to_rocket_chat(title, link, description)
|
|
last_title = title
|
|
|
|
# Wait for 1 minute before polling again
|
|
time.sleep(60)
|
|
|
|
if __name__ == "__main__":
|
|
main() |