Question

In: Computer Science

Develop a Python program that brings together APIs and web scraping. Be creative. Pick something you...

Develop a Python program that brings together APIs and web scraping. Be creative. Pick something you are interested in - a hobby, a job, history, cooking, travel, sports, a foreign language, music, art, whatever you have some passion about.

Find an API that connects with your interest. Write a Python program that demonstrates the use of that api AND does some web scraping as well. It must include the ability to download images to your computer.

Submit the following to this Blackboard assignment:

1. your WELL DOCUMENTED source code file(s)

2. a word document that explains your program - what it does and how it does it

3. a Loom video link demonstrating what your program does - be sure to show off the images you download with your app.

Solutions

Expert Solution

# -*- coding: utf-8 -*-
"""
Created on Sat Oct 17 14:26:02 2020

@author: Unknown
"""
######Sample python code begins here##########################################
# Importing the needed modules for the application
import os
import json
import urllib.request
import random
def main():
# Debug line to indicate the start of the program
print("Starting in Main ....")
# Destination directory for storing the image from web
dest_dir = "Image"
#The API "https://dog.ceo/api/breeds/image/random" returns a random DOG BREED image
response = urllib.request.urlopen("https://dog.ceo/api/breeds/image/random")
#If the API call was a sucess get the dog breed URL else write an error message
if response.getcode() == 200:
source = response.read()
data = json.loads(source)
else:
print('An error occurred while attempting to retrieve data from the API.')
#From the API output get the URL for the DOG BREED image
dog_breed_url = data['message']
print("Dog Breed URL is ",dog_breed_url)
#Format the destination path to download the DOG BREED image
cur_dir = os.path.abspath(os.path.curdir)
odirpath = os.path.join(cur_dir, dest_dir)
if not os.path.exists(odirpath): os.mkdir(odirpath)
#Genarate a four digit random number for the file name
randomint = random.randint(0000,9999)
imgname = 'img' + str(randomint) + '.jpg'
imgpath = os.path.join(odirpath, imgname)
print("Destination Path the image downloaded is : ",imgpath)
#Download the image from web
urllib.request.urlretrieve(dog_breed_url, imgpath)
print("Program ended....")
# Calling the main function
if __name__ == '__main__':
main()
######Sample python code ends here##########################################

The API URL - https://dog.ceo/api/breeds/image/random hosted the internet returns an json file with the path from where the image can be downloaded. The API returns an random image of a DOG breed.
The Python program at a high level does the following things:
1. Makes a call to the API url
2.Checks the status of the API call.

3.A return code of 200 indicates a successful call to the API, in case of an uncessfull call the program prints an error message.

4. The API returns a json message with the location from where to download the image.

{"message":"https:\/\/images.dog.ceo\/breeds\/dalmatian\/cooper1.jpg","status":"success"}

5. JSON message is read to get the path of the jpg file for the download

6.The image is downloaded to the local machine in a destination folder named "Images".


Related Solutions

In this assignment, you will develop a simple Web server in Python that is capable of...
In this assignment, you will develop a simple Web server in Python that is capable of processing only one request. Specifically, your Web server will (i) create a connection socket when contacted by a client (browser); (ii) receive the HTTP request from this connection; (iii) parse the request to determine the specific file being requested; (iv) get the requested file from the server’s file system; (v) create an HTTP response message consisting of the requested file preceded by header lines;...
Develop a python program to autonomously operate an adeept tank robot to pick up an object...
Develop a python program to autonomously operate an adeept tank robot to pick up an object placed randomly in an arena.
Develop a python program to convert two decimal numbers (A and B) to binary numbers. You...
Develop a python program to convert two decimal numbers (A and B) to binary numbers. You should generate B complement signal (flip all the bits of Input B,
Create a python program that contains a while loop together with a Sentinel (0) to process...
Create a python program that contains a while loop together with a Sentinel (0) to process indefinite item costs that are purchased online from a vendor. Be sure that you assign a variable SENTINEL to 0 to use in the Boolean condition of your while loop. A sales tax rate of 6.25% is applied to the subtotal for the items purchased. Be sure you assign a variable, TAXRATE to 0.0625. The program is to process a number of items, numItems,...
Posting together because they are related. Python 1. Create a program to count the number of...
Posting together because they are related. Python 1. Create a program to count the number of occurrences of each letter of the alphabet in a text file, and print out the total for each letter (if greater than 0). Ignore numbers, punctuation, and special characters. Make sure to treat capital and lowercase letters as occurrences of the same letter. The text file (sample_text.txt) is attached to the assignment. Example: For the text "My dog's name is Winston." The results would...
You will create an interest web based on something you like to do. Please follow the...
You will create an interest web based on something you like to do. Please follow the step-by-step directions below. 1) Make a list of the things/activities you liked to do as a child. 2) Make a list of the things/activities you like to do as an adult. 3) Find one thing in common from both of your lists - it should be an activity that you liked doing as a child and still like doing today. Take that one activity...
TheMathGame Develop a program in PYTHON that will teach children the basic math facts of addition....
TheMathGame Develop a program in PYTHON that will teach children the basic math facts of addition. The program generates random math problems for students to answer. User statistics need to be kept in RAM as the user is playing the game and recorded in a text file so that they may be loaded back into the program when the student returns to play the game again. In addition, the youngster should be allowed to see how (s)he is doing at...
Develop a python program to create a quiz with limited time and attempts!!! Add comments and...
Develop a python program to create a quiz with limited time and attempts!!! Add comments and screenshot of running the program quiz could be of anything like , what's the sum of 2&2. There should be number of attempts(limited) suppose if the answer is wrong.
Develop a program using python to demonstrate data exchange using USB protocol.
Develop a program using python to demonstrate data exchange using USB protocol.
For Python: In this assignment you are asked to write a Python program to determine the...
For Python: In this assignment you are asked to write a Python program to determine the Academic Standing of a studentbased on their CGPA. The program should do the following: Prompt the user to enter his name. Prompt the user to enter his major. Prompt the user to enter grades for 3 subjects (A, B, C, D, F). Calculate the CGPA of the student. To calculate CGPA use the formula: CGPA = (quality points * credit hours) / credit hours...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT