Esempio n. 1
0
def parse_promet(obfuscated_data):
    decoded = _decode(obfuscated_data)
    json = _loads(decoded)

    _transform_3787 = get_coordtransform()

    def transform3787(x, y):
        si_point = GEOSGeometry('SRID=3787;POINT (%s %s)' % (x, y))
        si_point.transform(_transform_3787)
        return si_point.x, si_point.y

    def transform4326(x, y):
        return x, y

    transforms = {
        u'EPSG:2170': transform3787,
        u'EPSG:4326': transform4326,
    }
    for category_obj in json['Contents']:
        for item in category_obj['Data']['Items']:
            crsid = item.get('CrsId')
            x, y = item.get('X'), item.get('Y')
            item['x_wgs'], item['y_wgs'] = transforms[crsid](x, y)

    now = timegm(datetime.datetime.utcnow().utctimetuple())
    json['updated'] = now
    json['copyright'] = COPYRIGHT_PROMET
    return json
Esempio n. 2
0
def parse_sos112(timestamp, data):
    data = data.decode(ENCODING).strip()

    records = []
    lines = [i.strip() for i in data.split('\r\n')]
    keys = lines[0].lower().split('\t')

    geotransform = get_coordtransform()

    for line in lines[1:]:
        rec = dict(zip(keys, line.split('\t')))
        y, x = rec['point'].split(',')

        point = GEOSGeometry('SRID=3787;POINT (%s %s)' % (x, y))
        point.transform(geotransform)
        rec['x_wgs'] = point.x
        rec['y_wgs'] = point.y

        records.append(rec)

    json_data = {
        'updated': timestamp,
        'records': records,
        'copyright': u'Uprava RS za zaščito in reševanje',
    }

    return json_data
Esempio n. 3
0
def parse_promet(obfuscated_data):
    decoded = _decode(obfuscated_data)
    json = _loads(decoded)

    _transform_3787 = get_coordtransform()

    def transform3787(x, y):
        si_point = GEOSGeometry('SRID=3787;POINT (%s %s)' % (x, y))
        si_point.transform(_transform_3787)
        return si_point.x, si_point.y

    def transform4326(x, y):
        return x, y

    transforms = {
        u'EPSG:2170': transform3787,
        u'EPSG:4326': transform4326,
    }
    for category_obj in json['Contents']:
        for item in category_obj['Data']['Items']:
            crsid = item.get('CrsId')
            x, y = item.get('X'), item.get('Y')
            item['x_wgs'], item['y_wgs'] = transforms[crsid](x, y)

    now = timegm(datetime.datetime.utcnow().utctimetuple())
    json['updated'] = now
    json['copyright'] = COPYRIGHT_PROMET
    return json
Esempio n. 4
0
def parse_sos112(timestamp, data):
    data = data.decode(ENCODING).strip()

    records = []
    lines = [i.strip() for i in data.split('\r\n')]
    keys = lines[0].lower().split('\t')

    geotransform = get_coordtransform()

    for line in lines[1:]:
        rec = dict(zip(keys, line.split('\t')))
        y, x = rec['point'].split(',')

        point = GEOSGeometry('SRID=3787;POINT (%s %s)' % (x, y))
        point.transform(geotransform)
        rec['x_wgs'] = point.x
        rec['y_wgs'] = point.y

        records.append(rec)

    json_data = {
        'updated': timestamp,
        'records': records,
        'copyright': u'Uprava RS za zaščito in reševanje',
    }

    return json_data
Esempio n. 5
0
def _transform_dataset(original_data):
    data = _loads(original_data)
    geotransform = get_coordtransform()
    for pr in data:
        si_point = GEOSGeometry('SRID=3787;POINT (%s %s)' % (pr['x'], pr['y']))
        si_point.transform(geotransform)
        pr['x_wgs'] = si_point.x
        pr['y_wgs'] = si_point.y

    return data
Esempio n. 6
0
def _transform_dataset(original_data):
    data = _loads(original_data)
    geotransform = get_coordtransform()
    for pr in data:
        si_point = GEOSGeometry('SRID=3787;POINT (%s %s)' % (pr['x'], pr['y']))
        si_point.transform(geotransform)
        pr['x_wgs'] = si_point.x
        pr['y_wgs'] = si_point.y

    return data
Esempio n. 7
0
def parse_parkirisca_lpt(parkirisca_data, occupancy_data):

    # silly xmlns
    parkirisca_data = parkirisca_data.replace(' xmlns="http://www.tempuri.org/dsP.xsd"', '')

    parkirisca = ET.fromstring(parkirisca_data)
    occupancy = ET.fromstring(occupancy_data)

    zattrs = ['ID_ParkiriscaNC', 'Cas', 'P_kratkotrajniki']
    zattrs.sort()
    zasedenost = {}

    for e in occupancy.findall('./ZASEDENOST'):
        zdict = dict([(i.tag, i.text) for i in e.getchildren()])
        assert list(sorted(zdict.keys())) == zattrs, 'occupancy.xml attributes changed!'
        zdict['Cas_timestamp'] = int(time.mktime(datetime.datetime.strptime(zdict['Cas'], '%Y-%m-%d %H:%M:%S').timetuple()))
        for k, v in zdict.items():
            if isinstance(v, str) and re.match('^\d+$', v):
                zdict[k] = int(v)
        zasedenost[zdict['ID_ParkiriscaNC']] = zdict

    assert len(zasedenost) > 1, 'Ni elementov v occupancy.xml?!'

    json = {'Parkirisca': [],}

    attrs = ['A_St_Mest', 'Cena_dan_Eur', 'Cena_mesecna_Eur', 'Cena_splosno', 'Cena_ura_Eur', 'ID_Parkirisca', 'ID_ParkiriscaNC', 'Ime', 'Invalidi_St_mest', 'KoordinataX', 'KoordinataY', 'Opis', 'St_mest', 'Tip_parkirisca', 'U_delovnik', 'U_sobota', 'U_splosno', 'Upravljalec']
    attrs.sort()
    geotransform = get_coordtransform()

    for p in parkirisca.findall('.//Parkirisca'):
        pdict = dict([(i.tag, i.text) for i in p.getchildren()])

        for k, v in pdict.items():
            if isinstance(v, basestring) and re.match('^\d+$', v):
                pdict[k] = int(v)

        assert list(sorted(pdict.keys())) == attrs, "parkirisca.xml Attributes changed!?"
        if zasedenost.get(pdict['ID_ParkiriscaNC']) != None:
            pdict['zasedenost'] = zasedenost[pdict['ID_ParkiriscaNC']]

        # convert coords to WGS84
        if pdict['KoordinataX'] and pdict['KoordinataY']:
            si_point = GEOSGeometry('SRID=3787;POINT (%s %s)' % (pdict['KoordinataX'], pdict['KoordinataY']))
            si_point.transform(geotransform)
            pdict[u'KoordinataX_wgs'] = si_point.x
            pdict[u'KoordinataY_wgs'] = si_point.y

        json['Parkirisca'].append(pdict)

    json['updated'] = time.time()
    json['copyright'] = COPYRIGHT_LPT
    return json
Esempio n. 8
0
def parse_events(obfuscated_data):
    decoded = _decode(obfuscated_data)

    # postprocess
    data = re.sub('new Date\((\d+)\)', r'\1', decoded)

    json = _loads(data)

    geotransform = get_coordtransform()
    for d in json['dogodki']['dogodek']:

        # convert geometric system
        point = GEOSGeometry('SRID=3787;POINT (%s %s)' % (d['x'], d['y']))
        point.transform(geotransform)
        d['x_wgs'] = point.x
        d['y_wgs'] = point.y

    json['updated'] = time.time()
    json['copyright'] = COPYRIGHT_PROMET
    return json
Esempio n. 9
0
def parse_events(obfuscated_data):
    decoded = _decode(obfuscated_data)

    # postprocess
    data = re.sub('new Date\((\d+)\)', r'\1', decoded)

    json = _loads(data)

    geotransform = get_coordtransform()
    for d in json['dogodki']['dogodek']:

        # convert geometric system
        point = GEOSGeometry('SRID=3787;POINT (%s %s)' % (d['x'], d['y']))
        point.transform(geotransform)
        d['x_wgs'] = point.x
        d['y_wgs'] = point.y

    json['updated'] = time.time()
    json['copyright'] = COPYRIGHT_PROMET
    return json
Esempio n. 10
0
def parse_counters(obfuscated_data):
    decoded = _decode(obfuscated_data)

    # postprocess
    data = re.sub('new Date\(([\d,]+)\)', r'[\1]', decoded)
    data = data.rstrip(')').lstrip('(')

    json = _loads(data)
    json['feed']['updated'] = _datetime2timestamp(json['feed']['updated'])
    geotransform = get_coordtransform()
    for e in json['feed']['entry']:
        e['updated'] = _datetime2timestamp(e['updated'])

        # convert geo points to WGS84
        si_point = GEOSGeometry('SRID=3787;POINT (%s %s)' % (e['stevci_geoX'], e['stevci_geoY']))
        si_point.transform(geotransform)
        e[u'stevci_geoX_wgs'] = si_point.x
        e[u'stevci_geoY_wgs'] = si_point.y

    json['updated'] = time.time()
    json['copyright'] = COPYRIGHT_PROMET
    return json
Esempio n. 11
0
def parse_counters(obfuscated_data):
    decoded = _decode(obfuscated_data)

    # postprocess
    data = re.sub('new Date\(([\d,]+)\)', r'[\1]', decoded)
    data = data.rstrip(')').lstrip('(')

    json = _loads(data)
    json['feed']['updated'] = _datetime2timestamp(json['feed']['updated'])
    geotransform = get_coordtransform()
    for e in json['feed']['entry']:
        e['updated'] = _datetime2timestamp(e['updated'])

        # convert geo points to WGS84
        si_point = GEOSGeometry('SRID=3787;POINT (%s %s)' % (e['stevci_geoX'], e['stevci_geoY']))
        si_point.transform(geotransform)
        e[u'stevci_geoX_wgs'] = si_point.x
        e[u'stevci_geoY_wgs'] = si_point.y

    json['updated'] = time.time()
    json['copyright'] = COPYRIGHT_PROMET
    return json