sneakpeek


Namesneakpeek JSON
Version 0.9.0 PyPI version JSON
download
home_pagehttps://github.com/codingcoffee/sneakpeek
SummaryA python module to generate link previews.
upload_time2024-04-16 13:53:57
maintainerAmeya Shenoy
docs_urlNone
authorAmeya Shenoy
requires_python<4.0,>=3.8
licenseMIT
keywords open-graph-protocol ogp twitter twitter-cards python schema link-preview
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
<div align="center">
  <h1>
    SneakPeek
  </h1>
  <h4>A python module and a minimalistic server to generate link previews.</h4>
</div>

[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
[![Downloads](https://pepy.tech/badge/sneakpeek)](https://pepy.tech/project/sneakpeek)
[![PyPI](https://img.shields.io/pypi/v/sneakpeek)](https://pypi.org/project/sneakpeek)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/sneakpeek)](https://pypi.org/project/sneakpeek)
[![test-ci](https://img.shields.io/github/workflow/status/codingcoffee/sneakpeek/test-ci)](https://github.com/codingCoffee/sneakpeek/actions)
[![Docker Pulls](https://img.shields.io/docker/pulls/codingcoffee/sneakpeek)](https://hub.docker.com/r/codingcoffee/sneakpeek)
[![Docker Image Size (tag)](https://img.shields.io/docker/image-size/codingcoffee/sneakpeek/latest)](https://hub.docker.com/r/codingcoffee/sneakpeek)

## What is supported

- Any page which supports [Open Graph Protocol](https://ogp.me) (which most sane websites do)
- Special handling for sites like
  - [Twitter](https://twitter.com) (requires a twitter [API key](https://developer.twitter.com/))


## Installation

Run the following to install

```sh
pip install sneakpeek
```


## Usage as a Python Module

### From a URL

```sh
>>> import sneakpeek
>>> from pprint import pprint

>>> link = sneakpeek.SneakPeek("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
>>> link.fetch()
>>> link.is_valid()
True
>>> pprint(link)
{'description': 'The official video for “Never Gonna Give You Up” by Rick '
                'AstleyTaken from the album ‘Whenever You Need Somebody’ – '
                'deluxe 2CD and digital deluxe out 6th May ...',
 'domain': 'www.youtube.com',
 'image': 'https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg',
 'image:height': '720',
 'image:width': '1280',
 'scrape': False,
 'site_name': 'YouTube',
 'title': 'Rick Astley - Never Gonna Give You Up (Official Music Video)',
 'type': 'video.other',
 'url': 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
 'video:height': '720',
 'video:secure_url': 'https://www.youtube.com/embed/dQw4w9WgXcQ',
 'video:tag': 'never gonna give you up karaoke',
 'video:type': 'text/html',
 'video:url': 'https://www.youtube.com/embed/dQw4w9WgXcQ',
 'video:width': '1280'}

>>> link = sneakpeek.SneakPeek(url="https://codingcoffee.dev")
>>> link.fetch()
>>> pprint(link)
{'description': 'A generalist with multi faceted interests and extensive '
                'experience with DevOps, System Design and Full Stack '
                'Development. I like blogging about things which interest me, '
                'have a niche for optimizing and customizing things to the '
                'very last detail, this includes my text editor and operating '
                'system alike.',
 'domain': 'codingcoffee.dev',
 'image': 'https://www.gravatar.com/avatar/7ecdc5e1441ecd501faaf42a6ab9d6c0?s=200',
 'scrape': False,
 'title': 'Ameya Shenoy',
 'type': 'website',
 'url': 'https://codingcoffee.dev'}
```

Use `scrape=True` to fetch data using scraping instead of relying on open graph tags

```sh
>>> link = sneakpeek.SneakPeek(url="https://news.ycombinator.com/item?id=23812063", scrape=True)
>>> link.fetch()
>>> pprint(link)
{'description': '',
 'domain': 'news.ycombinator.com',
 'image': 'y18.gif',
 'scrape': True,
 'title': 'WireGuard as VPN Server on Kubernetes with AdBlocking | Hacker News',
 'type': 'other',
 'url': 'https://news.ycombinator.com/item?id=23812063'}
 ```

### From HTML

```
>>> HTML = """
... <html xmlns:og="http://ogp.me/ns">
... <head>
... <title>The Rock (1996)</title>
... <meta property="og:title" content="The Rock" />
... <meta property="og:description" content="The Rock: Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer. A mild-mannered chemist and an ex-con must lead the counterstrike when a rogue group of military men, led by a renegade general, threaten a nerve gas attack from Alcatraz against San Francisco.">
... <meta property="og:type" content="movie" />
... <meta property="og:url" content="http://www.imdb.com/title/tt0117500/" />
... <meta property="og:image" content="https://m.media-amazon.com/images/M/MV5BZDJjOTE0N2EtMmRlZS00NzU0LWE0ZWQtM2Q3MWMxNjcwZjBhXkEyXkFqcGdeQXVyNDk3NzU2MTQ@._V1_FMjpg_UX1000_.jpg">
... </head>
... </html>
... """
>>> movie = sneakpeek.SneakPeek(html=HTML)
>>> movie.is_valid()
True
>>> pprint(movie)
{'description': 'The Rock: Directed by Michael Bay. With Sean Connery, Nicolas '
                'Cage, Ed Harris, John Spencer. A mild-mannered chemist and an '
                'ex-con must lead the counterstrike when a rogue group of '
                'military men, led by a renegade general, threaten a nerve gas '
                'attack from Alcatraz against San Francisco.',
 'domain': None,
 'image': 'https://m.media-amazon.com/images/M/MV5BZDJjOTE0N2EtMmRlZS00NzU0LWE0ZWQtM2Q3MWMxNjcwZjBhXkEyXkFqcGdeQXVyNDk3NzU2MTQ@._V1_FMjpg_UX1000_.jpg',
 'scrape': False,
 'title': 'The Rock',
 'type': 'movie',
 'url': 'http://www.imdb.com/title/tt0117500/'}
```


## Usage as a Server

A simple server using FastAPI and uvicorn is used to serve the requests.

```sh
sneekpeek serve
```

You can view the docs at http://localhost:9000/docs


## Usage as a CLI

```
sneakpeek preview --url "https://github.com/codingcoffee/" | jq
{
  "domain": "github.com",
  "scrape": false,
  "url": "https://github.com/codingCoffee",
  "title": "codingCoffee - Overview",
  "type": "profile",
  "image": "https://avatars.githubusercontent.com/u/13611153?v=4?s=400",
  "description": "Automate anything and everything 🙋‍♂️. codingCoffee has 68 repositories available. Follow their code on GitHub.",
  "error": null,
  "image:alt": "Automate anything and everything 🙋‍♂️. codingCoffee has 68 repositories available. Follow their code on GitHub.",
  "site_name": "GitHub"
}
```

## Docker

### As a Server

```sh
docker run -it --rm -p 9000:9000 codingcoffee/sneakpeek -- serve --host 0.0.0.0
```

### As a CLI

```sh
docker run -it --rm -p 9000:9000 codingcoffee/sneakpeek -- preview --url "https://github.com/codingcoffee"
```


## Configuration

### Twitter

- Sign up for a developer account on twitter [here](https://developer.twitter.com/)
- Create an app
- Add the following variables as ENV vars


```
TWITTER_CONSUMER_KEY="sample"
TWITTER_CONSUMER_SECRET="sample"
TWITTER_ACCESS_TOKEN="sample"
TWITTER_ACCESS_TOKEN_SECRET="sample"
```


## Development

```
pip install -U poetry
git clone https://github.com/codingcoffee/sneakpeek
cd sneakpeek
poetry install
```


## Running Tests

```sh
poetry run pytest
```

- Tested Websites
  - [x] [YouTube](https://youtube.com)
  - [x] [GitHub](https://github.com)
  - [x] [LinkedIN](https://linkedin.com)
  - [x] [Reddit](https://reddit.com)
  - [x] [StackOverflow](https://stackoverflow.com)
  - [x] [Business Insider](https://www.businessinsider.in)
  - [x] [HackerNews](https://news.ycombinator.com/)
  - [x] [Twitter](https://twitter.com)


## TODO

- [ ] [Instagram](https://instagram.com) (using [instagram-scraper](https://github.com/arc298/instagram-scraper))
- [ ] [Facebook](https://facebook.com)
- [ ] https://joinfishbowl.com/post_v3ibj1p63t
- [ ] CI/CD for publishing to PyPi


## Contribution

Have better suggestions to optimize the server image? Found some typos? Need special handling for a new website? Found a bug? Go ahead and create an [Issue](https://github.com/codingcoffee/sneakpeek/issues)! Contributions of any kind welcome!

Want to work on a TODO? Its always a good idea to talk about what are going to do before you actually start it, so frustration can be avoided.

Some rules for coding:

- Use the code style the project uses
- For each feature, make a seperate branch, so it can be reviewed separately
- Use commits with a good description, so everyone can see what you did


## License

The code in this repository has been released under the [MIT License](https://opensource.org/licenses/MIT)


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/codingcoffee/sneakpeek",
    "name": "sneakpeek",
    "maintainer": "Ameya Shenoy",
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": "shenoy.ameya@gmail.com",
    "keywords": "open-graph-protocol, ogp, twitter, twitter-cards, python, schema, link-preview",
    "author": "Ameya Shenoy",
    "author_email": "shenoy.ameya@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/cc/c1/fa21c93488d3b6a5274379f867c12f0d5291bc77520ad0f3db35d3a2b944/sneakpeek-0.9.0.tar.gz",
    "platform": null,
    "description": "\n<div align=\"center\">\n  <h1>\n    SneakPeek\n  </h1>\n  <h4>A python module and a minimalistic server to generate link previews.</h4>\n</div>\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)\n[![Downloads](https://pepy.tech/badge/sneakpeek)](https://pepy.tech/project/sneakpeek)\n[![PyPI](https://img.shields.io/pypi/v/sneakpeek)](https://pypi.org/project/sneakpeek)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/sneakpeek)](https://pypi.org/project/sneakpeek)\n[![test-ci](https://img.shields.io/github/workflow/status/codingcoffee/sneakpeek/test-ci)](https://github.com/codingCoffee/sneakpeek/actions)\n[![Docker Pulls](https://img.shields.io/docker/pulls/codingcoffee/sneakpeek)](https://hub.docker.com/r/codingcoffee/sneakpeek)\n[![Docker Image Size (tag)](https://img.shields.io/docker/image-size/codingcoffee/sneakpeek/latest)](https://hub.docker.com/r/codingcoffee/sneakpeek)\n\n## What is supported\n\n- Any page which supports [Open Graph Protocol](https://ogp.me) (which most sane websites do)\n- Special handling for sites like\n  - [Twitter](https://twitter.com) (requires a twitter [API key](https://developer.twitter.com/))\n\n\n## Installation\n\nRun the following to install\n\n```sh\npip install sneakpeek\n```\n\n\n## Usage as a Python Module\n\n### From a URL\n\n```sh\n>>> import sneakpeek\n>>> from pprint import pprint\n\n>>> link = sneakpeek.SneakPeek(\"https://www.youtube.com/watch?v=dQw4w9WgXcQ\")\n>>> link.fetch()\n>>> link.is_valid()\nTrue\n>>> pprint(link)\n{'description': 'The official video for \u201cNever Gonna Give You Up\u201d by Rick '\n                'AstleyTaken from the album \u2018Whenever You Need Somebody\u2019 \u2013 '\n                'deluxe 2CD and digital deluxe out 6th May ...',\n 'domain': 'www.youtube.com',\n 'image': 'https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg',\n 'image:height': '720',\n 'image:width': '1280',\n 'scrape': False,\n 'site_name': 'YouTube',\n 'title': 'Rick Astley - Never Gonna Give You Up (Official Music Video)',\n 'type': 'video.other',\n 'url': 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',\n 'video:height': '720',\n 'video:secure_url': 'https://www.youtube.com/embed/dQw4w9WgXcQ',\n 'video:tag': 'never gonna give you up karaoke',\n 'video:type': 'text/html',\n 'video:url': 'https://www.youtube.com/embed/dQw4w9WgXcQ',\n 'video:width': '1280'}\n\n>>> link = sneakpeek.SneakPeek(url=\"https://codingcoffee.dev\")\n>>> link.fetch()\n>>> pprint(link)\n{'description': 'A generalist with multi faceted interests and extensive '\n                'experience with DevOps, System Design and Full Stack '\n                'Development. I like blogging about things which interest me, '\n                'have a niche for optimizing and customizing things to the '\n                'very last detail, this includes my text editor and operating '\n                'system alike.',\n 'domain': 'codingcoffee.dev',\n 'image': 'https://www.gravatar.com/avatar/7ecdc5e1441ecd501faaf42a6ab9d6c0?s=200',\n 'scrape': False,\n 'title': 'Ameya Shenoy',\n 'type': 'website',\n 'url': 'https://codingcoffee.dev'}\n```\n\nUse `scrape=True` to fetch data using scraping instead of relying on open graph tags\n\n```sh\n>>> link = sneakpeek.SneakPeek(url=\"https://news.ycombinator.com/item?id=23812063\", scrape=True)\n>>> link.fetch()\n>>> pprint(link)\n{'description': '',\n 'domain': 'news.ycombinator.com',\n 'image': 'y18.gif',\n 'scrape': True,\n 'title': 'WireGuard as VPN Server on Kubernetes with AdBlocking | Hacker News',\n 'type': 'other',\n 'url': 'https://news.ycombinator.com/item?id=23812063'}\n ```\n\n### From HTML\n\n```\n>>> HTML = \"\"\"\n... <html xmlns:og=\"http://ogp.me/ns\">\n... <head>\n... <title>The Rock (1996)</title>\n... <meta property=\"og:title\" content=\"The Rock\" />\n... <meta property=\"og:description\" content=\"The Rock: Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer. A mild-mannered chemist and an ex-con must lead the counterstrike when a rogue group of military men, led by a renegade general, threaten a nerve gas attack from Alcatraz against San Francisco.\">\n... <meta property=\"og:type\" content=\"movie\" />\n... <meta property=\"og:url\" content=\"http://www.imdb.com/title/tt0117500/\" />\n... <meta property=\"og:image\" content=\"https://m.media-amazon.com/images/M/MV5BZDJjOTE0N2EtMmRlZS00NzU0LWE0ZWQtM2Q3MWMxNjcwZjBhXkEyXkFqcGdeQXVyNDk3NzU2MTQ@._V1_FMjpg_UX1000_.jpg\">\n... </head>\n... </html>\n... \"\"\"\n>>> movie = sneakpeek.SneakPeek(html=HTML)\n>>> movie.is_valid()\nTrue\n>>> pprint(movie)\n{'description': 'The Rock: Directed by Michael Bay. With Sean Connery, Nicolas '\n                'Cage, Ed Harris, John Spencer. A mild-mannered chemist and an '\n                'ex-con must lead the counterstrike when a rogue group of '\n                'military men, led by a renegade general, threaten a nerve gas '\n                'attack from Alcatraz against San Francisco.',\n 'domain': None,\n 'image': 'https://m.media-amazon.com/images/M/MV5BZDJjOTE0N2EtMmRlZS00NzU0LWE0ZWQtM2Q3MWMxNjcwZjBhXkEyXkFqcGdeQXVyNDk3NzU2MTQ@._V1_FMjpg_UX1000_.jpg',\n 'scrape': False,\n 'title': 'The Rock',\n 'type': 'movie',\n 'url': 'http://www.imdb.com/title/tt0117500/'}\n```\n\n\n## Usage as a Server\n\nA simple server using FastAPI and uvicorn is used to serve the requests.\n\n```sh\nsneekpeek serve\n```\n\nYou can view the docs at http://localhost:9000/docs\n\n\n## Usage as a CLI\n\n```\nsneakpeek preview --url \"https://github.com/codingcoffee/\" | jq\n{\n  \"domain\": \"github.com\",\n  \"scrape\": false,\n  \"url\": \"https://github.com/codingCoffee\",\n  \"title\": \"codingCoffee - Overview\",\n  \"type\": \"profile\",\n  \"image\": \"https://avatars.githubusercontent.com/u/13611153?v=4?s=400\",\n  \"description\": \"Automate anything and everything \ud83d\ude4b\u200d\u2642\ufe0f. codingCoffee has 68 repositories available. Follow their code on GitHub.\",\n  \"error\": null,\n  \"image:alt\": \"Automate anything and everything \ud83d\ude4b\u200d\u2642\ufe0f. codingCoffee has 68 repositories available. Follow their code on GitHub.\",\n  \"site_name\": \"GitHub\"\n}\n```\n\n## Docker\n\n### As a Server\n\n```sh\ndocker run -it --rm -p 9000:9000 codingcoffee/sneakpeek -- serve --host 0.0.0.0\n```\n\n### As a CLI\n\n```sh\ndocker run -it --rm -p 9000:9000 codingcoffee/sneakpeek -- preview --url \"https://github.com/codingcoffee\"\n```\n\n\n## Configuration\n\n### Twitter\n\n- Sign up for a developer account on twitter [here](https://developer.twitter.com/)\n- Create an app\n- Add the following variables as ENV vars\n\n\n```\nTWITTER_CONSUMER_KEY=\"sample\"\nTWITTER_CONSUMER_SECRET=\"sample\"\nTWITTER_ACCESS_TOKEN=\"sample\"\nTWITTER_ACCESS_TOKEN_SECRET=\"sample\"\n```\n\n\n## Development\n\n```\npip install -U poetry\ngit clone https://github.com/codingcoffee/sneakpeek\ncd sneakpeek\npoetry install\n```\n\n\n## Running Tests\n\n```sh\npoetry run pytest\n```\n\n- Tested Websites\n  - [x] [YouTube](https://youtube.com)\n  - [x] [GitHub](https://github.com)\n  - [x] [LinkedIN](https://linkedin.com)\n  - [x] [Reddit](https://reddit.com)\n  - [x] [StackOverflow](https://stackoverflow.com)\n  - [x] [Business Insider](https://www.businessinsider.in)\n  - [x] [HackerNews](https://news.ycombinator.com/)\n  - [x] [Twitter](https://twitter.com)\n\n\n## TODO\n\n- [ ] [Instagram](https://instagram.com) (using [instagram-scraper](https://github.com/arc298/instagram-scraper))\n- [ ] [Facebook](https://facebook.com)\n- [ ] https://joinfishbowl.com/post_v3ibj1p63t\n- [ ] CI/CD for publishing to PyPi\n\n\n## Contribution\n\nHave better suggestions to optimize the server image? Found some typos? Need special handling for a new website? Found a bug? Go ahead and create an [Issue](https://github.com/codingcoffee/sneakpeek/issues)! Contributions of any kind welcome!\n\nWant to work on a TODO? Its always a good idea to talk about what are going to do before you actually start it, so frustration can be avoided.\n\nSome rules for coding:\n\n- Use the code style the project uses\n- For each feature, make a seperate branch, so it can be reviewed separately\n- Use commits with a good description, so everyone can see what you did\n\n\n## License\n\nThe code in this repository has been released under the [MIT License](https://opensource.org/licenses/MIT)\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A python module to generate link previews.",
    "version": "0.9.0",
    "project_urls": {
        "Documentation": "https://github.com/codingcoffee/sneakpeek",
        "Homepage": "https://github.com/codingcoffee/sneakpeek",
        "Repository": "https://github.com/codingcoffee/sneakpeek"
    },
    "split_keywords": [
        "open-graph-protocol",
        " ogp",
        " twitter",
        " twitter-cards",
        " python",
        " schema",
        " link-preview"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9a68225b950593b5d947d0a5b28655e1b98d4b6e3075cbf7e74877c90ce62bae",
                "md5": "306120a1bdcf14737dedaeac764173a4",
                "sha256": "02202dabb3cb66eefe7b412ea7c9e99dac003a8f20ab5559584f4c0c2c7655d5"
            },
            "downloads": -1,
            "filename": "sneakpeek-0.9.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "306120a1bdcf14737dedaeac764173a4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 8840,
            "upload_time": "2024-04-16T13:53:55",
            "upload_time_iso_8601": "2024-04-16T13:53:55.824068Z",
            "url": "https://files.pythonhosted.org/packages/9a/68/225b950593b5d947d0a5b28655e1b98d4b6e3075cbf7e74877c90ce62bae/sneakpeek-0.9.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ccc1fa21c93488d3b6a5274379f867c12f0d5291bc77520ad0f3db35d3a2b944",
                "md5": "594d3f172f404902d03997a8dc997d11",
                "sha256": "eb02c08a01084acb61566c5f7e3992b234ff8f7476a2bdcd9c9a286940e7142f"
            },
            "downloads": -1,
            "filename": "sneakpeek-0.9.0.tar.gz",
            "has_sig": false,
            "md5_digest": "594d3f172f404902d03997a8dc997d11",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 7797,
            "upload_time": "2024-04-16T13:53:57",
            "upload_time_iso_8601": "2024-04-16T13:53:57.734827Z",
            "url": "https://files.pythonhosted.org/packages/cc/c1/fa21c93488d3b6a5274379f867c12f0d5291bc77520ad0f3db35d3a2b944/sneakpeek-0.9.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-16 13:53:57",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "codingcoffee",
    "github_project": "sneakpeek",
    "github_not_found": true,
    "lcname": "sneakpeek"
}
        
Elapsed time: 0.37615s