# Path: prometapi/compat.py
# def zlib_encode(data):


from django.db import models
from prometapi.compat import urlopen, unicode_type
import xml.etree.ElementTree as ET
import datetime
import time
import sys
import foojson
import json
	carto = ET.fromstring(data)

	count = 0
	for marker in carto.findall('./markers/marker'):
		assert len(marker.getchildren()) == 0, 'Marker has children!? ' + repr(marker.getchildren())
		station_id = unicode_type(marker.attrib['number'])
		json[station_id] = dict(marker.attrib)
	
		count += 1
	assert count > 0, 'No markers found in main XML!?'
	
	return json

def _parse_station_xml(data):
	sta_xml = ET.fromstring(data)

	sta_dict = {}
	for elem in sta_xml.findall('./*'):
		sta_dict[elem.tag] = elem.text

	expected_keys = list(sorted(sta_dict.keys()))
	assert expected_keys == ['available', 'free', 'ticket', 'total'], 'Missing or added keys in station XML!? %r' % expected_keys
	# backwards compatibility
	return sta_dict

def fetch_xmls():
	main_xml = urlopen(URL_CARTO, timeout=10).read()
	json = _parse_main_xml(main_xml)
	
	for k, v in json.iteritems():

# Path: prometapi/compat.py
# def zlib_encode(data):


# Path: prometapi/bicikeljproxy/models.py
from django.db import models
from prometapi.compat import urlopen, unicode_type
import xml.etree.ElementTree as ET
import datetime
import time
import sys
import foojson
import json

	carto = ET.fromstring(data)

	count = 0
	for marker in carto.findall('./markers/marker'):
		assert len(marker.getchildren()) == 0, 'Marker has children!? ' + repr(marker.getchildren())
		station_id = unicode_type(marker.attrib['number'])
		json[station_id] = dict(marker.attrib)
	
		count += 1
	assert count > 0, 'No markers found in main XML!?'
	
	return json

def _parse_station_xml(data):
	sta_xml = ET.fromstring(data)

	sta_dict = {}
	for elem in sta_xml.findall('./*'):
		sta_dict[elem.tag] = elem.text

	expected_keys = list(sorted(sta_dict.keys()))
	assert expected_keys == ['available', 'free', 'ticket', 'total'], 'Missing or added keys in station XML!? %r' % expected_keys
	# backwards compatibility
	return sta_dict

def fetch_xmls():
	main_xml = urlopen(URL_CARTO, timeout=10).read()
	json = _parse_main_xml(main_xml)
	
	for k, v in json.iteritems():

		sta_xml_data = urlopen(URL_STATION % k, timeout=10).read()