Write My Paper Button

Complete the Python program as defined in the attached file: 3900 Activity 5 Working with API’s and JSON -sv.pdf

Learning Goal: I’m working on a website development discussion question and need an explanation and answer to help me learn.

Working with JSON /Dictionaries and Application Programming interfaces

Complete the Python program as defined in the attached file: 3900 Activity 5 Working with API’s and JSON -sv.pdf

Download 3900 Activity 5 Working with API’s and JSON -sv.pdf

Links to an external site.

JSON Examples:

Sample Python Example: jsonLocationExample_APIkeyNeeded.pyDownload

jsonLocationExample_APIkeyNeeded.py#https://ipstack.com/

#Simple RESTful API request example
#Request a free API Key at this link: https://ipstack.com/product
#Paste your key at line 14 below
import requests
print(“ISQA 3900 Location API”)
print()
try:
api_start = ‘http://api.ipstack.com/174.74.113.227?access_key=’
api_key = ‘yourAPIkeyHere’
url = api_start + api_key
json_data = requests.get(url).json()
print(json_data)
IP = json_data[‘ip’]
print(“IP = ” + IP)
print(“Country = ” + json_data[‘country_name’])
print(“State = ” + json_data[‘region_name’])
print(“City = ” + json_data[‘city’])
except Exception:
print(“Unable to get json data”)

Another Example – Dog information – no API key needed: DogAPI.pyDownload DogAPI.py#https://ipstack.com/

#Simple RESTful API request example
#Request a free API Key at this link: https://ipstack.com/product
#Paste your key at line 14 below
import requests
print(“ISQA 3900 Location API”)
print()
try:
api_start = ‘http://api.ipstack.com/174.74.113.227?access_key=’
api_key = ‘yourAPIkeyHere’
url = api_start + api_key
json_data = requests.get(url).json()
print(json_data)
IP = json_data[‘ip’]
print(“IP = ” + IP)
print(“Country = ” + json_data[‘country_name’])
print(“State = ” + json_data[‘region_name’])
print(“City = ” + json_data[‘city’])
except Exception:
print(“Unable to get json data”)

NASA Space Station Tracking example: ISSTrackingProgram_Map.pyDownload ISSTrackingProgram_Map.py

# https://www.geeksforgeeks.org/how-to-track-iss-int…

# json convert the python dictionary
# above into a json
from sys import exit
import json
import turtle
import sys
# urllib.request fetch URLs using
# a variety of different protocols
import urllib.request
import time
# webbrowser provides a high-level interface
# to allow displaying Web-based documents
# to users
import webbrowser
# geocoder takes the data and locate these
# locations in the map
import geocoder
url = “http://api.open-notify.org/astros.json”
response = urllib.request.urlopen(url)
result = json.loads(response.read())
file = open(“iss.txt”, “w”)
file.write(“There are currently ” +
# prints number of astronauts
str(result[“number”]) + ” astronauts on the ISS: nn”)
people = result[“people”]
# prints names of crew
for p in people:
file.write(p[‘name’] + ” – on board” + “n”)
# print long and lat of space station
g = geocoder.ip(‘me’)
file.write(“nYour current lat / long is: ” + str(g.latlng))
file.close()
webbrowser.open(“iss.txt”)
# Setup the world map in turtle module
screen = turtle.Screen()
screen.setup(1280, 720)
screen.setworldcoordinates(-180, -90, 180, 90)
# load the world map image
screen.bgpic(“images/map.gif”)
screen.register_shape(“imagesiss.gif”)
iss = turtle.Turtle()
iss.shape(“imagesiss.gif”)
iss.setheading(45)
iss.penup()
try:
while True:
# load the current status of the ISS in real-time – updating position as it moves
url = “http://api.open-notify.org/iss-now.json”
response = urllib.request.urlopen(url)
result = json.loads(response.read())
# Extract the ISS location
location = result[“iss_position”]
lat = location[‘latitude’]
lon = location[‘longitude’]
# Ouput lon and lat to the terminal
lat = float(lat)
lon = float(lon)
print(“nLatitude: ” + str(lat))
print(“nLongitude: ” + str(lon))
# Update the ISS location on the map
iss.goto(lon, lat)
# Refresh each 5 seconds
time.sleep(2)
except:
print(“Ending program”)
sys.exit()

Rubric

Activity 5 Rubric – JSON, API, Output files

Activity 5 Rubric – JSON, API, Output files
Criteria Ratings Pts
This criterion is linked to a Learning OutcomeProgram Functionality
16 to >15.0 ptsFully Functional

Functions as required and has appropriate comments in the code Day, date, and all weather outputs formatted as required Git Hub repo updated and shared via Canvas comment if repo other than Activity5 repo created for class.

15 to >8.0 ptsMissing Functionality

One or two values not formatted correctly, are missing (Date, Day, weather values, etc), or some outputs missing identifying text

8 to >0 ptsMissing Functionality

Multiple values not formatted correctly, are missing (Date, Day, weather values, etc), or some outputs missing identifying text

16 pts
This criterion is linked to a Learning OutcomeException Handling
5 to >4.0 ptsExceptions and Errors Handled and Reported

Program reports errors to user if the city or country name is invalid and allows user to continue

4 to >0.0 ptsMissing Functionality

Program does not report errors or user not allowed to continue after entering invalid values

0 ptsMissing Functionality

Program crashes when an invalid city or county is input

5 pts
This criterion is linked to a Learning OutcomeOutput saved to text fileWrite the valid outputs to a text file. The user should be prompted to enter the output filename.
6 to >5.0 ptsValid weather data written to file

No error messages and no user prompts written to file.

5 to >0.0 ptsValid weather data incomplete or incorrect in output file

Output to file is incomplete or includes error messages or prompts.

0 ptsNo Marks
6 pts
This criterion is linked to a Learning OutcomeGood programming practice followedDescriptive variable and function names; Simple comments including the following REQUIRED program file header at the top of the Python file: Your name; The course name and date; A short description of the code in the file (i.e. purpose of the program)
3 to >2.0 ptsGood programming practices used

Descriptive variable and function names; Simple comments including the following REQUIRED program file header at the top of the Python file: Your name; The course name and date; A short description of the code in the file (i.e. purpose of the program)

2 to >0.0 ptsNot all good programming practices followed

Missing or incorrect: Descriptive variable and function names; Simple comments including the following REQUIRED program file header at the top of the Python file: Your name; The course name and date; A short description of the code in the file (i.e. purpose of the program)

0 ptsGood programming practices not followed
3 pts
This criterion is linked to a Learning OutcomeLate PenaltyIf applicable
0 ptsDeduction if applicable 0 ptsNo Penalty
0 pts
Total Points: 30
WhatsApp Widget
GET YOUR PAPER DONE