【问题标题】:how do you get the current weather on python [closed]你如何在 python 上获取当前天气 [关闭]
【发布时间】:2014-06-28 22:43:39
【问题描述】:

我很抱歉,因为我没有代码作为示例。这是因为我不知道如何导入天气。我是 python 新手,我正在尝试编写一个可以执行一些简单辅助任务的代码,例如告诉时间、回答随机问题(这两个我都可以做)和告诉天气。如果有人知道如何以简单或其他方式导入当前天气,请告诉我。

【问题讨论】:

  • import current_weather?开个玩笑。
  • 用户会提供地点还是您会事先定义地点?
  • 使用漂亮的汤和您选择的天气网站。

标签: python weather


【解决方案1】:

使用svn checkout http://python-weather-api.googlecode.com/svn/trunk/ python-weather-api-read-onlypython-weather-api获取代码

我正在使用 ubuntu,所以如果您使用其他操作系统,请查看链接以获取说明。

cd 到 python-weather-api-read-only 然后运行 ​​sudo python setup.py install

您可以从here获取天气国家代码ID

我根据一个文档示例做了一个简单的函数:

import pywapi
import string
def get_weather(loc_id):
    weather_com_result = pywapi.get_weather_from_weather_com(loc_id)
    yahoo_result = pywapi.get_weather_from_yahoo(loc_id)
    print "Weather.com says: It is " + string.lower(weather_com_result['current_conditions']['text']) + " and " +   weather_com_result['current_conditions']['temperature'] + "C now in Galway Ireland.\n\n"
    print "Yahoo says: It is " + string.lower(yahoo_result['condition']['text']) + " and " + yahoo_result['condition']['temp'] + "C now in Galway Ireland.\n\n"

In [2]: get_weather('EIXX0017')
Weather.com says: It is cloudy / windy and 11C now in Galway Ireland.

Yahoo says: It is partly cloudy and 12C now in Galway Ireland.

google了五分钟才找到,安装,做了一个简单的功能。

如果您想接受用户输入,请使用国家/城市作为键并将代码存储为值。

【讨论】:

    猜你喜欢
    • 2011-01-28
    • 2013-03-03
    • 1970-01-01
    • 2014-09-01
    • 2010-12-01
    • 2011-10-19
    • 1970-01-01
    • 2012-04-24
    • 2011-10-22
    相关资源
    最近更新 更多