Does Voat have a python API?
14 15 Jul 2015 17:53 by u/Dark_Meadows
I wasn't very sure where to post this, so I'm sorry if this is the wrong sub
14 15 Jul 2015 17:53 by u/Dark_Meadows
I wasn't very sure where to post this, so I'm sorry if this is the wrong sub
12 comments
9 u/rafaelcosta 15 Jul 2015 18:07
The HTTP API is there. An implementation of that API done in Python doesn't exist yet. However, you should be able to make one yourself pretty easily. It's just HTTP requests that return JSON data. Piece of cake.
9 u/Craftkorb 15 Jul 2015 20:49
As stated by others, you're confusing a library for Python to access the voat API with the API provided by voat for programmatic access to it.
You can find the API documentation here: https://voat.co/api/help (Linked in the footer of the page if you forget the link btw). The voat API uses HTTP as transport protocol and JSON data as storage format. Every somewhat decent language on the planet should offer implementations for both. The API scheme voat uses is, more or less, RESTful. As that scheme is wildly used by magnitudes of webservices, it's a good thing to know about.
If you're "new to this", and have never done such a thing, then I think just trying to write a minimal client yourself is actually a good idea. If you always hide behind the libraries, you won't get further with your skills. If you're an experienced Python developer, I guess that a python package (No idea how it's called over there, I use Ruby ..) would be appreciated.
Either way. Let's quickly implement a minimal client to show posts on the frontpage! As scripting language I'll use bash. We also need something which implements HTTP, and something that can parse JSON. For HTTP, we'll use
curl. For JSON it'll bejq. Please make sure to have these installed. On a ArchLinux box, the command to install these is:sudo pacman -S curl jq. Other distributions may call these packages differently, Mac users may find this in homebrew, and Windows users .. Let's get to the code before we all go insane!First step: Find out how we're supposed to access the frontpage. Looking at the documentation, we see
GET api/frontpage This API returns 100 submissions which are currently shown on Voat frontpage.This sounds exactly what we're looking for.Second step: After opening the docs on that API, we see a huge table and stuff. I suggest that you read it throughout! Just kidding.
Let's skip it for the moment. Let's say we want to display the title of the submission, and the subverse which it was posted to. The call needed to download this is:
curl 'https://voat.co/api/frontpage'. Just run this command in your shell. Now that you almost tried to make sense out of that wall of text, run the command again, but pipe it throughjq ''(Note the single quotes!):curl 'https://voat.co/api/frontpage | jq ''Third step: Looks better already. If you don't know what JSON is, now's a good moment to read up on it. Really, it's easy, if you know what an array and a Object/Hash/Dictionary/AssociativeArray/Whatever-your-language-calls-it is you're good to go. A harder read is the man page of jq.
Fourth step: Ok, now we need to tell jq to turn the JSON into something we want to look at. In the following examples, I'll just write what to put between the single-quotes next to
jqof the command above. So, we see that the response is a huge array of objects. First, get into the array:.[](.means 'this object',[]means "all elements"). Good. Now, we need to read the title ("Title") and the subverse ("Subverse"). We do this by piping the 'this object' to a filter (jq speak):.[] | .Subverse + .Title(|the pipe symbol like in your shell,.somethingaccesses 'something' in a object,+is the string concatenation operator).Fifth step: Shit's about to get real! Now we have a simple view of the frontpage. I'd suggest making it a bit more readable:
.[]| .Subverse + ": " + .Title. You can get rid of the surrounding "" by passing '-r' to jq. The complete one-liner now looks like this:curl 'https://voat.co/api/frontpage' | jq -r '.[]| .Subverse + ": " + .Title'Congratulations, you've just learned how to use your shell to build a simplistic tool to access voat's API!
1 u/Craftkorb 15 Jul 2015 20:55
Ruby implementation (If anyone wants to contribute, go ahead ..):
0 u/Childermass 20 Jul 2015 04:23
This is cool and I'm going to read this in two weeks when I can play with it.
3 u/topical_username 15 Jul 2015 19:44
Use the Python Requests and json packages to interface with the HTTP API. Not sure what you mean by 'python API' though. APIs are typically language agnostic.
2 u/b3k 15 Jul 2015 20:16
Requests even has a feature to automatically parse the JSON.
0 u/topical_username 15 Jul 2015 21:15
Exactly. I LOVE this package. I built a module for accessing the government EIA API using it for a data analysis project.
Edit: and just for clarity, I import the json package to further process what the API gives back. But yeah, the .json() method is great!
2 u/due 15 Jul 2015 18:06
Not sure what you mean by python api exactly.
Api as in api written in python to get posts comments and users? Or python object wrapper to use while you code in python?
Either way voat officially supports neither atm.
2 u/falkensMaze 15 Jul 2015 18:07
The API appears to use JSON to return data so I'm not sure what you exactly mean by "Python API". Are you asking if there is a python library? I'm not sure one exists yet. Anyway, the link to the API documentation is here. https://voat.co/v/voatdev/comments/88531 Also it appears /v/voatdev is where you should post this stuff
*edited for clarity
1 u/faissaloo 15 Jul 2015 18:28
I think he means a Python implementation.
0 u/faissaloo 15 Jul 2015 18:25
An API would be awesome
0 u/VoatSimulator 15 Jul 2015 20:54
I think someone made a Python wrapper for the API. Head over to the dev site or have a search on Github if you're looking for a ready-made solution, otherwise the REST API is available.