Random Quote Fetcher

  • Share this:

Code introduction


This function fetches a random quote from the quotable.io API and returns the quote along with its author.


Technology Stack : requests, json, datetime

Code Type : Function

Code Difficulty : Intermediate


                
                    
import random
import requests
import json
from datetime import datetime

def fetch_random_quote():
    url = "https://api.quotable.io/random"
    response = requests.get(url)
    data = response.json()
    quote = data['content']
    author = data['author']
    return f"'{quote}' - {author}"