-
Notifications
You must be signed in to change notification settings - Fork 58
/
convert_weather.py
executable file
·38 lines (27 loc) · 1.04 KB
/
convert_weather.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#! /usr/bin/env python
import json
import re
WEATHER_RX = r'public static const ([A-Z_]*):Object = ({[^\}]*})'
PROP_RX = r':([^,\n]*)([,\n])'
# weatherfile = open('Weather.as').read()
# jsonfile = open("weathers.json",'w')
# weathers = {}
# for a in re.findall(WEATHER_RX, weatherfile, re.DOTALL):
# print a[0]
# w = re.sub(PROP_RX, r':"\1"\2', a[1])
# w = w.replace("'",'"')
# weathers[a[0]] = json.loads(w)
#
# json.dump(weathers, jsonfile, indent=2)
#
presets = open('WeatherPresets.as', 'w')
presets.write("// THIS FILE IS AUTOGENERATED, MODIFY weathers.json IN STEAD.\n\n")
presets.write("package {\n")
presets.write("public class WeatherPresets extends Object{\n")
weathers = json.load(open('weathers.json'))
print "Found: \n- " + '\n- '.join(sorted(weathers.keys()))
for weather, content in weathers.items():
presets.write("\tpublic static const %s:Object = {\n" % (weather))
presets.write(',\n'.join(["\t\t'%s': %s" % (key,val) for key, val in content.items()]))
presets.write('\n\t}\n')
presets.write("}\n}")