Commit d0176846 authored by Markus's avatar Markus

migrated to dbus notifications via dbus

parent da052bd7
#!/usr/bin/env python2.7
import urllib
#!/usr/bin/env python
import dbus
import urllib.request
import json
import pynotify
import argparse
import os
import time
import sys
USER_HOME=os.path.expanduser("~")
CACHE_FOLDER=os.path.join(str(USER_HOME),".cache/hack_count")
CACHE_FILE="hack_count.json"
CACHE_PATH=os.path.join(str(CACHE_FOLDER),str(CACHE_FILE))
count_changed=True
item = ('org.freedesktop.Notifications')
path = ('/org/freedesktop/Notifications')
interface = ('org.freedesktop.Notifications')
icon = ''
array = ''
hint = ''
time = 10000 # Use seconds x 1000
app_name = ('Hack-Space User Count')
title = ('Hackspace User')
body = ('')
if __name__ == '__main__':
###parser
......@@ -27,15 +43,15 @@ if __name__ == '__main__':
parser.add_argument("-i","--interval",type=int,help="Interval for\
update default=30",default=30)
args = parser.parse_args()
while True :
##fetch usercount
var = urllib.urlopen("http://hack-hro.de/api/users")
var = urllib.request.urlopen("http://hack-hro.de/api/users")
#var = urllib.urlopen("http://172.16.42.107:3000/api/users")
json_string = var.read()
json_dict = json.loads(json_string)
#print(json_string)
json_dict = json.loads(json_string.decode('ascii'))
device_count = json_dict['deviceCount']
users = json_dict['users']
......@@ -71,19 +87,19 @@ if __name__ == '__main__':
iofile.close()
##notification
if args.notify:
if not pynotify.init("HackHro"):
sys.exit(1)
###init dbus notifications
bus = dbus.SessionBus()
notif = bus.get_object(item, path)
notify = dbus.Interface(notif, interface)
#create notification
n = pynotify.Notification("DeviceCount", str(device_count)+" Devices")
if count_changed :
if not n.show() :
print ("Failed to send notification")
sys.exit(1)
count_changed = False
notify.Notify(app_name, 0, icon, title, str(device_count), array, hint, time)
count_changed = False
##print count
if args.printing == True:
print "HackHro Users: ",device_count
print ("HackHro Users: ",device_count)
if not args.daemonize == True :
sys.exit(0)
time.sleep(args.interval)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment