summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--config.py.example15
-rwxr-xr-xrsnotify.py93
3 files changed, 110 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..4ad16eb
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+/config.py
+/icon.png
diff --git a/config.py.example b/config.py.example
new file mode 100644
index 0000000..c031e50
--- /dev/null
+++ b/config.py.example
@@ -0,0 +1,15 @@
+import os, logging
+
+USERNAME=''
+PASSWORD=''
+
+# log level
+LOGLEVEL=logging.INFO
+
+# seconds to sleep between queries
+SLEEP=300
+
+# icon for notifications
+ICON=os.path.dirname(__file__ + '/icon.png')
+
+# vim:ft=python:
diff --git a/rsnotify.py b/rsnotify.py
new file mode 100755
index 0000000..5cdc377
--- /dev/null
+++ b/rsnotify.py
@@ -0,0 +1,93 @@
+#!/usr/bin/env python
+
+import config, logging, requests, sys, time
+from lxml import etree
+from gi.repository import Notify
+
+logger = logging.getLogger(__name__)
+logger.setLevel(config.LOGLEVEL)
+
+# create console handler and set level to debug
+ch = logging.StreamHandler()
+ch.setLevel(config.LOGLEVEL)
+
+# create formatter
+formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
+
+# add formatter to ch
+ch.setFormatter(formatter)
+
+# add ch to logger
+logger.addHandler(ch)
+
+s = requests.Session()
+
+logger.info('Logging in as %s' % config.USERNAME)
+r = s.post('https://secure.runescape.com/m=weblogin/login.ws', data={
+ 'username': config.USERNAME,
+ 'password': config.PASSWORD,
+ 'mod': 'www',
+ 'dest': ''
+})
+
+if 'recaptcha' in r.text:
+ raise Error("Login encountered reCAPTCHA. Log in with a browser and try again.")
+
+logger.info("'Authorising' toolbar")
+s.post('http://services.runescape.com/m=toolbar/authorise.ws', data='remember=remember&submit=login')
+
+s.cookies['toolbar_activity_filter'] = 'AQAOACkAAAAqAAAAGAAAAAoAAAAXAAAAAAAAABYAAAABAAAAKAAAAAsAAAACAAAAAwAAAAwAAAAUAAA='
+
+checks = [
+ {
+ 'name': 'D&D',
+ 'url': 'http://services.runescape.com/m=toolbar/activities.ws',
+ 'last': [],
+ },
+ {
+ 'name': 'GE',
+ 'url': 'http://services.runescape.com/m=toolbar/geupdate.ws',
+ 'last': [],
+ },
+]
+
+def load(toload):
+
+ logger.debug("Loading %s (%s)" % (toload['name'], toload['url']))
+
+ r = s.get(toload['url'])
+
+ xml = etree.fromstring(r.content)
+ items = xml.xpath('//MENU_ITEM')
+
+ toload['last'] = [next(item.iter('CAPTION')).text for item in items]
+
+def check(tocheck):
+
+ logger.info("Checking %s (%s)" % (tocheck['name'], tocheck['url']))
+
+ thislast = tocheck['last']
+
+ load(tocheck)
+
+ for caption in tocheck['last']:
+ logger.debug('Checking for "%s" in last' % caption)
+ if caption not in thislast:
+ notify('RuneScape %s notification' % tocheck['name'], caption)
+ else:
+ logger.debug('"%s" found in last, skipping notification' % caption)
+
+Notify.init('RuneScape Notifier')
+
+def notify(summary, body):
+ logger.info("Sending %s: %s" % (summary, body))
+ n = Notify.Notification.new(summary, body, config.ICON)
+ n.show()
+
+logger.info("Preloading checks")
+list(map(load, checks))
+
+while True:
+ logger.info("Sleeping for %d seconds" % config.SLEEP)
+ time.sleep(config.SLEEP)
+ list(map(check, checks))