blob: 8a97a5bdc037b3e464c1489a3f40f9c37cfac55d (
plain)
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
|
"""
OPENWEATHERというインターネットサービスを利用したものです。
私個人のAPIキーですが、個人で利用したものを利用してアクセスしてください
d5098ce4e32e6d1ffc703cd671d8f985
http://api.openweathermap.org/data/2.5/forecast?id=1850147&APPID={APIKEY}
"""
import os
import json
import time
import sys
from multiprocessing import Process
ok = None
home = os.environ['HOME']
# check the exists of recent prediction
with open('{home}/kawaii-term/async/weather.txt'.format(home=home),'r') as f:
line = None
for line in f:
...
last = line.strip()
if last == '':
ok = False
print('please wait serveral seconds...' )
else:
#print('last', last )
lasttime = int( last.split('___').pop(0) )
if int( time.time() ) - lasttime > 30:
#print('refresh')
ok = False
# 無条件に出力
print(last.split('___').pop() )
def async_update():
raw = os.popen('curl -s "http://api.openweathermap.org/data/2.5/weather?q=Tokoy,jp&appid=1e240e732347c23472274dc188cd39d6"').read()
obj = json.loads( raw )
desc = obj['weather'][0]['description']
save = '___'.join( map(str,[int(time.time()), desc] ) )
os.system('echo {save} >> {home}/kawaii-term/async/weather.txt'.format( save=save, home=home ) )
if ok is not None:
p = Process(target=async_update, args=())
p.start()
p.join()
|