Compare commits
No commits in common. "bd2af92ec9dc6825735f18e365bdbdf2a42b15f5" and "38e78bcdf45454993d2093abe4bce59634c2bd7d" have entirely different histories.
bd2af92ec9
...
38e78bcdf4
1 changed files with 14 additions and 20 deletions
34
discorss.py
34
discorss.py
|
|
@ -23,11 +23,9 @@ log_file_name = r"/app.log"
|
||||||
|
|
||||||
def getDescription(feed):
|
def getDescription(feed):
|
||||||
try:
|
try:
|
||||||
tempStr = str(feed.entries[0]["summary_detail"]["value"])
|
desc = str(feed.entries[0]["summary_detail"]["value"])
|
||||||
desc = tempStr[:100] if len(tempStr) > 100 else tempStr
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
tempStr = str(feed.entries[0]["description"])
|
desc = str(feed.entries[0]["description"])
|
||||||
desc = tempStr[:100] if len(tempStr) > 100 else tempStr
|
|
||||||
return desc
|
return desc
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -54,33 +52,29 @@ def main():
|
||||||
print(feed.entries[0]["published"], published_time, now)
|
print(feed.entries[0]["published"], published_time, now)
|
||||||
# Generate the webhook
|
# Generate the webhook
|
||||||
webhook = {
|
webhook = {
|
||||||
"content": "RSS Feed Update from " + str(hook["name"]),
|
|
||||||
"embeds": [
|
"embeds": [
|
||||||
{
|
{
|
||||||
"title": str(feed.entries[0]["title"]),
|
"title": str(feed.entries[0]["title"]),
|
||||||
"url": str(feed.entries[0]["link"]),
|
"url": str(feed.entries[0]["link"]),
|
||||||
"color": 5814783,
|
"description": getDescription(feed),
|
||||||
"fields": [
|
"provider": "DiscoRSS",
|
||||||
{
|
|
||||||
"name": str(feed.entries[0]["title"]),
|
|
||||||
"value": getDescription(feed),
|
|
||||||
}
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
"attachments": [],
|
|
||||||
}
|
}
|
||||||
customHeader = {
|
customHeader = {
|
||||||
"user-agent": "DiscoRSS (https://git.frzn.dev/amr/discorss, 0.1)",
|
"user-agent": "DiscoRSS (https://git.frzn.dev/amr/discorss, 0.1)",
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
}
|
}
|
||||||
webhookStr = json.dumps(webhook)
|
|
||||||
print(webhookStr)
|
|
||||||
if published_time > last_check and published_time < now:
|
if published_time > last_check and published_time < now:
|
||||||
r = requests.post(hook["webhook"], data=webhookStr, headers=customHeader)
|
print(json.dumps(webhook))
|
||||||
app_config["lastupdate"] = now
|
r = requests.post(
|
||||||
with open(config_file_path, "w") as config_file:
|
hook["webhook"], data=json.dumps(webhook), headers=customHeader
|
||||||
json.dump(app_config, config_file, indent=4)
|
)
|
||||||
|
print(webhook["embeds"][0]["title"])
|
||||||
|
print(r.text, r.status_code, r.json())
|
||||||
|
app_config["lastupdate"] = now
|
||||||
|
with open(config_file_path, "w") as config_file:
|
||||||
|
json.dump(app_config, config_file, indent=4)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue