Git Product home page Git Product logo

narwal's Introduction

narwal

narwal (sic) is a Python wrapper for reddit's API made to be simple, intuitive, and concise, i.e. pythonic.

>>> import narwal
>>> session = narwal.connect('narwal_bot', 'hunter2', user_agent="i'm a narw(h)al!")
>>> frontpage = session.hot()
>>> for link in frontpage[:3]:
    ...   print link
    ...
    (3088) Words can not describe how much I love this pic of Obama and Clinton
    (1697) Rough day for a mom at the airport.
    (1370) I felt awful when this happened.
>>> frontpage[1].upvote()
<Response [200]>
>>> frontpage[1].comment('cool story bro')
<Comment [narwal_bot: cool story bro]>

See the docs at http://narwal.readthedocs.org/.

Works with Python 2.7.

Installation

To install, just do the usual:

$ pip install narwal

Examples

Start a session:

>>> import narwal
>>> session = narwal.connect(user_agent='narwal demo')

Start a logged in session:

>>> session = narwal.connect('narwal_bot', 'password', user_agent='narwal demo')

Get the front page:

>>> page1 = session.hot()

Get the next page:

>>> page2 = page1.more()

Get the fourth link's comments:

>>> comments = page1[3].comments()

Get the second link of r/test/top:

>>> link = session.top('test')[1]

Submit a comment to it:

>>> comment = link.comment('the narwhal ba--')

Downvote the comment we just submitted:

>>> comment.downvote()
<Response [200]>

And reply to it:

>>> comment.reply('NO! *slap*')
<Comment [(1) narwal_bot: NO! *slap*]>

Check our inbox:

>>> inbox = session.inbox()

Read the first message:

>>> print inbox[0]
larryng: hi there

Get the sender's account info and submissions:

>>> user = session.user(inbox[0].author)
>>> user.submitted()
[<Link [(1) test post please ...]>]

Plus a whole lot more, since most of the reddit API has been implemented. See the API docs (or the source) for more features.

narwal's People

Contributors

larryng avatar

Stargazers

Sadiq Saif avatar

Watchers

Sadiq Saif avatar

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.