-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcrawler.py
More file actions
executable file
·42 lines (28 loc) · 892 Bytes
/
crawler.py
File metadata and controls
executable file
·42 lines (28 loc) · 892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
import os
import django
import requests
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mensa.settings")
django.setup()
from homometer.models import Stat
def get_stats():
return requests.get("http://graphite-kom.srv.lrz.de/render/?from=-1hours&target=ap.ap*-?mg*.ssid.*&format=json").json()
def update_stats(stats):
for k, v in stats.items():
Stat.objects.update_or_create(
ap=k,
defaults={'current': v},
)
def main():
page = get_stats()
aps = list(map(lambda x: (x['target'].split('.')[1], x['datapoints'][-1][0]
or x['datapoints'][-2][0] or 0), page))
stats = dict()
for ap, current in aps:
if ap in stats:
stats[ap] += current
else:
stats[ap] = current
update_stats(stats)
if __name__ == "__main__":
main()