Skip to content

Instantly share code, notes, and snippets.

@RobTranquillo
Last active August 29, 2015 14:23
Show Gist options
  • Save RobTranquillo/7f417b802dcf33780ef5 to your computer and use it in GitHub Desktop.
Save RobTranquillo/7f417b802dcf33780ef5 to your computer and use it in GitHub Desktop.
[ParkAPI] a modul, to get an old totals value from json file or null
#if a city does not send totals so we push totals to the higest known value in the json file
#
# problem: if one lot name exist twice, it takes always the last value
# but a lot name should never exists more than one time
def get_lastlots ( lot_name ) :
import os.path
lots = 0
last_values_json = "cache/<city>.json"
if os.path.isfile(last_values_json):
with open(last_values_json) as data_file:
import json
last_values = json.load(data_file)
if last_values is None :
# if no last json file exists, return 0
return 0
for lastlots in last_values["lots"] :
if lastlots["name"] is lot_name:
lots = int(lastlots["total"])
return lots
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment