-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackfill.py
28 lines (21 loc) · 900 Bytes
/
backfill.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
from absl import logging, app, flags
import storage
FLAGS = flags.FLAGS
flags.DEFINE_string("place", "san_carlos", ",".join(storage.PLACES.keys()))
flags.DEFINE_string("datadir", "data", "location of data cache")
flags.DEFINE_string("database", "darksky.sqlite", "location of database")
def main(argv):
wdb = storage.WeatherDB(FLAGS.datadir)
sql = storage.WeatherSQL(FLAGS.database)
lat, lng = storage.PLACES[FLAGS.place]
location_id = storage.LOCATION_IDS[FLAGS.place]
days = wdb.get_cached_days_for_location(lat, lng)
days = sorted(days)
logging.info("have %s days for location %s", len(days), FLAGS.place)
for ix, dt in enumerate(days):
if ix % 1000 == 0:
logging.info("doing %s" % dt)
res = wdb.get_from_storage(storage.PlaceTime(lat, lng, dt))
sql.put(location_id, dt, res)
if __name__ == "__main__":
app.run(main)