-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetSPCond.py
59 lines (51 loc) · 1.98 KB
/
getSPCond.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from infoExtractor import getBouyData
import datetime
import requests
import json
class SurfSpot:
def __init__(self, name, lat, lon):
self.name=name
self.lat=lat
self.lon=lon
self.buoyData=getBouyData()
self.Wind = getWindData(lat,lon)
self.tideData=getTide()
def getSurfSpotData():
#add animals and killers
spotList =[["Rock", 35.372834,-120.867390],
["Pit", 35.377083, -120.867371],
["Studios", 35.419715, -120.880746],
["Yerb", 35.403359, -120.872336],
["Cayucos", 35.447924, -120.906409],
["Sanspit", 35.304456, -120.880269],
["Hazards", 35.291400, -120.886026],
["Beachcombers",35.168331, -120.697321],
["Sewers", 35.159157, -120.686966],
["Pismo", 35.138202, -120.646070]]
tempSpot =[]
for spots in spotList:
tempSpot.append(SurfSpot(spots[0],spots[1],spots[2]))
return tempSpot
def getKey():
f = open("WeatherAppKey")
return f.read()
def getWindData(lat,lon):
#API KEY NOT PRIVATE
key = getKey()
data_spec = requests.get(f'https://api.openweathermap.org/data/2.5/forecast?lat={lat}&lon={lon}&units=imperial&appid={key}').text
y = json.loads(data_spec)
wind=[]
for data_item in y['list']:
wind.append(data_item['wind'])
return wind
def getTide():
today = datetime.date.today()
nextWeek = today + datetime.timedelta(days=7)
tideData = requests.get(f'https://api.tidesandcurrents.noaa.gov/api/prod/datagetter?begin_date={str(today).replace("-","")}&end_date={str(nextWeek).replace("-","")}&station=9412110&product=ofs_water_level&datum=MLLW&time_zone=gmt&units=english&format=xml').text.replace("<wl","").replace("/>","").split("\n")
return tideData
def consoludateData():
spots =["Rock", 35.372834,-120.867390]
rock = SurfSpot(spots[0],spots[1],spots[2])
print(rock.buoyData[0 ])
print(rock.Wind)
consoludateData()