Package: yahoo-search-py
yahoo-searchSearch anything on Yahoo: web pages, news, videos, autocomplete, and weather.$pipinstallyahoo-search-pySimple APISimple and Pythonic API with Pydantic.Get almost every result:also_try,pages,card, andrelated_searches.fromyahoo_searchimportsearchresult=search("chocolate")print(result.pages[0])See Example OutputPageResult(title='Chocolate - Wikipedia',link='https://en.wikipedia.org/wiki/Chocolate',text='A "cocoa product" is defined as a food product that is sourced from cocoa beans and contains "cocoa nibs, cocoa liquor, cocoa mass, unsweetened chocolate, bitter chocolate, chocolate liquor, cocoa, low-fat cocoa, cocoa powder, or low-fat cocoa powder". Conching. Main article: Conching.')Yahoo News SearchYou can also search news with ease.fromyahoo_searchimportsearch_newsresult=search_news("taiwan")print(result.news[0])See Example OutputNews(title='How to take the Taiwan Design Expo personality test that\'s trending on IG Stories',thumbnail='https://s.yimg.com/fz/api/res/1.2/(...)',source='Lifestyle Asia via Yahoo Style Singapore',text='If you\'ve always wanted to know your personality type beyond the conventional MBTI variants, it\'s...')Yahoo Videos SearchSearch and preview online videos easily.fromyahoo_searchimportsearch_videosresult=search_videos("jvke - golden hour")print(result.videos[0].video_preview)See Example Outputhttps://tse3.mm.bing.net/th?id=OM.7UQt_nfsv8nF0A_1687237113&pid=ApiYahoo WeatherGet the weather, because why not.fromyahoo_searchimportweatherw=weather()print(w.celsius)print(w.forecast["Monday"])See Example Output30WeatherForecast(fahrenheit=HighLowTemperature(highest=92,lowest=78),celsius=HighLowTemperature(highest=34,lowest=26),weather=WeatherForecastInner(text='Haze',icon='https://s.yimg.com/g/images/spaceball.gif'),precipitation=Precipitation(icon='https://s.yimg.com/g/images/spaceball.gif',percentage='0%'))Yahoo AutocompleteYou can add autocompletes to your applications.fromyahoo_searchimportautocompleteprint(autocomplete("hello"))See Example Output["hello fresh","hello kitty","hello molly","hello neighbor","hello october","hello fresh log in to my account","hello october images","hello kitty coloring pages","hello magazine","hellosign"]ExamplesBelow are some simple examples (and inspirations):Simple App — Yahoo SearchBelow is a simple app that implements Yahoo searching right in your terminal.fromyahoo_searchimportsearchwhileTrue:query=input("search: ")result=search(query)ifresult.card:# if there's a wikipedia definitionprint("meaning",result.card.heading)print(result.card.text)forpageinresult.pages:print(page.title,page.link)print(page.text)forsearchinresult.related_searches:print("related search: ",search.text)Minutely News — Yahoo NewsTired of "hourly" or "daily" news? Try minutely, and let them fill into your mind... full of news.importtimefromyahoo_searchimportsearch_newskeywords=("news","taiwan","usa","chocolate")current=0whileTrue:result=search_news(keywords[current])fornewsinresult.news:print(news.title)print(news.text)print()# loop through the keywordscurrent+=1current%=len(keywords)time.sleep(60)Video Previewer API — Yahoo VideosWe love public APIs, so let's make our own.importfastapifromyahoo_searchimportsearch_videosapp=fastapi.FastAPI()@app.get("/preview")defpreview_video(query:str):# takes the URL paramres=search_videos(query)return{"url":res.videos[0].video_preview}Weather Forecast App — Yahoo WeatherNawh, I ain't gonna setup a whole Flask app for this 💀💀Terminal app is enough.fromyahoo_searchimportweatherres=weather()print("Forecast")forday,forecastinres.forecast.items():print(day,"-",forecast.weather.text,forecast.precipitation.percentage,forecast.fahrenheit.highest,"/",forecast.fahrenheit.lowest)Extra: AsyncIf you're working with coroutines, such as Discord bots or FastAPI, you can wrap it into async.(The below code structure is fromStackoverflow.)importasynciofromyahoo_searchimportsearchasyncdefasearch(loop,query):# None uses the default executor (ThreadPoolExecutor)awaitloop.run_in_executor(None,search,query)Models & Functions DefinitionsBelow are the models & functions type definitions.See All Models (15)classAlsoTryItem(BaseModel):link:strtext:strclassPageResult(BaseModel):title:strlink:strtext:Optional[str]=NoneclassCardResultSource(BaseModel):link:strtext:strclassCardResult(BaseModel):image:Optional[str]=Noneheading:Optional[str]=Nonetext:Optional[str]=Nonesource:Optional[CardResultSource]=NoneclassRelatedSearch(BaseModel):link:strtext:strclassSearchResult(BaseModel):also_try:List[AlsoTryItem]pages:List[PageResult]card:Optional[CardResult]=Nonerelated_searches:List[RelatedSearch]classNews(BaseModel):title:strthumbnail:Optional[str]=Nonesource:Optional[str]=Nonelast_updated:Optional[str]=Nonetext:Optional[str]=NoneclassNewsSearchResult(BaseModel):news:List[News]classVideo(BaseModel):age:Optional[str]=Nonecite:Optional[str]=Nonethumbnail:Optional[str]=Nonevideo_preview:Optional[str]=Nonetitle:strlink:strclassVideoSearchResult(BaseModel):videos:List[Video]classHighLowTemperature(BaseModel):highest:intlowest:intclassWeatherForecastInner(BaseModel):text:stricon:strclassPrecipitation(BaseModel):icon:strpercentage:strclassWeatherForecast(BaseModel):fahrenheit:HighLowTemperaturecelsius:HighLowTemperatureweather:WeatherForecastInnerprecipitation:PrecipitationclassWeatherInformation(BaseModel):location:strcountry:strtime:strcelsius:intfahrenheit:intweather:strweather_icon:strforecast:Dict[Literal["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],WeatherForecast]See All Functions (4)defsearch(query:str)->SearchResult:...defsearch_news(query:str)->NewsSearchResult:...defweather()->WeatherInformation:...defautocomplete(query:str)->List[str]:...No, this time I'm not bored. I just want to practice webscraping.