Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
infrastructure
Hackspace Device Info
Commits
d0176846
Commit
d0176846
authored
May 22, 2014
by
Markus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
migrated to dbus notifications via dbus
parent
da052bd7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
15 deletions
+31
-15
hack_count
hack_count
+31
-15
No files found.
hack_count
View file @
d0176846
#!/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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment