diff --git a/.idea/project.iml b/.idea/project.iml index ba4e577..2c80e12 100644 --- a/.idea/project.iml +++ b/.idea/project.iml @@ -4,7 +4,7 @@ - + \ No newline at end of file diff --git a/surf_data.py b/surf_data.py index c4ba84d..f27f1bb 100644 --- a/surf_data.py +++ b/surf_data.py @@ -9,15 +9,22 @@ def get_beach_data(): test1 = request.json.get('beach_to_search') print(test1) - port_forecasts = pysurfline. get_spot_forecasts( + port_forecasts = pysurfline.get_spot_forecasts( spotId=test1, days=2, intervalHours=3 ) - print(port_forecasts.name) + port_forecasts = {str(port_forecasts.name): + [ + str(port_forecasts.sunlightTimes), str(port_forecasts.tides), + str(port_forecasts.weather), + str(port_forecasts.wind) + ]} + + # print(port_forecasts.name) - return jsonify(test1) + return jsonify(port_forecasts) if __name__ == "__main__": app.run(port=332, debug=True) \ No newline at end of file diff --git a/web_micro/routes.py b/web_micro/routes.py index 0f72055..e99d162 100644 --- a/web_micro/routes.py +++ b/web_micro/routes.py @@ -11,20 +11,28 @@ def home(): @app.route('/search_beaches', methods=['POST']) def search_beaches(): + spotID_dict = {'Pacifica, California': '5842041f4e65fad6a7708976'} + + beach = request.json + + if beach in spotID_dict.keys(): + spotID = spotID_dict[beach] + + global response + + response = requests.post(SURF_DATA_URL, json={'beach_to_search': spotID}) + - # beach = request.json() - beach = '5cbf8d85e7b15800014909e8' - # print('Response received: ', beach) - response = requests.post(SURF_DATA_URL, json={'beach_to_search': beach}, verify=False) - test = response.json() - print(jsonify(test)) - return redirect('search_results') @app.route('/search_results') def search_results(): return render_template('search_results.html') +@app.route('/forecast') +def show_forecast(): + + return render_template('forecast.html') if __name__ == '__main__': app.run(port=333) diff --git a/web_micro/static/search_beaches.js b/web_micro/static/search_beaches.js index 1e5b34f..9ed3eae 100644 --- a/web_micro/static/search_beaches.js +++ b/web_micro/static/search_beaches.js @@ -6,7 +6,7 @@ function sendData() { headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({'beaches to search': beach}) + body: JSON.stringify(beach) }) .then(response =>{ if(!response.ok) { @@ -21,4 +21,25 @@ function sendData() { .catch(error => { console.error('Error with fetch operation:', error) }) +} + +function goHome() { + window.location.href = '/' +} + +function getForecast(){ + fetch('/forecast') + .then(response => { + if (!response.ok){ + throw new Error('Network response was not ok'); + } + window.location.href = response.url; + return response.text(); + }) + .then(data => { + console.log('Forecast: ', data); + }) + .catch(error =>{ + console.error('There was a problem with the fetch operation:', error); + }); } \ No newline at end of file diff --git a/web_micro/templates/forecast.html b/web_micro/templates/forecast.html new file mode 100644 index 0000000..263e72c --- /dev/null +++ b/web_micro/templates/forecast.html @@ -0,0 +1,83 @@ + + + + + +Beach Search + + + +
+
+ + + + + + +
+
+

+ { + "Pacifica / Linda Mar": [ + "[SunlightTimes(midnight=Time(2024-02-12 08:00:00), ...), SunlightTimes(midnight=Time(2024-02-13 08:00:00), ...)]", + "[Tides(timestamp=Time(2024-02-12 08:00:00), ...), Tides(timestamp=Time(2024-02-12 08:21:15), ...)]", + "[Weather(timestamp=Time(2024-02-12 08:00:00), ...), Weather(timestamp=Time(2024-02-12 11:00:00), ...)]", + "[Wind(timestamp=Time(2024-02-12 08:00:00), ...), Wind(timestamp=Time(2024-02-12 11:00:00), ...)]" + ] +} + +

+
+
+ + + diff --git a/web_micro/templates/search_results.html b/web_micro/templates/search_results.html index fd682c0..e3650cf 100644 --- a/web_micro/templates/search_results.html +++ b/web_micro/templates/search_results.html @@ -52,20 +52,24 @@
- Surf Web + + + + +

Select your beach:

-
    - -
+ Pacifca