Yahoo Weather API with Oauth1
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\\"/>\\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!

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

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



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

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

Regular expressions are powerful tools for pattern matching and text manipulation in programming, enhancing efficiency in text processing across various applications.

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

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

In Python, how to dynamically create an object through a string and call its methods? This is a common programming requirement, especially if it needs to be configured or run...
