yahoo-search-py


Nameyahoo-search-py JSON
Version 0.3 PyPI version JSON
download
home_page
SummarySearch anything on Yahoo: web pages, news, videos, autocomplete, and weather.
upload_time2023-10-08 04:53:23
maintainer
docs_urlNone
author
requires_python>=3
licenseMIT License Copyright (c) 2023 JC Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords search yahoo google web news videos autocomplete weather
VCS
bugtrack_url
requirements httpx pydantic selectolax urllib3
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # yahoo-search

![GitHub issues](https://img.shields.io/github/issues/AWeirdScratcher/yahoo-search?style=for-the-badge&logo=github)
![PyPI - License](https://img.shields.io/pypi/l/yahoo-search-py?style=for-the-badge&logo=pypi&logoColor=white)

Search anything on Yahoo: web pages, news, videos, autocomplete, and weather.

```shell
$ pip install yahoo-search-py
```

## Simple API

Simple and Pythonic API with Pydantic.

Get almost every result: `also_try`, `pages`, `card`, and `related_searches`.

```python
from yahoo_search import search

result = search("chocolate")
print(result.pages[0])
```

<details>
    <summary>See Example Output</summary>

```python
PageResult(
    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.'
)
```

</details>

## Yahoo News Search

You can also search news with ease.

```python
from yahoo_search import search_news

result = search_news("taiwan")
print(result.news[0])
```

<details>
    <summary>See Example Output</summary>

```python
News(
    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...'
)
```

</details>

## Yahoo Videos Search

Search and preview online videos easily.

```python
from yahoo_search import search_videos

result = search_videos("jvke - golden hour")
print(result.videos[0].video_preview)
```

<details>
    <summary>See Example Output</summary>

```
https://tse3.mm.bing.net/th?id=OM.7UQt_nfsv8nF0A_1687237113&pid=Api
```

</details>

## Yahoo Weather

Get the weather, because why not.

```python
from yahoo_search import weather

w = weather()
print(w.celsius)
print(w.forecast["Monday"])
```

<details>
    <summary>See Example Output</summary>

```python
30
WeatherForecast(
    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%'
    )
)
```

</details>

## Yahoo Autocomplete

You can add autocompletes to your applications.

```python
from yahoo_search import autocomplete

print(autocomplete("hello"))
```

<details>
    <summary>See Example Output</summary>

```python
["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"]
```

</details>

## Examples

Below are some simple examples (and inspirations):

### Simple App — Yahoo Search

Below is a simple app that implements Yahoo searching right in your terminal.

```python
from yahoo_search import search

while True:
    query = input("search: ")
    result = search(query)

    if result.card:
        # if there's a wikipedia definition
        print("meaning", result.card.heading)
        print(result.card.text)

    for page in result.pages:
        print(page.title, page.link)
        print(page.text)

    for search in result.related_searches:
        print("related search: ", search.text)
```

## Minutely News — Yahoo News

Tired of "hourly" or "daily" news? Try minutely, and let them fill into your mind... full of news.

```python
import time

from yahoo_search import search_news

keywords = ("news", "taiwan", "usa", "chocolate")
current = 0

while True:
    result = search_news(keywords[current])
    for news in result.news:
        print(news.title)
        print(news.text)
        print()

    # loop through the keywords
    current += 1
    current %= len(keywords)

    time.sleep(60)
```

## Video Previewer API — Yahoo Videos

We love public APIs, so let's make our own.

```python
import fastapi
from yahoo_search import search_videos

app = fastapi.FastAPI()

@app.get("/preview")
def preview_video(query: str):
    # takes the URL param
    res = search_videos(query)
    return {
        "url": res.videos[0].video_preview
    }
```
## Weather Forecast App — Yahoo Weather

Nawh, I ain't gonna setup a whole Flask app for this 💀💀

Terminal app is enough.

```python
from yahoo_search import weather

res = weather()

print("Forecast")

for day, forecast in res.forecast.items():
    print(
        day,
        "-", 
        forecast.weather.text,
        forecast.precipitation.percentage,
        forecast.fahrenheit.highest,
        "/",
        forecast.fahrenheit.lowest
    )
```

## Extra: Async

If you're working with coroutines, such as Discord bots or FastAPI, you can wrap it into async.

(The below code structure is from [Stackoverflow](https://stackoverflow.com/questions/43241221/how-can-i-wrap-a-synchronous-function-in-an-async-coroutine).)

```python
import asyncio

from yahoo_search import search


async def asearch(loop, query):
    # None uses the default executor (ThreadPoolExecutor)
    await loop.run_in_executor(
        None, 
        search, 
        query
    )
```

## Models & Functions Definitions

Below are the models & functions type definitions.

<details>
    <summary>See All Models (15)</summary>

```python
class AlsoTryItem(BaseModel):
    link: str
    text: str

class PageResult(BaseModel):
    title: str
    link: str
    text: Optional[str] = None

class CardResultSource(BaseModel):
    link: str
    text: str

class CardResult(BaseModel):
    image: Optional[str] = None
    heading: Optional[str] = None
    text: Optional[str] = None
    source: Optional[CardResultSource] = None

class RelatedSearch(BaseModel):
    link: str
    text: str

class SearchResult(BaseModel):
    also_try: List[AlsoTryItem]
    pages: List[PageResult]
    card: Optional[CardResult] = None
    related_searches: List[RelatedSearch]

class News(BaseModel):
    title: str
    thumbnail: Optional[str] = None
    source: Optional[str] = None
    last_updated: Optional[str] = None
    text: Optional[str] = None

class NewsSearchResult(BaseModel):
    news: List[News]

class Video(BaseModel):
    age: Optional[str] = None
    cite: Optional[str] = None
    thumbnail: Optional[str] = None
    video_preview: Optional[str] = None
    title: str
    link: str

class VideoSearchResult(BaseModel):
    videos: List[Video]

class HighLowTemperature(BaseModel):
    highest: int
    lowest: int

class WeatherForecastInner(BaseModel):
    text: str
    icon: str

class Precipitation(BaseModel):
    icon: str
    percentage: str

class WeatherForecast(BaseModel):
    fahrenheit: HighLowTemperature
    celsius: HighLowTemperature
    weather: WeatherForecastInner
    precipitation: Precipitation

class WeatherInformation(BaseModel):
    location: str
    country: str
    time: str
    celsius: int
    fahrenheit: int
    weather: str
    weather_icon: str
    forecast: Dict[
        Literal[
            "Monday", 
            "Tuesday", 
            "Wednesday", 
            "Thursday", 
            "Friday", 
            "Saturday", 
            "Sunday"
        ],
        WeatherForecast
    ]
```

</details>

<details>
    <summary>See All Functions (4)</summary>

```python
def search(query: str) -> SearchResult: ...
def search_news(query: str) -> NewsSearchResult: ...
def weather() -> WeatherInformation: ...
def autocomplete(query: str) -> List[str]: ...
```

</details>

---

No, this time I'm not bored. I just want to practice webscraping.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "yahoo-search-py",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3",
    "maintainer_email": "",
    "keywords": "search,yahoo,google,web,news,videos,autocomplete,weather",
    "author": "",
    "author_email": "AWeirdDev <aweirdscratcher@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/e1/83/fc0a9ebd324d275b6ae33762b2bf978d1c7e0b530eeffc031a5a03ac92f4/yahoo-search-py-0.3.tar.gz",
    "platform": null,
    "description": "# yahoo-search\n\n![GitHub issues](https://img.shields.io/github/issues/AWeirdScratcher/yahoo-search?style=for-the-badge&logo=github)\n![PyPI - License](https://img.shields.io/pypi/l/yahoo-search-py?style=for-the-badge&logo=pypi&logoColor=white)\n\nSearch anything on Yahoo: web pages, news, videos, autocomplete, and weather.\n\n```shell\n$ pip install yahoo-search-py\n```\n\n## Simple API\n\nSimple and Pythonic API with Pydantic.\n\nGet almost every result: `also_try`, `pages`, `card`, and `related_searches`.\n\n```python\nfrom yahoo_search import search\n\nresult = search(\"chocolate\")\nprint(result.pages[0])\n```\n\n<details>\n    <summary>See Example Output</summary>\n\n```python\nPageResult(\n    title='Chocolate - Wikipedia',\n    link='https://en.wikipedia.org/wiki/Chocolate',\n    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.'\n)\n```\n\n</details>\n\n## Yahoo News Search\n\nYou can also search news with ease.\n\n```python\nfrom yahoo_search import search_news\n\nresult = search_news(\"taiwan\")\nprint(result.news[0])\n```\n\n<details>\n    <summary>See Example Output</summary>\n\n```python\nNews(\n    title='How to take the Taiwan Design Expo personality test that\\'s trending on IG Stories',\n    thumbnail='https://s.yimg.com/fz/api/res/1.2/(...)',\n    source='Lifestyle Asia via Yahoo Style Singapore',\n    text='If you\\'ve always wanted to know your personality type beyond the conventional MBTI variants, it\\'s...'\n)\n```\n\n</details>\n\n## Yahoo Videos Search\n\nSearch and preview online videos easily.\n\n```python\nfrom yahoo_search import search_videos\n\nresult = search_videos(\"jvke - golden hour\")\nprint(result.videos[0].video_preview)\n```\n\n<details>\n    <summary>See Example Output</summary>\n\n```\nhttps://tse3.mm.bing.net/th?id=OM.7UQt_nfsv8nF0A_1687237113&pid=Api\n```\n\n</details>\n\n## Yahoo Weather\n\nGet the weather, because why not.\n\n```python\nfrom yahoo_search import weather\n\nw = weather()\nprint(w.celsius)\nprint(w.forecast[\"Monday\"])\n```\n\n<details>\n    <summary>See Example Output</summary>\n\n```python\n30\nWeatherForecast(\n    fahrenheit=HighLowTemperature(\n        highest=92,\n        lowest=78\n    ),\n    celsius=HighLowTemperature(\n        highest=34,\n        lowest=26\n    ),\n    weather=WeatherForecastInner(\n        text='Haze',\n        icon='https://s.yimg.com/g/images/spaceball.gif'\n    ),\n    precipitation=Precipitation(\n        icon='https://s.yimg.com/g/images/spaceball.gif',\n        percentage='0%'\n    )\n)\n```\n\n</details>\n\n## Yahoo Autocomplete\n\nYou can add autocompletes to your applications.\n\n```python\nfrom yahoo_search import autocomplete\n\nprint(autocomplete(\"hello\"))\n```\n\n<details>\n    <summary>See Example Output</summary>\n\n```python\n[\"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\"]\n```\n\n</details>\n\n## Examples\n\nBelow are some simple examples (and inspirations):\n\n### Simple App \u2014 Yahoo Search\n\nBelow is a simple app that implements Yahoo searching right in your terminal.\n\n```python\nfrom yahoo_search import search\n\nwhile True:\n    query = input(\"search: \")\n    result = search(query)\n\n    if result.card:\n        # if there's a wikipedia definition\n        print(\"meaning\", result.card.heading)\n        print(result.card.text)\n\n    for page in result.pages:\n        print(page.title, page.link)\n        print(page.text)\n\n    for search in result.related_searches:\n        print(\"related search: \", search.text)\n```\n\n## Minutely News \u2014 Yahoo News\n\nTired of \"hourly\" or \"daily\" news? Try minutely, and let them fill into your mind... full of news.\n\n```python\nimport time\n\nfrom yahoo_search import search_news\n\nkeywords = (\"news\", \"taiwan\", \"usa\", \"chocolate\")\ncurrent = 0\n\nwhile True:\n    result = search_news(keywords[current])\n    for news in result.news:\n        print(news.title)\n        print(news.text)\n        print()\n\n    # loop through the keywords\n    current += 1\n    current %= len(keywords)\n\n    time.sleep(60)\n```\n\n## Video Previewer API \u2014 Yahoo Videos\n\nWe love public APIs, so let's make our own.\n\n```python\nimport fastapi\nfrom yahoo_search import search_videos\n\napp = fastapi.FastAPI()\n\n@app.get(\"/preview\")\ndef preview_video(query: str):\n    # takes the URL param\n    res = search_videos(query)\n    return {\n        \"url\": res.videos[0].video_preview\n    }\n```\n## Weather Forecast App \u2014 Yahoo Weather\n\nNawh, I ain't gonna setup a whole Flask app for this \ud83d\udc80\ud83d\udc80\n\nTerminal app is enough.\n\n```python\nfrom yahoo_search import weather\n\nres = weather()\n\nprint(\"Forecast\")\n\nfor day, forecast in res.forecast.items():\n    print(\n        day,\n        \"-\", \n        forecast.weather.text,\n        forecast.precipitation.percentage,\n        forecast.fahrenheit.highest,\n        \"/\",\n        forecast.fahrenheit.lowest\n    )\n```\n\n## Extra: Async\n\nIf you're working with coroutines, such as Discord bots or FastAPI, you can wrap it into async.\n\n(The below code structure is from [Stackoverflow](https://stackoverflow.com/questions/43241221/how-can-i-wrap-a-synchronous-function-in-an-async-coroutine).)\n\n```python\nimport asyncio\n\nfrom yahoo_search import search\n\n\nasync def asearch(loop, query):\n    # None uses the default executor (ThreadPoolExecutor)\n    await loop.run_in_executor(\n        None, \n        search, \n        query\n    )\n```\n\n## Models & Functions Definitions\n\nBelow are the models & functions type definitions.\n\n<details>\n    <summary>See All Models (15)</summary>\n\n```python\nclass AlsoTryItem(BaseModel):\n    link: str\n    text: str\n\nclass PageResult(BaseModel):\n    title: str\n    link: str\n    text: Optional[str] = None\n\nclass CardResultSource(BaseModel):\n    link: str\n    text: str\n\nclass CardResult(BaseModel):\n    image: Optional[str] = None\n    heading: Optional[str] = None\n    text: Optional[str] = None\n    source: Optional[CardResultSource] = None\n\nclass RelatedSearch(BaseModel):\n    link: str\n    text: str\n\nclass SearchResult(BaseModel):\n    also_try: List[AlsoTryItem]\n    pages: List[PageResult]\n    card: Optional[CardResult] = None\n    related_searches: List[RelatedSearch]\n\nclass News(BaseModel):\n    title: str\n    thumbnail: Optional[str] = None\n    source: Optional[str] = None\n    last_updated: Optional[str] = None\n    text: Optional[str] = None\n\nclass NewsSearchResult(BaseModel):\n    news: List[News]\n\nclass Video(BaseModel):\n    age: Optional[str] = None\n    cite: Optional[str] = None\n    thumbnail: Optional[str] = None\n    video_preview: Optional[str] = None\n    title: str\n    link: str\n\nclass VideoSearchResult(BaseModel):\n    videos: List[Video]\n\nclass HighLowTemperature(BaseModel):\n    highest: int\n    lowest: int\n\nclass WeatherForecastInner(BaseModel):\n    text: str\n    icon: str\n\nclass Precipitation(BaseModel):\n    icon: str\n    percentage: str\n\nclass WeatherForecast(BaseModel):\n    fahrenheit: HighLowTemperature\n    celsius: HighLowTemperature\n    weather: WeatherForecastInner\n    precipitation: Precipitation\n\nclass WeatherInformation(BaseModel):\n    location: str\n    country: str\n    time: str\n    celsius: int\n    fahrenheit: int\n    weather: str\n    weather_icon: str\n    forecast: Dict[\n        Literal[\n            \"Monday\", \n            \"Tuesday\", \n            \"Wednesday\", \n            \"Thursday\", \n            \"Friday\", \n            \"Saturday\", \n            \"Sunday\"\n        ],\n        WeatherForecast\n    ]\n```\n\n</details>\n\n<details>\n    <summary>See All Functions (4)</summary>\n\n```python\ndef search(query: str) -> SearchResult: ...\ndef search_news(query: str) -> NewsSearchResult: ...\ndef weather() -> WeatherInformation: ...\ndef autocomplete(query: str) -> List[str]: ...\n```\n\n</details>\n\n---\n\nNo, this time I'm not bored. I just want to practice webscraping.\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 JC  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Search anything on Yahoo: web pages, news, videos, autocomplete, and weather.",
    "version": "0.3",
    "project_urls": {
        "Bug Tracker": "https://github.com/AWeirdScratcher/yahoo-search/issues",
        "Homepage": "https://github.com/AWeirdScratcher/yahoo-search"
    },
    "split_keywords": [
        "search",
        "yahoo",
        "google",
        "web",
        "news",
        "videos",
        "autocomplete",
        "weather"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e183fc0a9ebd324d275b6ae33762b2bf978d1c7e0b530eeffc031a5a03ac92f4",
                "md5": "be8b4d2cf7d3ce1abb192077307978a6",
                "sha256": "01b5ca2ff117e9e3aca3754c233e49272793cb013de7652f70be48bcddb31772"
            },
            "downloads": -1,
            "filename": "yahoo-search-py-0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "be8b4d2cf7d3ce1abb192077307978a6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3",
            "size": 11407,
            "upload_time": "2023-10-08T04:53:23",
            "upload_time_iso_8601": "2023-10-08T04:53:23.142009Z",
            "url": "https://files.pythonhosted.org/packages/e1/83/fc0a9ebd324d275b6ae33762b2bf978d1c7e0b530eeffc031a5a03ac92f4/yahoo-search-py-0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-08 04:53:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "AWeirdScratcher",
    "github_project": "yahoo-search",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "httpx",
            "specs": []
        },
        {
            "name": "pydantic",
            "specs": []
        },
        {
            "name": "selectolax",
            "specs": []
        },
        {
            "name": "urllib3",
            "specs": []
        }
    ],
    "lcname": "yahoo-search-py"
}
        
Elapsed time: 1.99166s