-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecoder.py
More file actions
57 lines (44 loc) · 1.63 KB
/
decoder.py
File metadata and controls
57 lines (44 loc) · 1.63 KB
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
52
53
54
55
56
57
def dayDecoder(data):
# 最高温度と最低温度のどちらかがない場合
if data["temperature"]["min"] == None or data["temperature"]["max"] == None:
return {\
"date":data["date"],\
"telop":data["telop"],\
"telop":data["telop"],\
"temperature":None,\
"umbrella":"雨" in data["telop"]
}
# 最高温度と最低温度の両方ある場合
else:
# 温度は°Cのみ使用(celsius) °Fは"fahrenheit"を指定
return {\
"date":data["date"],\
"telop":data["telop"],\
"telop":data["telop"],\
"temperature":{\
"min":data["temperature"]["min"]["celsius"],\
"max":data["temperature"]["max"]["celsius"],\
},\
"umbrella":"雨" in data["telop"]
}
def decoder(infData):
# 明後日がデータない時があるので、その対応
todayWeather = None
tomorrowWeather = None
dayAfterTomorrowWeather = None
for inf in infData["forecasts"]:
if inf["dateLabel"] == "今日":
todayWeather = dayDecoder(inf)
elif inf["dateLabel"] == "明日":
tomorrowWeather = dayDecoder(inf)
elif inf["dateLabel"] == "明後日":
dayAfterTomorrowWeather = dayDecoder(inf)
# 返すデータを作る
retData = {\
"place":infData["location"],\
"presentationTime":infData["publicTime"],\
"today":todayWeather,\
"tomorrow":tomorrowWeather,\
"dayAfterTomorrow":dayAfterTomorrowWeather
}
return retData