Skip to content

Commit 9a1699c

Browse files
author
Tania Allard
committed
Add NASA
1 parent 8097690 commit 9a1699c

File tree

16 files changed

+6402
-636
lines changed

16 files changed

+6402
-636
lines changed

β€Ž.gitignoreβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
\.DS_Store
3+
config.yml
34

45
# Byte-compiled / optimized / DLL files
56
__pycache__/

β€Žsession5/CFG_app/app.pyβ€Ž

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from flask import Flask, render_template, request, redirect, session
22
from helpers.twitter import authenticate, collect_tweets, get_config
33
from helpers.spotify import authorize_spotify, spotify_search, get_auth
4+
from helpers.NASA import get_APOD
45

56
import requests
67

@@ -81,6 +82,28 @@ def spotify_search_app():
8182

8283
return render_template('spotify_show.html', data = data, query = query, search_type = search_type)
8384

85+
86+
# -------------- Functions and decorators for NASA API queries --------------
87+
88+
@app.route("/NASA")
89+
def NASA_handler():
90+
""" This will only take you to the NASA search page"""
91+
92+
return render_template("NASA.html")
93+
94+
95+
@app.route("/NASA_search", methods = ['POST'])
96+
def NASA_search_app():
97+
"""When the search is submitted from the previous page,
98+
this function passes the form data to our python scripts
99+
and uses them to perform the query. It will then return the tweets
100+
and display them in /tweets_show"""
101+
date = request.form['date']
102+
APOD = get_APOD(date)
103+
104+
return render_template('NASA_show.html', apod = APOD, date = date)
105+
106+
84107
# "debug=True" causes Flask to automatically refresh upon any changes you
85108
# make to this file.
86109
app.run(debug=True)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import requests
2+
3+
def get_APOD(date):
4+
"""This will do the request on the NASA api"""
5+
payload = 'https://api.nasa.gov/planetary/apod'
6+
params = {'api_key' : 'DEMO_KEY',
7+
'date' : date}
8+
9+
response = requests.get(payload, params = params)
10+
return response.json()

β€Žsession5/CFG_app/static/js/bootrstrap-datetimepicker.jsβ€Ž

Lines changed: 2655 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
Β (0)