Skip to content

Get quotes from the K-ON anime in the most easiest way possible

License

Notifications You must be signed in to change notification settings

ZeyaTsu/k-on-quotes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

K-ON Quotes

Get quotes from the K-ON anime in the most easiest way possible
Mio Akiyama

Table of contents

  • Content
  • Usage
  • Splitting the quote from the author
  • Fixing UnicodeError when 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}")

# If you are getting errors while printing or using GETquote or whatever, try to str()

1 - With .txt file (online)

import requests, random

file_url = "https://zeyatsu.github.io/k-on-quotes/quotes.txt" # 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/.txt" by "k-on-quotes/characters/the_character_you_want.json/.txt"

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

Author: ZeyaTsu
ZeyaTsu

About

Get quotes from the K-ON anime in the most easiest way possible

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages