Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
Hackspace Device Info
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
infrastructure
Hackspace Device Info
Commits
01a931d0
Commit
01a931d0
authored
May 15, 2014
by
Markus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added deamonize, interval...
parent
dc5dd511
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
16 deletions
+54
-16
hack_count
hack_count
+54
-16
No files found.
hack_count
View file @
01a931d0
...
@@ -3,6 +3,13 @@ import urllib
...
@@ -3,6 +3,13 @@ import urllib
import
json
import
json
import
pynotify
import
pynotify
import
argparse
import
argparse
import
os
import
time
CACHE_FOLDER
=
"~/.cache/hack_count/"
CACHE_FILE
=
"hack_count.json"
CACHE_PATH
=
os
.
path
.
join
(
str
(
CACHE_FOLDER
),
str
(
CACHE_FILE
))
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
@@ -10,23 +17,54 @@ if __name__ == '__main__':
...
@@ -10,23 +17,54 @@ if __name__ == '__main__':
parser
.
add_argument
(
"-n"
,
"--notify"
,
action
=
"store_true"
,
help
=
"Create a notification using
\
parser
.
add_argument
(
"-n"
,
"--notify"
,
action
=
"store_true"
,
help
=
"Create a notification using
\
libnotify"
,
default
=
False
)
libnotify"
,
default
=
False
)
parser
.
add_argument
(
"-p"
,
"--printing"
,
action
=
"store_true"
,
help
=
"Create a notification using
\
parser
.
add_argument
(
"-p"
,
"--printing"
,
action
=
"store_true"
,
help
=
"Enable or disable
\
libnotify"
,
default
=
True
)
printing"
,
default
=
True
)
parser
.
add_argument
(
"-d"
,
"--daemonize"
,
action
=
"store_true"
,
help
=
"Daemonize the
\
script"
,
default
=
False
)
parser
.
add_argument
(
"-i"
,
"--interval"
,
type
=
int
,
help
=
"Interval for
\
update"
,
default
=
30
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
##fetch usercount
while_val
=
False
var
=
urllib
.
urlopen
(
"http://hack-hro.de/api/users"
)
if
args
.
daemonize
==
True
:
device_count
=
json
.
loads
(
var
.
read
().
decode
())[
'deviceCount'
]
while_val
=
True
if
args
.
notify
:
while
while_val
==
True
:
if
not
pynotify
.
init
(
"HackHro"
):
##fetch usercount
sys
.
exit
(
1
)
var
=
urllib
.
urlopen
(
"http://hack-hro.de/api/users"
)
#create notification
device_count
=
json
.
loads
(
var
.
read
().
decode
())[
'deviceCount'
]
n
=
pynotify
.
Notification
(
"DeviceCount"
,
str
(
device_count
)
+
" Devices"
)
if
not
n
.
show
():
####fetch cached vals
print
(
"Failed to send notification"
)
if
os
.
path
.
exists
(
CACHE_PATH
):
sys
.
exit
(
1
)
cached_data_dict
=
json
.
loads
(
open
(
CACHE_PATH
).
read
())
if
args
.
printing
:
#print cached_data_dict['device_count']
print
"HackHro Users: "
,
device_count
### if diffrent save and create notification
if
not
cached_data_dict
[
'device_count'
]
==
device_count
:
#####prepare save value
cachedict
=
{
"device_count"
:
device_count
,
}
#####create cache folder if not exsits####
if
not
os
.
path
.
exists
(
CACHE_FOLDER
):
os
.
makedirs
(
CACHE_FOLDER
)
### save to cachefile ####
with
open
(
os
.
path
.
join
(
str
(
CACHE_FOLDER
),
str
(
CACHE_FILE
)),
"w"
)
as
iofile
:
json
.
dump
(
cachedict
,
iofile
)
iofile
.
close
()
if
args
.
notify
:
if
not
pynotify
.
init
(
"HackHro"
):
sys
.
exit
(
1
)
#create notification
n
=
pynotify
.
Notification
(
"DeviceCount"
,
str
(
device_count
)
+
" Devices"
)
if
not
n
.
show
():
print
(
"Failed to send notification"
)
sys
.
exit
(
1
)
##print count
if
args
.
printing
==
True
:
print
"HackHro Users: "
,
device_count
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