Yahoo重新开放了天气API,不使用oauth只能每天获取2000次/ip
使用oauth获取天气的python代码如下,使用了requests_oauthlib进行认证
使用oauth获取天气的次数为每小时2w次,每天10w次。
使用前请注册一个Yahoo的APP获得key
# sudo pip install requests requests_oauthlib
import requests from requests_oauthlib import OAuth1 consumerKey = <Your Consumer Key from Yahoo> consumerSecret = <Your Consumer Secret from Yahoo> baseurl = "https://query.yahooapis.com/v1/yql?" yql_query = 'select * ' + 'from weather.forecast where woeid in' yql_query += ' (select woeid from geo.places(1) where text="%s") and u="c"' % "Beijing" auth = OAuth1(consumerKey, consumerSecret) result = requests.post(baseurl, data={'q': yql_query, 'format': 'json'}, auth=auth) print result # Out[10]: <Response [200]> print result.json()<br><br># Out[11]: u'{"query":{"count":1,"created":"2017-07-10T12:50:30Z","lang":"en-US","results":{"channel":{"units":{"distance":"km","pressure":"mb","speed":"km/h","temperature":"C"},"title":"Yahoo! Weather - Beijing, Beijing, CN","link":"http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*","description":"Yahoo! Weather for Beijing, Beijing, CN","language":"en-us","lastBuildDate":"Mon, 10 Jul 2017 08:50 PM CST","ttl":"60","location":{"city":"Beijing","country":"China","region":" Beijing"},"wind":{"chill":"90","direction":"205","speed":"17.70"},"atmosphere":{"humidity":"41","pressure":"33626.85","rising":"0","visibility":"25.91"},"astronomy":{"sunrise":"4:55 am","sunset":"7:44 pm"},"image":{"title":"Yahoo! Weather","width":"142","height":"18","link":"http://weather.yahoo.com","url":"http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif"},"item":{"title":"Conditions for Beijing, Beijing, CN at 08:00 PM CST","lat":"39.90601","long":"116.387909","link":"http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*","pubDate":"Mon, 10 Jul 2017 08:00 PM CST","condition":{"code":"31","date":"Mon, 10 Jul 2017 08:00 PM CST","temp":"32","text":"Clear"},"forecast":[{"code":"32","date":"10 Jul 2017","day":"Mon","high":"38","low":"22","text":"Sunny"},{"code":"30","date":"11 Jul 2017","day":"Tue","high":"35","low":"22","text":"Partly Cloudy"},{"code":"34","date":"12 Jul 2017","day":"Wed","high":"36","low":"26","text":"Mostly Sunny"},{"code":"4","date":"13 Jul 2017","day":"Thu","high":"37","low":"27","text":"Thunderstorms"},{"code":"4","date":"14 Jul 2017","day":"Fri","high":"35","low":"26","text":"Thunderstorms"},{"code":"4","date":"15 Jul 2017","day":"Sat","high":"31","low":"26","text":"Thunderstorms"},{"code":"4","date":"16 Jul 2017","day":"Sun","high":"32","low":"25","text":"Thunderstorms"},{"code":"30","date":"17 Jul 2017","day":"Mon","high":"33","low":"25","text":"Partly Cloudy"},{"code":"30","date":"18 Jul 2017","day":"Tue","high":"34","low":"25","text":"Partly Cloudy"},{"code":"30","date":"19 Jul 2017","day":"Wed","high":"35","low":"25","text":"Partly Cloudy"}],"description":"<![CDATA[<img src=\\"http://l.yimg.com/a/i/us/we/52/31.gif\\"/ alt="Yahoo Weather API with Oauth1" >\\n<BR />\\n<b>Current Conditions:</b>\\n<BR />Clear\\n<BR />\\n<BR />\\n<b>Forecast:</b>\\n<BR /> Mon - Sunny. High: 38Low: 22\\n<BR /> Tue - Partly Cloudy. High: 35Low: 22\\n<BR /> Wed - Mostly Sunny. High: 36Low: 26\\n<BR /> Thu - Thunderstorms. High: 37Low: 27\\n<BR /> Fri - Thunderstorms. High: 35Low: 26\\n<BR />\\n<BR />\\n<a href=\\"http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*\\">Full Forecast at Yahoo! Weather</a>\\n<BR />\\n<BR />\\n(provided by <a href=\\"http://www.weather.com\\" >The Weather Channel</a>)\\n<BR />\\n]]>","guid":{"isPermaLink":"false"}}}}}}'
The above is the detailed content of Yahoo Weather API with Oauth1. For more information, please follow other related articles on the PHP Chinese website!

Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

This article explains how to use Beautiful Soup, a Python library, to parse HTML. It details common methods like find(), find_all(), select(), and get_text() for data extraction, handling of diverse HTML structures and errors, and alternatives (Sel

Serialization and deserialization of Python objects are key aspects of any non-trivial program. If you save something to a Python file, you do object serialization and deserialization if you read the configuration file, or if you respond to an HTTP request. In a sense, serialization and deserialization are the most boring things in the world. Who cares about all these formats and protocols? You want to persist or stream some Python objects and retrieve them in full at a later time. This is a great way to see the world on a conceptual level. However, on a practical level, the serialization scheme, format or protocol you choose may determine the speed, security, freedom of maintenance status, and other aspects of the program

This article compares TensorFlow and PyTorch for deep learning. It details the steps involved: data preparation, model building, training, evaluation, and deployment. Key differences between the frameworks, particularly regarding computational grap

Python's statistics module provides powerful data statistical analysis capabilities to help us quickly understand the overall characteristics of data, such as biostatistics and business analysis. Instead of looking at data points one by one, just look at statistics such as mean or variance to discover trends and features in the original data that may be ignored, and compare large datasets more easily and effectively. This tutorial will explain how to calculate the mean and measure the degree of dispersion of the dataset. Unless otherwise stated, all functions in this module support the calculation of the mean() function instead of simply summing the average. Floating point numbers can also be used. import random import statistics from fracti

This tutorial builds upon the previous introduction to Beautiful Soup, focusing on DOM manipulation beyond simple tree navigation. We'll explore efficient search methods and techniques for modifying HTML structure. One common DOM search method is ex

This article guides Python developers on building command-line interfaces (CLIs). It details using libraries like typer, click, and argparse, emphasizing input/output handling, and promoting user-friendly design patterns for improved CLI usability.

The article discusses popular Python libraries like NumPy, Pandas, Matplotlib, Scikit-learn, TensorFlow, Django, Flask, and Requests, detailing their uses in scientific computing, data analysis, visualization, machine learning, web development, and H


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version
Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment