Avatar of the person chatting

Write a python script that fetches a popular quote form an API endpoint, it then appends the quote to a file

Here is a python script that fetches a popular quote from an API endpoint and appends it to a file:

import requests # API endpoint for fetching popular quotes QUOTE_API_ENDPOINT = 'https://api.quotable.io/random' # file to append the quote to QUOTE_FILE = 'quotes.txt' # fetch a quote from the API endpoint response = requests.get(QUOTE_API_ENDPOINT) # parse the response as JSON quote = response.json() # extract the quote text from the JSON object quote_text = quote['content'] # append the quote to the file with open(QUOTE_FILE, 'a') as f: f.write(quote_text) f.write('\n') print(f'Successfully appended quote to {QUOTE_FILE}')

This script uses the requests library to make an HTTP GET request to the API endpoint, which returns a JSON object containing a quote. The script then parses the JSON response and extracts the quote text, and appends it to a file.

Note that this script is just an example and may not work as-is, since it is not connected to a real API endpoint. You will need to provide your own API endpoint and modify the script accordingly.