如何在python上获取当前天气

如何在python上获取当前天气,python,weather,Python,Weather,我道歉,因为我没有代码作为例子。这是因为我不知道如何输入天气。我是python新手,我正在尝试编写一个代码,它可以执行一些简单的辅助任务,例如报时、回答随机问题(这两个我都能做)和告诉天气。如果有人知道如何以简单或其他方式导入当前天气,请告诉我。使用svn checkouthttp://python-weather-api.googlecode.com/svn/trunk/ python weather api只读,从中获取代码 我正在使用ubuntu,所以如果你正在使用其他操作系统,请查看链接

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

使用
svn checkouthttp://python-weather-api.googlecode.com/svn/trunk/ python weather api只读
,从中获取代码

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

cd至python天气api只读,然后运行sudo python setup.py安装

您可以从以下位置获取天气国家代码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.
搜索谷歌后,花了五分钟找到、安装并制作了一个简单的功能


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

导入当前天气
?开玩笑吧。用户会提供地点还是你会事先定义地点?使用你选择的美丽的汤和天气网站。