質問編集履歴

1

脱字

2021/10/04 07:00

投稿

vally
vally

スコア3

test CHANGED
File without changes
test CHANGED
@@ -28,6 +28,296 @@
28
28
 
29
29
 
30
30
 
31
+ from kivy.network.urlrequest import UrlRequest
32
+
33
+ import certifi as cfi
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+ class WeatherWidget(Screen):
42
+
43
+
44
+
45
+ city = StringProperty('--')
46
+
47
+ saiko = StringProperty("--")
48
+
49
+ saite = StringProperty("--")
50
+
51
+ forecast = []
52
+
53
+
54
+
55
+ def download_current_weather(self, city, *args, **kwargs):
56
+
57
+ url = 'https://api.openweathermap.org/data/2.5/weather?q=' + city + '&lang=ja&APPID=8ed81ed8fdfd79eb23df5bc02b396d09'
58
+
59
+ UrlRequest(url = url, on_success = self.show_current_weather, on_error = self.download_error, on_progress = self.progress, chunk_size = 40960,ca_file=cfi.where(), verify=True)
60
+
61
+
62
+
63
+ def download_forecast(self, city, *args, **kwargs):
64
+
65
+ url = 'https://api.openweathermap.org/data/2.5/forecast?q=' + city + '&cnt=8&lang=ja&APPID=8ed81ed8fdfd79eb23df5bc02b396d09'
66
+
67
+ UrlRequest(url = url, on_success = self.show_forecast, on_error = self.download_error, on_progress = self.progress, chunk_size = 40960,ca_file=cfi.where(), verify=True)
68
+
69
+
70
+
71
+ def download_error(self, request, error):
72
+
73
+ self.notification = 'data could not be downloaded'
74
+
75
+
76
+
77
+ def progress(self, request, current_size, total_size):
78
+
79
+ self.notification = ('Downloading data: {} bytes of {} bytes'.format(current_size, total_size))
80
+
81
+
82
+
83
+ def show_current_weather(self, request, result):
84
+
85
+ self.city = result.get('name','nn')
86
+
87
+
88
+
89
+ self.notification = ''
90
+
91
+
92
+
93
+
94
+
95
+ def show_forecast(self, request, result):
96
+
97
+ self.forecast = result
98
+
99
+
100
+
101
+ self.ids['grid'].clear_widgets()
102
+
103
+
104
+
105
+ for count in self.forecast['list']:
106
+
107
+ tenki = count['weather'][0]['main']
108
+
109
+
110
+
111
+ self.ids['grid'].add_widget(Label(text=strftime('%H:%M',gmtime(count['dt'])), font_size='30sp'))
112
+
113
+
114
+
115
+ if tenki == "Clouds":
116
+
117
+ self.ids['grid'].add_widget(Label(text="曇り", font_size='30sp'))
118
+
119
+ if tenki == "Rain":
120
+
121
+ self.ids['grid'].add_widget(Label(text="雨", font_size='30sp'))
122
+
123
+ if tenki == "clear sky":
124
+
125
+ self.ids['grid'].add_widget(Label(text="晴れ", font_size='30sp'))
126
+
127
+
128
+
129
+
130
+
131
+ self.ids['grid'].add_widget(Label(text='{:.0f}'.format(count['main']['temp'] - 273.15) + '°C', font_size='30sp'))
132
+
133
+ self.ids['grid'].add_widget(Label(text='{:.0f}'.format(count['pop']*100) + '%', font_size='30sp'))
134
+
135
+ self.ids['grid'].add_widget(Label(text='{:.0f}'.format(count['main']['humidity']) + '%', font_size='30sp'))
136
+
137
+ self.ids['grid'].add_widget(Label(text='{:.0f}'.format(count['wind']['speed']) + '(m/s)', font_size='30sp'))
138
+
139
+
140
+
141
+ self.notification = ''
142
+
143
+ class WeatherWidget2(Screen):
144
+
145
+
146
+
147
+ city = StringProperty('--')
148
+
149
+
150
+
151
+ forecast2 = []
152
+
153
+
154
+
155
+ def download_current_weather2(self, city, *args, **kwargs):
156
+
157
+ url = 'https://api.openweathermap.org/data/2.5/weather?q=' + city + '&lang=ja&APPID=8ed81ed8fdfd79eb23df5bc02b396d09'
158
+
159
+ UrlRequest(url = url, on_success = self.show_current_weather, on_error = self.download_error2, on_progress = self.progress2, chunk_size = 40960,ca_file=cfi.where(), verify=True)
160
+
161
+
162
+
163
+ def download_forecast2(self, lat, lon, *args, **kwargs):
164
+
165
+ url = 'https://api.openweathermap.org/data/2.5/onecall?lat=' + lat + '&lon=' + lon + '&exclude=current,minutely,hourly,alerts&lang=ja&APPID=8ed81ed8fdfd79eb23df5bc02b396d09'
166
+
167
+ UrlRequest(url = url, on_success = self.show_forecast2, on_error = self.download_error2, on_progress = self.progress2, chunk_size = 40960,ca_file=cfi.where(), verify=True)
168
+
169
+
170
+
171
+ def download_error2(self, request, error):
172
+
173
+ self.notification = 'data could not be downloaded'
174
+
175
+
176
+
177
+ def progress2(self, request, current_size, total_size):
178
+
179
+ self.notification = ('Downloading data: {} bytes of {} bytes'.format(current_size, total_size))
180
+
181
+
182
+
183
+ def show_current_weather(self, request, result):
184
+
185
+
186
+
187
+ self.city = result.get('name','nn')
188
+
189
+
190
+
191
+ self.notification = ''
192
+
193
+
194
+
195
+ def show_forecast2(self, request, result):
196
+
197
+ self.forecast2 = result
198
+
199
+
200
+
201
+ self.ids['grid2'].clear_widgets()
202
+
203
+
204
+
205
+ for count in self.forecast2['daily']:
206
+
207
+ dt=strftime('%a',gmtime(count['dt']))
208
+
209
+ tenki = count['weather'][0]['main']
210
+
211
+
212
+
213
+ if dt == "Mon":
214
+
215
+ self.ids['grid2'].add_widget(Label(text ="月曜日", font_size='30sp'))
216
+
217
+ if dt == "Tue":
218
+
219
+ self.ids['grid2'].add_widget(Label(text ="火曜日", font_size='30sp'))
220
+
221
+ if dt == "Wed":
222
+
223
+ self.ids['grid2'].add_widget(Label(text ="水曜日", font_size='30sp'))
224
+
225
+ if dt == "Thu":
226
+
227
+ self.ids['grid2'].add_widget(Label(text ="木曜日", font_size='30sp'))
228
+
229
+ if dt == "Fri":
230
+
231
+ self.ids['grid2'].add_widget(Label(text ="金曜日", font_size='30sp'))
232
+
233
+ if dt == "Sat":
234
+
235
+ self.ids['grid2'].add_widget(Label(text ="土曜日", font_size='30sp'))
236
+
237
+ if dt == "Sun":
238
+
239
+ self.ids['grid2'].add_widget(Label(text ="日曜日", font_size='30sp'))
240
+
241
+
242
+
243
+ if tenki == "Clouds":
244
+
245
+ self.ids['grid2'].add_widget(Label(text="曇り", font_size='30sp'))
246
+
247
+ if tenki == "Rain":
248
+
249
+ self.ids['grid2'].add_widget(Label(text="雨", font_size='30sp'))
250
+
251
+ if tenki == "Clear":
252
+
253
+ self.ids['grid2'].add_widget(Label(text="晴れ", font_size='30sp'))
254
+
255
+ self.ids['grid2'].add_widget(Label(text='{:.0f}'.format(count['temp']['max'] - 273.15) + '°C', font_size='30sp'))
256
+
257
+ self.ids['grid2'].add_widget(Label(text='{:.0f}'.format(count['temp']['min'] - 273.15) + '°C', font_size='30sp'))
258
+
259
+ self.ids['grid2'].add_widget(Label(text='{:.0f}'.format(count['pop']*100) + '%', font_size='30sp'))
260
+
261
+
262
+
263
+ self.notification = ''
264
+
265
+
266
+
267
+ def show_forecast(self, request, result):
268
+
269
+ self.forecast = result
270
+
271
+
272
+
273
+ self.ids['grid'].clear_widgets()
274
+
275
+
276
+
277
+ for count in self.forecast['list']:
278
+
279
+ tenki = count['weather'][0]['main']
280
+
281
+
282
+
283
+ self.ids['grid'].add_widget(Label(text=strftime('%H:%M',gmtime(count['dt'])), font_size='30sp'))
284
+
285
+
286
+
287
+ if tenki == "Clouds":
288
+
289
+ self.ids['grid'].add_widget(Label(text="曇り", font_size='30sp'))
290
+
291
+ if tenki == "Rain":
292
+
293
+ self.ids['grid'].add_widget(Label(text="雨", font_size='30sp'))
294
+
295
+ if tenki == "clear sky":
296
+
297
+ self.ids['grid'].add_widget(Label(text="晴れ", font_size='30sp'))
298
+
299
+
300
+
301
+
302
+
303
+ self.ids['grid'].add_widget(Label(text='{:.0f}'.format(count['main']['temp'] - 273.15) + '°C', font_size='30sp'))
304
+
305
+ self.ids['grid'].add_widget(Label(text='{:.0f}'.format(count['pop']*100) + '%', font_size='30sp'))
306
+
307
+ self.ids['grid'].add_widget(Label(text='{:.0f}'.format(count['main']['humidity']) + '%', font_size='30sp'))
308
+
309
+ self.ids['grid'].add_widget(Label(text='{:.0f}'.format(count['wind']['speed']) + '(m/s)', font_size='30sp'))
310
+
311
+
312
+
313
+ self.notification = ''
314
+
315
+
316
+
317
+
318
+
319
+
320
+
31
321
  ```
32
322
 
33
323