Client

class nineapi.client.Client(app_id='com.ninegag.android.app', log_level=20)[source]

9GAG API Client.

Create API client instance.

Parameters:
  • app_id – Application id (defaults to ‘com.ninegag.android.app’)
  • log_level – Logging level (defaults to logging.INFO)
class Services[source]

Represents sub-API URLs.

get_posts(group=1, type_='hot', count=10, entry_types=['animated', 'photo', 'video', 'album'], olderThan=None, **kwargs)[source]

Fetch posts.

Parameters:
  • group – Posts category (defaults to 1)
  • type – Posts type (defaults to ‘hot’)
  • count – Count of posts.
  • entry_types – list of strings
  • olderThan – Last seen post (for pagination) - str, Post or None
Returns:

list of Post

Raises:

APIException

is_authorized

Authorization status.

log_in(username, password)[source]

Attempt to log in.

Parameters:
  • username – User login.
  • password – User password.
Returns:

True

Return type:

bool

Raises:

APIException

search_posts_by_tag(query, offset=0, count=10, entry_types=['animated', 'photo', 'video', 'album'], sort='asc', **kwargs)[source]

Fetch posts that match specific tag.

Parameters:
  • query – Posts tag
  • offset – Offset to start from.
  • count – Count of posts.
  • entry_types – list of strings
  • sort – sorting order (“asc” or “desc”) - does not seem to work
Returns:

list of Post

Raises:

APIException

class nineapi.client.Post(client, props)[source]

Represents single post.

class Types[source]

Enum for possible post type values.

get_media_url()[source]

Returns image URL for Photo posts and .WEBM URL for Animated posts.

get_top_comments()[source]

Retrieves top comments for this post.

id

Post ID.

props

Dictionary with post data.

title

Post title.

type

Post type.

url

Post url.