K-ON Quotes API, get quotes from the K-ON Anime
Project description
K-ON Quotes
Get quotes from the K-ON anime in the most easiest way possible
Table of contents
- Content
- Usage
- Splitting the quote from the author
- Fixing UnicodeError whe using local file
Content
Currently the file contains 213 quotes, however, more quotes are going to come in the future.
You can ask to add quotes by opening either an issue or a pull request
Usage
0 - With python package
pip install kon_quotes
from kon_quotes import GETquote
quote = GETquote(character_you_want) # mio, yui, azusa, tsumugi, ritsu, sawako, jun, general, all
quote_author = quote.GETauthor()
print(f"{quote} - {quote_author}")
1 - With .txt file (online)
import requests, random
file_url = "https://zeyatsu.github.io/k-on-quotes/quotes.json" # No need to download the txt file.
response = requests.get(file_url)
if response.status_code == 200:
lines = response.text.splitlines()
random_line = random.choice(lines)
print(random_line)
else:
print("Error: ", response.status_code)
2 - With API (.json file (online))
import random
import requests
json_url = "https://zeyatsu.github.io/k-on-quotes/quotes.json" # No need to download the json file.
response = requests.get(json_url)
if response.status_code == 200:
data = response.json()
random_author = random.choice(list(data["authors"].keys()))
random_quote = random.choice(data["authors"][random_author])
print(f"{random_quote} by {random_author}")
For characters replace "k-on-quotes/quotes.json" by "k-on-quotes/characters/the_character_you_want.json"
Splitting the quote from the author
quote, author = random_quote.strip().split(" / ")
print(f"Quote: {quote} by {author}")
Fixing UnicodeError when using local file
If you download the quotes.txt file instead of using the url, it is possible to get a UnicodeError. In this case, you will have to add a encoding parameter
with open('quotes.txt', 'r', encoding='utf-8') as f:
Credits
ZeyaTsu |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file kon_quotes-1.0.1.tar.gz
.
File metadata
- Download URL: kon_quotes-1.0.1.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19e14efa350b105c46cfd8dad059a8220812046e5bc29c14cf79847a6c2adca9 |
|
MD5 | 475b1e3de846e402e6fdf1ab23d212f3 |
|
BLAKE2b-256 | 906195b6530637badddc7be883666b44c816549b37508ecbbd68daf6979ea746 |
File details
Details for the file kon_quotes-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: kon_quotes-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d8c609352d162c82fb2366b270800d3d5819c80170b644d4a021a872d917a3d |
|
MD5 | 31175c33103cd405ac215bf40d773fe6 |
|
BLAKE2b-256 | 9016d35ff169818dd82b4765489cd7a7810108c818406eef6d67eb17f3adc8f5 |