-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_df.py
51 lines (44 loc) · 1.26 KB
/
build_df.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
39
40
41
42
43
44
45
46
47
48
49
50
51
import datetime
import os
from absl import logging, app, flags
import pandas as pd
import storage
import sqlite3
FLAGS = flags.FLAGS
flags.DEFINE_string("place", "san_carlos", ",".join(storage.PLACES.keys()))
flags.DEFINE_string("database", "darksky.sqlite", "location of database")
flags.DEFINE_string("outdir", "summaries", "where to write csv")
my_cols = [
"latitude",
"longitude",
"date_str",
"hour",
"icon",
"temperature",
"windSpeed",
"apparentTemperature",
"cloudCover",
"dewPoint",
"humidity",
"precipIntensity",
"precipProbability",
"pressure",
"summary",
]
def main(argv):
lat, lng = storage.PLACES[FLAGS.place]
db = sqlite3.connect(FLAGS.database)
sel_str = ",".join(my_cols)
df = pd.read_sql("SELECT %s from hourly_weather hw JOIN locations l ON l.location_id = hw.location_id WHERE l.location_name = '%s'" % (sel_str, FLAGS.place), db)
logging.debug(df.head())
max_date = df["date_str"].max()
min_date = df["date_str"].min()
logging.info("writing data through %s", max_date)
df.to_csv(
os.path.join(
FLAGS.outdir,
"{}_through_{}_from_{}.csv.gz".format(FLAGS.place, max_date, min_date),
)
)
if __name__ == "__main__":
app.run(main)