Giter Club home page Giter Club logo

python-ninegag's Introduction

python-ninegag

https://travis-ci.org/sashgorokhov/python-ninegag.svg?branch=master

Python library to get stuff from 9gag.com

Installation

Via pip:

pip install python-ninegag

Usage

pyninegag.get_sections()

Returns dict of 9gag sections, where keys are capitalized sections names, and values are their urls.

Example output:

{'Fresh': 'http://9gag.com/fresh',
'Cute Animals': 'http://9gag.com/cute',
'Comic': 'http://9gag.com/comic',
'Food': 'http://9gag.com/food',
'GIF': 'http://9gag.com/gif',
'Cosplay': 'http://9gag.com/cosplay',
'Geeky': 'http://9gag.com/geeky',
'Girl': 'http://9gag.com/girl',
'Funny': 'http://9gag.com/funny',
'Design': 'http://9gag.com/design',
'WTF': 'http://9gag.com/wtf',
'NSFW': 'http://9gag.com/nsfw',
'Trending': 'http://9gag.com/trending',
'Timely': 'http://9gag.com/timely',
'Meme': 'http://9gag.com/meme',
'Hot': 'http://9gag.com/hot'
}

NOTE: NSFW section will return zero articles (empty iterable) since watching this section requires user login, which is not supported by this library.

These values are not hardcoded and will be generated on first request. Values are cached.

pyninegag.get_articles(url, max_pages=1)

Return iterable with all articles found on given url. max_pages - how many pages of results to parse. If None - all available. Default 1 - only first page.

pyninegag.get_articles(pyninegag.BASE_URL)

Will return all articles on main 9gag page.

Example output:

[
{
    'id': 'a1MEzz6',
    'title': 'Jumping into the abyss',
    'data': {
        'type': 'gif',
        'url': 'http://img-9gag-fun.9cache.com/photo/a1MEzz6_460sa.gif'
    },
    'comments': '163',
    'votes': '10709',
    'url': 'http://9gag.com/gag/a1MEzz6'
},
{
    'id': 'agVEP3g',
    'title': 'Made of crab',
    'data': {
        'type': 'image',
        'url': 'http://img-9gag-fun.9cache.com/photo/agVEP3g_700b_v1.jpg'
    },
    'comments': '257',
    'votes': '10053',
    'url': 'http://9gag.com/gag/agVEP3g'
}
]

Article type can be one of gif, image or longpost. Longpost is just a very tall image.

pyninegag.get_by_section(section_name, max_pages=1)

Return iterable with all articles found in given section. Section name must be one of the keys of pyninegag.get_sections(). If not found, ValueError will be raised.

There is also a logger pyninegag enabled that logs exceptions and warnings of parsing errors. All errors contain article id and url in message for easier debugging of problems.

python-ninegag's People

Contributors

sashgorokhov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

python-ninegag's Issues

APIs are not working

Tried using the apis provided by these library. They are not working as expected.
get_arcticles api is showing json decode errors.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.