WIKI TOOLS

-

index

viewhistorytalk

RSAW

RSAW is a really light API wrapper, created for this here website. I (/u/diogenesjunior) created it because Saidit didn't have a Python API wrapper, and I personally needed to use Saidit programatically.

Installation

Installing RSAW is easy, assuming you have pip3 installed:

pip3 install RSAW

Credentials

To get all of your needed API creds:

  • Go to /prefs/apps
  • Select "are you a developer? create an app..."
  • Name it "RSAW Testing"
  • Select "script"
  • Leave a small description about your project
  • Leave the about url empty
  • Put a link to the logged in account's profile for the redirect uri

You can then start using the API wrapper. I suggest you at least learn some Python first. Here's a small rundown of how you'd use it:

  • Create a file named "main.py"
  • Copy and paste the following into main.py:

    import rsaw
    
    saidit = rsaw.Saidit(client_id='client_id',
                    client_secret='client_secret',
                    username='username',
                    password='password',
                    app='our_app',
                    token_file='/tmp/token')
    me = saidit.get('/api/v1/me')
    print(me)
    
  • Replace 'client_id' with the personal use script

  • Replace 'client_secret' with the secret

  • Replace 'username' with your username

  • Replace 'password' with your password

  • Replace 'our_app' with a simple user agent

Now run the file in your terminal:

python3 main.py

This will return data found at "/api/v1/me". There are many more endpoints, all listed here

  • /api/v1/me/karma
  • /api/v1/me/prefs
  • /api/v1/me/trophies
  • /prefs/friends
  • /prefs/blocked
  • /api/v1/me/friends
  • /api/v1/me/blocked

POST requests

Suppose you want to make a POST request:

from rsaw import Saidit

saidit = Saidit(client_id='client_id',
                client_secret='client_secret',
                username='username',
                password='password',
                app='our_app',
                token_file='/tmp/token')
paramaters = {'kind': 'self', 'sr': 'rsaw', 'title': 'testing - title', 'text': 'testing - selftext'}
me = saidit.post('/api/submit', params=paramaters)

This will submit a self post to /s/rsaw, with a title of "testing - title", and a selftext of "testing - selftext"


revision by [deleted]— view source