Advertisement
Guest User

wip

a guest
May 23rd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.40 KB | None | 0 0
  1. """
  2. CIS 41B (01Y)
  3. Lab 4 - lab4thread.py
  4. ~
  5.  
  6. https://developer.nps.gov/api/v1/parks?parkCode=acad&api_key=C7SfLFWYf9AwhzvlPpvMCQYveao45BdlyukRqUhQ
  7. API Key:
  8. C7SfLFWYf9AwhzvlPpvMCQYveao45BdlyukRqUhQ
  9. https://developer.nps.gov/api/v1/parks?stateCode=​<state code>​&api_key=​<your key>
  10.  
  11. park contains:
  12.    states          : state abbreviation, ex: 'CA'
  13.    latLong         : latitude and longitude of park location
  14.    description     : description of park
  15.    designation     : type of park, ex: 'National Park'
  16.    parkCode        : 4 letter id to represent park
  17.    id              : individual park ID for API data
  18.    directionsInfo  : text description of location
  19.    directionsUrl   : URL for directions
  20.    fullName        : name of park
  21.    url             : URL to park
  22.    weatherInfo     : text description of weather
  23.    name            : shortened name of park
  24.  
  25. @author Huy Nguyen, Minhduc Cao
  26. @version 1.0
  27. @date 2019.05.23
  28. """
  29. import urllib.request
  30. import json
  31. import matplotlib
  32. import tkinter as tk
  33. import sys  # For gui2fg()
  34. import os   # For gui2fg()
  35.  
  36.  
  37. def gui2fg():
  38.     """Brings tkinter GUI to foreground on Mac
  39.    Call gui2fg() after creating main window and before mainloop()
  40.    start
  41.    """
  42.     if sys.platform == 'darwin':
  43.         tmpl = 'tell application "System Events" to set frontmost of every process whose unix id is %d to true'
  44.         os.system("/usr/bin/osascript -e '%s'" % (tmpl % os.getpid()))
  45.  
  46.  
  47. def tempGrabData():
  48.     """Temporary, just used for testing out API access and grabbing data"""
  49.     state = "ca"                                                                 # Change this to whatever state you need in lowercase
  50.     key = "&api_key=C7SfLFWYf9AwhzvlPpvMCQYveao45BdlyukRqUhQ"                   # This is my API key, you can use your own or use mine
  51.     url = "https://developer.nps.gov/api/v1/parks?stateCode=" + state + key     # Creates URL to access API
  52.     response = urllib.request.urlopen(url).read()
  53.     data = json.loads(response.decode('utf-8'))
  54.  
  55.     numParks = data["total"]
  56.     print("There are " + str(numParks) + " in " + state.upper() + ".")
  57.     for park in data["data"]:                                                   # park is a dictionary, see top of file to see what park contains for data access
  58.         print(park["fullName"])
  59.  
  60.  
  61. class MainWin(tk.Tk):
  62.     def __init__(self):
  63.         super().__init__()
  64.  
  65.  
  66. tempGrabData()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement