# Path: prometapi/compat.py
# def zlib_encode(data):
# 
# Path: prometapi/encoders.py
# def encrypt(e, t):
#     r = str_to_longs(e)
#     a = str_to_longs(t)
#     if len(r) <= 1:
#         r = [r[0], 0]
#     
#     l = len(r)
#     g = r[l - 1]
#     s = r[0]
#     i = 2654435769
#     c = math.floor(6 + 52 / l)
#     u = 0
#     
#     while c > 0:
#         u += i
#         n = rshift(u, 2) & 3
#         
#         p = 0
#         while l > p:
#             s = r[(p + 1) % l]
#             o = (rshift(g, 5) ^ ((s << 2) & 0xffffffff) ) + (rshift(s, 3) ^ ((g << 4) & 0xffffffff)) ^ (u ^ s) + (a[3 & p ^ n] ^ g)
#             g = r[p] = (r[p] + o) & 0xffffffff
#             
#             p += 1
#         c -= 1
#     f = longs_to_str(r)
#     return f
# 
# Path: prometapi/geoprocessing.py
# def get_coordtransform():
# 	from django.contrib.gis.gdal.srs import SpatialReference, CoordTransform
# 	sl = SpatialReference('EPSG:3787')
# 	sl.import_wkt(sl_wkt)
# 	wgs = SpatialReference('EPSG:4326')
# 	trans = CoordTransform(sl, wgs)
# 	return trans
# 
# def find_coordtransform(srid):
# 	if srid == u'EPSG:3787':
# 		return get_coordtransform()
# 	elif srid == u'EPSG:3912':
# 		from django.contrib.gis.gdal.srs import SpatialReference, CoordTransform
# 		sl = SpatialReference('EPSG:3912')
# 		wgs = SpatialReference('EPSG:4326')
# 		trans = CoordTransform(sl, wgs)
# 		return trans
# 	else:
# 		raise ValueError("Couldn't find transform: %r" % srid)


import datetime
import re
import os
import uuid
import simplejson
import time
import urllib
import requests
import subprocess
import xml.etree.ElementTree as ET
from prometapi.compat import urlopen, unicode_type, unichr_cast
from calendar import timegm
from django.db import models
from django.contrib.gis.geos import GEOSGeometry
from django.utils._os import safe_join
from django.utils.timezone import make_aware, utc
from django.conf import settings
from prometapi.encoders import encrypt
from prometapi.geoprocessing import get_coordtransform, find_coordtransform
    from django.db import connection
        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

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

def fetch_prikljucki():
    url = get_lokacije_url('prikljucki')

# Path: prometapi/compat.py
# def zlib_encode(data):
# 
# Path: prometapi/encoders.py
# def encrypt(e, t):
#     r = str_to_longs(e)
#     a = str_to_longs(t)
#     if len(r) <= 1:
#         r = [r[0], 0]
#     
#     l = len(r)
#     g = r[l - 1]
#     s = r[0]
#     i = 2654435769
#     c = math.floor(6 + 52 / l)
#     u = 0
#     
#     while c > 0:
#         u += i
#         n = rshift(u, 2) & 3
#         
#         p = 0
#         while l > p:
#             s = r[(p + 1) % l]
#             o = (rshift(g, 5) ^ ((s << 2) & 0xffffffff) ) + (rshift(s, 3) ^ ((g << 4) & 0xffffffff)) ^ (u ^ s) + (a[3 & p ^ n] ^ g)
#             g = r[p] = (r[p] + o) & 0xffffffff
#             
#             p += 1
#         c -= 1
#     f = longs_to_str(r)
#     return f
# 
# Path: prometapi/geoprocessing.py
# def get_coordtransform():
# 	from django.contrib.gis.gdal.srs import SpatialReference, CoordTransform
# 	sl = SpatialReference('EPSG:3787')
# 	sl.import_wkt(sl_wkt)
# 	wgs = SpatialReference('EPSG:4326')
# 	trans = CoordTransform(sl, wgs)
# 	return trans
# 
# def find_coordtransform(srid):
# 	if srid == u'EPSG:3787':
# 		return get_coordtransform()
# 	elif srid == u'EPSG:3912':
# 		from django.contrib.gis.gdal.srs import SpatialReference, CoordTransform
# 		sl = SpatialReference('EPSG:3912')
# 		wgs = SpatialReference('EPSG:4326')
# 		trans = CoordTransform(sl, wgs)
# 		return trans
# 	else:
# 		raise ValueError("Couldn't find transform: %r" % srid)


# Path: prometapi/models.py
import datetime
import re
import os
import uuid
import simplejson
import time
import urllib
import requests
import subprocess
import xml.etree.ElementTree as ET
from prometapi.compat import urlopen, unicode_type, unichr_cast
from calendar import timegm
from django.db import models
from django.contrib.gis.geos import GEOSGeometry
from django.utils._os import safe_join
from django.utils.timezone import make_aware, utc
from django.conf import settings
from prometapi.encoders import encrypt
from prometapi.geoprocessing import get_coordtransform, find_coordtransform
    from django.db import connection

        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

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

def fetch_prikljucki():
    url = get_lokacije_url('prikljucki')

    original_data = urlopen(url).read()