Created
February 5, 2019 16:00
-
-
Save xtpor/0ef8347e17b10096db6634f64c57b600 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
temperatures_file = sys.argv[1] | |
record_file = sys.argv[2] | |
def parse_csv(text): | |
return [line.split(",") for line in text.split("\n")] | |
def lookup_temperature(district, date): | |
year, month, day = date.split("/") | |
headers = temperatures_data[0] | |
i = headers.index("%s月-%s" % (month, year[-2:])) | |
j = [row[1] for row in temperatures_data].index(district) | |
return temperatures_data[j][i] | |
with open(temperatures_file, "r") as f: | |
temperatures_data = parse_csv(f.read()) | |
with open(record_file, "r") as f: | |
record_data = parse_csv(f.read()) | |
print(",".join(record_data[0])) | |
for record in record_data[1:]: | |
serial, date0, z0, date1, z1, date2, z2, date3, z3, district, a, b, c = record | |
if district: | |
if date0: | |
z0 = lookup_temperature(district, date0) | |
if date1: | |
z1 = lookup_temperature(district, date1) | |
if date2: | |
z2 = lookup_temperature(district, date2) | |
if date3: | |
z3 = lookup_temperature(district, date3) | |
print(",".join([serial, date0, z0, date1, z1, date2, z2, date3, z3, district, a, b, c])) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment