Yahoo Weather API with Oauth1

Source: Internet
Author: User
Tags oauth yahoo weather api
Yahoo has reopened the weather API, and can only get 2000/IP per day without using OAuth

The Python code that uses OAuth to get the weather is as follows, using Requests_oauthlib for authentication

Use OAuth to get the weather for 2w times per hour, 10w times a day.

Please register a Yahoo app before use to get key

# sudo pip install requests requests_oauthlib

Import requestsfrom requests_oauthlib Import oauth1consumerkey = <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_que ry, ' format ': ' JSON '}, Auth=auth) print result# out[10]: <response [200]>print Result.json ()

# Out[11]: U ' {"Query": {"Count": 1, "created": "2017-07-10t12:50:30z", "Lang": "en-us", "results": {"channel": {"units": { "Distance": "km", "pressure": "MB", "Speed": "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, 08:50 PM CST "," TTL ":" $ "," location ": {" City ":" Beijing ', ' country ': ' China ', ' region ': ' Beijing '}, "Wind": {"Chill": "All", "direction": "205", "Speed": "17.70"}, " Atmosphere ": {" humidity ":" $ "," pressure ":" 33626.85 "," Rising ":" 0 "," visibility ":" 25.91 "}," Astronomy ": {" Sunrise ":" 4:55 am "," Sunset ":" 7:44 PM "}," image ": {" title ":" Yahoo! Weather "," width ":" 142 "," height ":" + "," 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 5:00pm CST "," lat ":" 39.90601 "," Long ":" 116.387909 "," link ":"/HTTP// Us.rd.yahoo.com/dailynews/rss/weather/country__country/* "," pubDate ": Mon, 5:00pm-6:00pm CST," condition ": {" code ":" + "," date ":" Mon, 5:00pm (JST) CST "," temp ":" + "," text ":" Clear "}," forecast ": [{" Code ":" + "," date ":" Mon "," Day ": High: "Max", "Low": "Sunny", "text": "},{", "code": "+", "date": "All-in-one", "Day": "Tue", "High": "A", "Low": "$", "text ":" Partly Cloudy "},{" code ":" The "," date ":" The "," Day ":" Wed "," High ":" $ "," low ":" + "," text ":" Mostly Sunny "},{" Code ":" 4 "," Date ":" Thu "," Day ":" $ "," high ":" PNs "," Low ":" Thunderstorms "," text ":"},{"," Code ":" 4 "," Date ":" 14 Jul "," Day ":" Fri "," High ":" + "," low ":" + "," text ":" Thunderstorms "},{" code ":" 4 "," Date ":" Page "," Day ":" Sat " , "High": "+", "low": "+", "text": "Thunderstorms"},{"code": "4", "Date": "Sun", "High": "+", "Low": " "," "Text": "Thunderstorms"},{"code": "+", "date": "Mon", "Day": "^", "High": "", "" "," "Text": "Partly Cloudy "},{" Code ":" "," "Date": "" "," Day ":" Tue "," High ":" The "," Low ":" + "," text ":" PartlY Cloudy "},{" Code ":" "," "Date": "", "Day": "Wed", "High": "X", "Low": "+", "text": "Partly Cloudy"}], " Description ":" <! [Cdata[\\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&LT;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 "}}}}}}'

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.