示例#1
0
def main():
	from datetime import date
	import os

	global saved

	f = open(os.path.expanduser("~/.osmitstats"), "r")
	j = JsonReader()
	saved = j.read(f.readline())
	print repr(saved)
	f.close()
	#saved["current"] = str(date.today()).replace('-', '')
	#today = str(date.today()).replace('-', '')
	saved["current"] = "20090531"

	q_regioni = """SELECT c.nome_reg, sum(c.pop2001), sum(length(transform(s.intersection, 3395))) AS highw FROM it_comuni c LEFT JOIN osm_stat_20090531 s ON c.pro_com =s.pro_com GROUP BY c.nome_reg ORDER BY nome_reg;"""
	
	f = open("page.html", "w")
	f.write(comuni_coperti_per_regione())
	f.flush()
	f.close()

	# The script has finished now, touch our helper file
	f = open(os.path.expanduser("~/.osmitstats"), "w")
	j = JsonWriter()
	#saved["previous"] = saved["current"]
	saved["current"] = None
	f.write(j.write(saved))
	f.close()
示例#2
0
def save(nodes, ways, relations, tags):
    try:
        j = JsonReader()
        f = open(os.path.expanduser(stats_path), "r")
        stats = j.read(f.readline())
        f.close()
    except (ReadException, IOError):
        f = open(os.path.expanduser(stats_path), "w")
        f.close()
        stats = {}
        pass

    nodes_count = 0
    ways_count = 0
    relations_count = 0

    # let's count primitives
    for pair in mysort(nodes, False):
        nodes_count += pair[0]
    for pair in mysort(ways, False):
        ways_count += pair[0]
    for pair in mysort(relations, False):
        relations_count += pair[0]

    tags_count = defaultdict(int)
    for tag in tags:
        for pair in tags[tag]:
            tags_count[tag] += pair[0]

    p = re.compile(".*/italy_(\d{8})\.osm")
    m = p.match(sys.argv[1])
    if m:
        date = m.groups()[0]
    else:
        date = today

    stats[date] = {
        "nodes" : nodes_count,
        "ways" : ways_count,
        "relations" : relations_count,
        "tags" : dict(tags_count),
    }

    f = open(os.path.expanduser(stats_path), "w")
    j = JsonWriter()
    f.write(j.write(stats))
    f.close()
示例#3
0
def main():
	from optparse import OptionParser
	import os

	global saved

	parser = OptionParser()
	parser.add_option("--planet", dest="planet", action="store",
	                  default=None, help="The planet file to parse")
	parser.add_option("--key", dest="key", action="store",
	                  default=None, help="The key to generate statistics for")
	parser.add_option("--tag", dest="tag", action="store",
	                  default=None, help="The tag to generate statistics for")
	(options, args) = parser.parse_args()

	if not options.planet:
		parser.error("The --planet option is required.")

	if options.key and options.tag:
		parser.error("You cannot specify both --tag and --key.")

	if not options.key and not options.tag:
		parser.error("You must specify one between --tag and --key.")

	if options.key:
		options.tag = "%s=*" % options.key

	try:
		f = open(os.path.expanduser("~/.osmitstats"), "r")
		j = JsonReader()
		saved = j.read(f.readline())
		f.close()
	except ReadException:
		pass

	saved["tagstats"] = {
		"20090617" : parse(options.planet, options.tag)
	}

	print repr(saved)

	f = open(os.path.expanduser("~/.osmitstats"), "w")
	j = JsonWriter()
	f.write(j.write(saved))
	f.close()