-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcare.py
executable file
·64 lines (63 loc) · 2.01 KB
/
care.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
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
#-*-coding:utf-8-*-
#=======================================
# Author: liuzhida - [email protected]
# Last modified: 2012-09-07 15:58
# Filename: ai.py
# Description:
#=======================================
import urllib2
import redis
f = urllib2.urlopen(url = 'http://www.7timer.com/v4/bin/civillight.php?lon=116.407&lat=39.904&ac=0&unit=metric&output=json&tzshift=0',)
data = f.read()
json = eval(data)
temp1 = json['dataseries'][0]['temp2m']['max']
temp2 = json['dataseries'][0]['temp2m']['min']
temp3 = json['dataseries'][1]['temp2m']['max']
temp4 = json['dataseries'][1]['temp2m']['min']
wind1 = json['dataseries'][0]['wind10m_max']
wind2 = json['dataseries'][1]['wind10m_max']
weather = json['dataseries'][1]['weather']
temp = temp1-temp3
wind = wind1 -wind2
string = "明天"
flag = 0
if temp >= 3:
flag = 1
elif "rain" in weather:
string = string + "有雨要降温,记得添衣服带伞哦"
elif "snow" in weather:
string = string + "有雪要降温,记得添衣服带伞哦"
elif "storm" in weather:
string = string + "有暴风雨要降温,记得添衣服带伞哦"
elif "shower" in weather:
string = string + "有小雨要降温,记得添衣服带伞哦"
else:
string = string + "降温%s度,添件衣服吧"%temp
elif wind1 > 5 and wind <= -3:
string = string + "风大,添件衣服吧"
flag = 1
elif "rain" in weather:
string = string + "有雨,记得带伞哦"
flag = 1
elif "snow" in weather:
string = string + "有雪,记得带伞哦"
flag = 1
elif "storm" in weather:
string = string + "有暴风雨,记得带伞哦"
flag = 1
elif "shower" in weather:
string = string + "局部地区有小雨,记得带伞哦"
flag = 1
else:
flag = 0
print string
#r=redis.Redis(host='127.0.0.1',port=6379,db=0)
#phone_li = r.keys("weather:*")
#if flag == 1:
# for i in phone_li:
# phone = i.split(':')[1]
# sms = r.get(i)
# sms = sms.replace("{weather}",string)
#else:
# exit