Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- CIS 41B (01Y)
- Lab 4 - lab4thread.py
- ~
- https://developer.nps.gov/api/v1/parks?parkCode=acad&api_key=C7SfLFWYf9AwhzvlPpvMCQYveao45BdlyukRqUhQ
- API Key:
- C7SfLFWYf9AwhzvlPpvMCQYveao45BdlyukRqUhQ
- https://developer.nps.gov/api/v1/parks?stateCode=<state code>&api_key=<your key>
- park contains:
- states : state abbreviation, ex: 'CA'
- latLong : latitude and longitude of park location
- description : description of park
- designation : type of park, ex: 'National Park'
- parkCode : 4 letter id to represent park
- id : individual park ID for API data
- directionsInfo : text description of location
- directionsUrl : URL for directions
- fullName : name of park
- url : URL to park
- weatherInfo : text description of weather
- name : shortened name of park
- @author Huy Nguyen, Minhduc Cao
- @version 1.0
- @date 2019.05.23
- """
- import urllib.request
- import json
- import matplotlib
- import tkinter as tk
- import sys # For gui2fg()
- import os # For gui2fg()
- def gui2fg():
- """Brings tkinter GUI to foreground on Mac
- Call gui2fg() after creating main window and before mainloop()
- start
- """
- if sys.platform == 'darwin':
- tmpl = 'tell application "System Events" to set frontmost of every process whose unix id is %d to true'
- os.system("/usr/bin/osascript -e '%s'" % (tmpl % os.getpid()))
- def tempGrabData():
- """Temporary, just used for testing out API access and grabbing data"""
- state = "ca" # Change this to whatever state you need in lowercase
- key = "&api_key=C7SfLFWYf9AwhzvlPpvMCQYveao45BdlyukRqUhQ" # This is my API key, you can use your own or use mine
- url = "https://developer.nps.gov/api/v1/parks?stateCode=" + state + key # Creates URL to access API
- response = urllib.request.urlopen(url).read()
- data = json.loads(response.decode('utf-8'))
- numParks = data["total"]
- print("There are " + str(numParks) + " in " + state.upper() + ".")
- for park in data["data"]: # park is a dictionary, see top of file to see what park contains for data access
- print(park["fullName"])
- class MainWin(tk.Tk):
- def __init__(self):
- super().__init__()
- tempGrabData()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement