Skip to content

Commit

Permalink
update python to 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrael committed Mar 16, 2023
1 parent 60c994e commit 759b09f
Show file tree
Hide file tree
Showing 29 changed files with 2,660 additions and 2,387 deletions.
Binary file added .DS_Store
Binary file not shown.
66 changes: 33 additions & 33 deletions data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,65 +7,65 @@ class Data:
def __init__(self):
pass

weather_dict = {u'CLEAR_DAY': {u'name': u'晴天', u'icon': u'assets/sun-3.png'},
u'CLEAR_NIGHT': {u'name': u'晴夜', u'icon': u'assets/moon-1.png'},
u'PARTLY_CLOUDY_DAY': {u'name': u'多云', u'icon': u'assets/cloudy.png'},
u'PARTLY_CLOUDY_NIGHT': {u'name': u'多云', u'icon': u'assets/cloudy-night.png'},
u'CLOUDY': {u'name': u'阴', u'icon': u'assets/cloud.png'},
u'RAIN': {u'name': u'雨', u'icon': u'assets/rain-1.png'},
u'SNOW': {u'name': u'雪', u'icon': u'assets/snow.png'},
u'WIND': {u'name': u'风', u'icon': u'assets/windy.png'},
u'FOG': {u'name': u'雾', u'icon': u'assets/fogg.png'}, u'HAZE': {u'name': u'霾'},
u'SLEET': {u'name': u'冻雨'}}
weather_dict = {'CLEAR_DAY': {'name': '晴天', 'icon': 'assets/sun-3.png'},
'CLEAR_NIGHT': {'name': '晴夜', 'icon': 'assets/moon-1.png'},
'PARTLY_CLOUDY_DAY': {'name': '多云', 'icon': 'assets/cloudy.png'},
'PARTLY_CLOUDY_NIGHT': {'name': '多云', 'icon': 'assets/cloudy-night.png'},
'CLOUDY': {'name': '阴', 'icon': 'assets/cloud.png'},
'RAIN': {'name': '雨', 'icon': 'assets/rain-1.png'},
'SNOW': {'name': '雪', 'icon': 'assets/snow.png'},
'WIND': {'name': '风', 'icon': 'assets/windy.png'},
'FOG': {'name': '雾', 'icon': 'assets/fogg.png'}, 'HAZE': {'name': '霾'},
'SLEET': {'name': '冻雨'}}

@staticmethod
def get_wind_direction(wd):
if wd <= 22.5 or wd > 337.5:
return u'北风'
return '北风'
elif 22.5 < wd <= 67.5:
return u'东北风'
return '东北风'
elif 67.5 < wd <= 112.5:
return u'东风'
return '东风'
elif 112.5 < wd <= 157.5:
return u'东南风'
return '东南风'
elif 157.5 < wd <= 202.5:
return u'南风'
return '南风'
elif 202.5 < wd <= 247.5:
return u'西南风'
return '西南风'
elif 247.5 < wd <= 292.5:
return u'西风'
return '西风'
elif 292.5 < wd <= 337.5:
return u'西北风'
return '西北风'

@staticmethod
def get_wind_speed(ws):
if ws <= 2:
return u'无风'
return '无风'
if 2 < ws <= 6:
return u'软风'
return '软风'
elif 6 < ws <= 12:
return u'轻风'
return '轻风'
elif 12 < ws <= 19:
return u'缓风'
return '缓风'
elif 19 < ws <= 30:
return u'和风'
return '和风'
elif 30 < ws <= 40:
return u'清风'
return '清风'
elif 40 < ws <= 51:
return u'强风'
return '强风'
elif 51 < ws <= 62:
return u'疾风'
return '疾风'
elif 62 < ws <= 75:
return u'烈风'
return '烈风'
elif 75 < ws <= 87:
return u'增强烈风'
return '增强烈风'
elif 87 < ws <= 103:
return u'暴风'
return '暴风'
elif 103 < ws <= 149:
return u'台风'
return '台风'
elif 149 < ws <= 183:
return u'强台飓风'
return '强台飓风'
elif 183 < ws <= 220:
return u'超强台飓风'
return '超强台飓风'
else:
return u'极强台飓风'
return '极强台飓风'
52 changes: 26 additions & 26 deletions forecast.py
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
# coding=utf-8
import sys
from workflow import Workflow3, notify
from ualfred import Workflow3, notify

log = None


def main(wf):
import cPickle
import pickle
from data import Data
from workflow import web
from ualfred import web

city = wf.stored_data(u'cy-city')
api_key = wf.get_password(u'apiKey')
city = wf.stored_data('cy-city')
api_key = wf.get_password('apiKey')

if city is None:
wf.add_item(u'请通过cy-opt 设置所在城市')
wf.add_item('请通过cy-opt 设置所在城市')
wf.send_feedback()
return
if api_key is None:
api_key = u'TAkhjf8d1nlSlspN'
api_key = 'TAkhjf8d1nlSlspN'

city_name = city[1]

url = u'https://api.caiyunapp.com/v2/' + api_key + u'/' + city[5] + u',' + city[4] + u'/forecast.json'
url = 'https://api.caiyunapp.com/v2/' + api_key + '/' + city[5] + ',' + city[4] + '/forecast.json'
log.debug(url)
r = web.get(url)
data = r.json()
log.debug(data)
if u'ok' == data[u'status']:
result = data[u'result']
wf.add_item(subtitle=city_name + u'未来24小时天气预报', title=result[u'hourly'][u'description'])
wf.add_item(title=result[u'minutely'][u'description'])
daily = result[u'daily']
if 'ok' == data['status']:
result = data['result']
wf.add_item(subtitle=city_name + '未来24小时天气预报', title=result['hourly']['description'])
wf.add_item(title=result['minutely']['description'])
daily = result['daily']
for i in range(1, 5):
skycon = daily[u'skycon'][i]
temp = daily[u'temperature'][i]
wind = daily[u'wind'][i]
ultraviolet = daily[u'ultraviolet'][i]
aqi = daily[u'aqi'][i]
subtitle = city_name + skycon[u'date'] + u'天气预报'
item = Data.weather_dict.get(skycon[u'value'])
skycon = daily['skycon'][i]
temp = daily['temperature'][i]
wind = daily['wind'][i]
ultraviolet = daily['ultraviolet'][i]
aqi = daily['aqi'][i]
subtitle = city_name + skycon['date'] + '天气预报'
item = Data.weather_dict.get(skycon['value'])
# add first
title = item.get(u'name')
title = item.get('name')
# add temperature
title += u'\t温度:' + str(temp[u'max']) + u'°~' + str(temp[u'min']) + u\t'
title += '\t温度:' + str(temp['max']) + '°~' + str(temp['min']) + \t'
# add wind
title += Data.get_wind_direction(wind[u'avg'][u'direction']) + Data.get_wind_speed(wind[u'avg'][u'speed'])
title += Data.get_wind_direction(wind['avg']['direction']) + Data.get_wind_speed(wind['avg']['speed'])
# add ultraviolet
title += u'\t紫外线:' + ultraviolet[u'desc']
title += '\t紫外线:' + ultraviolet['desc']
# add aqi
title += u'\tAQI:' + str(aqi['min']) + u'~' + str(aqi['max'])
title += '\tAQI:' + str(aqi['min']) + '~' + str(aqi['max'])

wf.add_item(subtitle=subtitle, title=title, icon=item.get(u'icon'), copytext=subtitle + u':' + title)
wf.add_item(subtitle=subtitle, title=title, icon=item.get('icon'), copytext=subtitle + ':' + title)

wf.send_feedback()

Expand Down
Loading

0 comments on commit 759b09f

Please sign in to comment.