Tronalddump.io is a free API and web archive for the dumbest things Donald Trump has ever said ...
You might want to check out the documentation for the API before working with it.
The package consists of two main modules:
api
: tools for accessing the API.parse
: tools for parsing retieved data.
Ensure you have Python 3 and the package manager pip
installed.
Install using pip:
$ pip3 install tronald-dumpy
or, you can build the latest version from source:
$ git clone https://github.com/Gushka/tronalddump-python.git
$ cd tronalddump-python/
$ python3 setup.py install
Import the main modules and create a client:
from tronalddump import api, parse
client = api.TronaldDumpAPI()
Now to access any API method we will use this client.
For example, let us get a random quote:
>>> resp = client.random_quote()
>>> resp
<TronaldDumpResponse: 'https://www.tronalddump.io/random/quote'>
# Get the response data:
>>> resp.data
{JSON}
# Get the URL:
>>> resp.url
'https://www.tronalddump.io/random/quote'
Using the TronaldDump module you also can get specific values from the API response just as easy.
Create a Parser using the JSON file-object we obtained earlier:
>>> parsed = parse.Parser(resp)
Now we can extract all kinds of data from the JSON based on what the initial response type was.
# Retrieve value of a quote:
>>> parsed.value()
"Money was never a big motivation for me, except as a way to keep score."
# Retrieve the date it was written online:
>>> parsed.date_appeared()
datetime.date(2014, 9, 14)
There's also a function to print into the console formatted JSON response.
Use it only for the debugging purposes.
>>> parsed.printout()
Retrieves all existing tags from the API.
TronaldDumpAPI().all_tags()
Finds a tag by its value. Given paramaters will be capitalized for the proper search indexing.
TronaldDumpAPI().find_tag(value)
Retrieve a random quote from Troland Dump.
TronaldDumpAPI().random_quote()
Retrieve a random meme image with a quote Troland Dump.
TronaldDumpAPI().random_meme(output_dir, filename="randommeme.png", force_write=True)
output_dir
: The directory where to store the image.filename
: The name for the downloaded file. By default it's randommeme.pngforce_write
: Whether to overwrite already existing file or not. By default is set to True
Search for a quote by a query or tag. Returns one-page answer. You must pick either query
or tag
parameter.
They are interchangeble and only one may be used at a time.
TO BE IMPROVED: For now returns only the first page of a search answer.
TronaldDumpAPI().search_quote(query=None, tag=None, page=0)
query
: The string which will be searched for.tag
: The tag which will be searched for.page
: The number of a page that will be returned.
Find a quote by its ID.
TronaldDumpAPI().find_quote(id)
id
: The ID of a quote you're looking for.
Retrieve the source of a quote by its ID.
TronaldDumpAPI().quote_source(id)
id
: The ID of a quote source of which you're looking for.
Find an author by their ID.
TronaldDumpAPI().find_author(id)
id
: The ID of an author you're looking for.
Prints the contents of given JSON object in the formatted form.
Parser().printout()
Retrieve all tags values from the given JSON object in a list.
Parser().tag_value()
Retrieve the "value" value of a given JSON object.
Parser().value()
Retrieve the "author" value of a given JSON object.
Parser().author()
Retrieve the date when a given quote was written and published.
Parser().date_appeared()
Retrieve all the tags of a given quote
Parser().tags()
Retrieve the "quote-id" value from the JSON object
Parser().quote_id()
Retrieve the source of a given quote
Parser().source()
For full and more detailed information see help()
on needed classes and functions.