summaryrefslogtreecommitdiff
path: root/datasources/de_wettermichel.py
blob: fb17210081749a48550dc1c1bde9dc1723822c21 (plain)
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
43
44
#!/usr/bin/env python
# -*- coding:utf8 -*-
import httplib
from StringIO import StringIO
from lxml import objectify

def read():
    conn = httplib.HTTPConnection("www.wettermichel.de")
    conn.request("GET", "/weatherdata/params3.xml")
    response = conn.getresponse()
    assert response.status == 200, "Site status code == 200"

    xml = objectify.parse( response )
    conn.close()
    return xml

def insert(name, value, valueType):
    conn = httplib.HTTPConnection("127.0.0.1:8080")
    conn.request("PUT", "/api/value/{n}".format(n=name), value)
    response = conn.getresponse()
    assert response.status == 200, "put status code == 200"
    conn.close()




for keyval in read().xpath("/data/*"):
    if keyval.tag == "entry":
        continue

    if isinstance(keyval, objectify.IntElement):
        insert("de.wettermichel.{n}".format(n=keyval.tag),
                keyval.text, "int")
    elif isinstance(keyval, objectify.FloatElement):
        insert("de.wettermichel.{n}".format(n=keyval.tag),
                keyval.text, "float")
    elif isinstance(keyval, objectify.StringElement):
        # ignore strings
        pass
    else:
        print "ignore other: %s %s" % (keyval.tag, keyval.__class__)


# vim: autoindent tabstop=4 shiftwidth=4 expandtab softtabstop=4 filetype=python