Compare commits

...

2 Commits

Author SHA1 Message Date
8c5208a0f0 Add Wowhead links and clean up code 2020-10-23 12:27:02 +02:00
42256b211d Change cronjob hours and remove Watcher pet 2020-10-23 12:26:12 +02:00
2 changed files with 52 additions and 24 deletions

View File

@ -12,7 +12,7 @@ You can also append it with `|<string>` to pass through any reminder to the noti
Cronjob to execute every 6 hours, 10 minutes past the hour:
```
10 */6 * * * cd /root/wqb && /usr/bin/python wqb.py
10 3,9,15,21 * * * cd /root/wqb && /usr/bin/python wqb.py
```
# Master Tamer/Pet lists
@ -54,7 +54,6 @@ Durian Strongfruit|Training with Durian
Ruinhoof|Ruinhoof
Deathscreech|Deathscreech
Corrupted Blood of Argus|Corrupted Blood of Argus
Watcher|Watcher
Minixis|Minixis
Foulclaw|Foulclaw
Retch|Retch

73
wqb.py
View File

@ -1,6 +1,7 @@
import json
import urllib2
import logging
import re
logging.basicConfig(filename='wqb.log', format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', encoding='utf-8', level=logging.DEBUG)
@ -17,6 +18,9 @@ token = config[1].split('=')[1].strip()
def send_message(input):
data = {
'chat_id': chat_id,
'parse_mode': "MarkdownV2",
'disable_web_page_preview': 'true',
'disable_notification': 'true',
'text': input
}
@ -27,30 +31,55 @@ def send_message(input):
logging.info('sent message ' + input)
def get_id(quest):
sources = {'SL': sl, 'BfA': bfa, 'Legion': legion}
for name, src in sources.items():
if (src.find(quest) != -1):
rgx = r"\"(\d+)\":{\"name_enus\":\"" + re.escape(quest) + r"\""
m = re.search(rgx, src)
if (m):
return m.group(1), name
else:
return 0, name
return -1, ''
def sanitize(str):
return str.replace('-', '\\-')
qlist = open('ql','r')
qlist = qlist.readlines()
output = ''
for quest in qlist:
quest = quest.rstrip()
qsplit = quest.split('|')
if len(qsplit) == 2:
if (sl.find(qsplit[1]) != -1):
send_message('[SL Tamer] ' + qsplit[0] + ' - ' + qsplit[1])
if (bfa.find(qsplit[1]) != -1):
send_message('[BFA Tamer] ' + qsplit[0] + ' - ' + qsplit[1])
if (legion.find(qsplit[1]) != -1):
send_message('[Legion Tamer] ' + qsplit[0] + ' - ' + qsplit[1])
qsplit = quest.rstrip().split('|')
id = -1
tag = ''
q = ''
prefix = ''
suffix = ''
if len(qsplit) == 1:
q = qsplit[0]
elif len(qsplit) == 2:
q = qsplit[1]
prefix = qsplit[0] + " - "
elif len(qsplit) == 3:
if (sl.find(qsplit[1]) != -1):
send_message('[SL Tamer] ' + qsplit[0] + ' - ' + qsplit[1] + ' - ' + qsplit[2])
if (bfa.find(qsplit[1]) != -1):
send_message('[BFA Tamer] ' + qsplit[0] + ' - ' + qsplit[1] + ' - ' + qsplit[2])
if (legion.find(qsplit[1]) != -1):
send_message('[Legion Tamer] ' + qsplit[0] + ' - ' + qsplit[1] + ' - ' + qsplit[2])
else:
if (sl.find(quest) != -1):
send_message('[SL] ' + quest)
if (bfa.find(quest) != -1):
send_message('[BFA] ' + quest)
if (legion.find(quest) != -1):
send_message('[Legion] ' + quest)
q = qsplit[1]
prefix = qsplit[0] + " - "
suffix = " - " + qsplit[2]
r = get_id(q)
id = r[0]
tag = r[1]
if (id == -1):
continue
elif (id > 0):
q = "[%s](https://wowhead.com/quest=%s)" % (q, id)
output = "%s\n\\[%s\\] %s%s%s" % (output, tag, prefix, q, suffix)
if output != '':
output = sanitize(output)
send_message(output.strip())