83 lines
2.3 KiB
Python
83 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import json
|
|
import requests
|
|
|
|
class push:
|
|
|
|
def __init__(self, url, topic):
|
|
self.url = url
|
|
self.topic = topic
|
|
self.msg = ''
|
|
|
|
|
|
def send(self,obj):
|
|
|
|
msg = ''
|
|
priority = 1
|
|
tags = ["bell"]
|
|
|
|
if type(obj) == str:
|
|
msg = obj
|
|
if obj == 'none':
|
|
msg = 'no new articles'
|
|
|
|
return requests.post(self.url,
|
|
data=json.dumps({
|
|
"topic": self.topic,
|
|
"message": msg,
|
|
"tags": ["exclamation"],
|
|
"priority": 2
|
|
})
|
|
)
|
|
|
|
if obj['Titel'] == 'ERROR':
|
|
return requests.post(self.url,
|
|
data=json.dumps({
|
|
"topic": self.topic,
|
|
"message": obj['msg'],
|
|
"title": obj['Titel'],
|
|
"tags": ["warning"],
|
|
"priority": 5
|
|
})
|
|
)
|
|
|
|
|
|
if obj['prio'] == 'important':
|
|
tags = ["bangbang"]
|
|
priority = 3
|
|
if obj['prio'] == 'pinned':
|
|
tags = ["pushpin"]
|
|
priority = 5
|
|
|
|
if self.topic == "sozialinfo":
|
|
if obj['content'] != 'none':
|
|
msg += obj['Firma'] + ' - ' + obj['content']['Ort'] + '\n'
|
|
msg += obj['content']['Antritt'] + '\n\n'
|
|
if priority > 2:
|
|
msg += obj['content']['Beschreibung']
|
|
else:
|
|
msg += obj['Firma'] + ' - ' + obj['Anstellungsart']
|
|
|
|
if self.topic == "Wohnungen":
|
|
if obj['Zimmer'] != 'none':
|
|
msg += obj['Preis'] + ' - ' + obj['Zimmer'] + '\n'
|
|
msg += obj['Adresse'] + '\n\n'
|
|
if priority > 2:
|
|
msg += obj['Beschreibung']
|
|
else:
|
|
msg += obj['Zimmer'] + ' - ' + obj['Preis'] + ' - ' + obj['Adresse']
|
|
|
|
return requests.post(self.url,
|
|
data=json.dumps({
|
|
"topic": self.topic,
|
|
"message": msg,
|
|
"title": obj['Titel'],
|
|
"tags": tags,
|
|
"priority": priority,
|
|
"actions": [{ "action": "view", "label": "Open Source", "url": obj['lnk'], "clear": True }]
|
|
})
|
|
)
|
|
|
|
|