-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π©πΌβπ¨β°οΈ β Merge pull request #45 from Signal-K/GP-28-P
π³π©πΌβπ¨ β Gp 28 p
- Loading branch information
Showing
130 changed files
with
15,919 additions
and
1,302 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: Flask App CI | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.x' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
- name: Test with pytest | ||
run: pytest | ||
|
||
- name: Lint with flake8 | ||
run: | | ||
pip install flake8 | ||
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | ||
- name: Run Flask app | ||
run: python app.py |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# This configuration file was automatically generated by Gitpod. | ||
# Please adjust to your needs (see https://www.gitpod.io/docs/introduction/learn-gitpod/gitpod-yaml) | ||
# and commit this file to your remote git repository to share the goodness with others. | ||
|
||
# Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart | ||
|
||
tasks: | ||
- init: npm install && npm run build && make | ||
command: npm run start | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,10 @@ | ||
[packages] | ||
moralis = "*" | ||
flask = "*"ac | ||
flask_cors = "*" | ||
thirdweb-sdk = "*" | ||
python-dotenv = "*" | ||
psycopg2 = "*" | ||
matplotlib = "*" | ||
lightkurve = "*" | ||
nbformat = "*" | ||
gunicorn = "*" | ||
sqlalchemy = "*" | ||
psycopg2-binary = "*" | ||
flask-sqlalchemy = "*" | ||
supabase = "*" | ||
gotrue = "*" | ||
noise = "*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
web3 = "*" | ||
brownie = "*" | ||
eth-brownie = "*" | ||
eth_utils = "*" | ||
thirdweb-sdk = "*" | ||
moralis = "*" | ||
psycopg2 = "*" | ||
psycopg2-binary = "*" | ||
flask-sqlalchemy = "*" | ||
sqlalchemy = "*" | ||
gotrue = "*" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,71 @@ | ||
from flask import Flask, request, make_response, jsonify, Blueprint | ||
from flask import Flask, jsonify, request, g | ||
import requests | ||
|
||
import base64 | ||
from io import BytesIO | ||
app = Flask(__name__) | ||
|
||
from database.store import planets, add_planet_to_DB | ||
# from Generator import gen_image # add this to a blueprint | ||
# Store authentication details in a global variable 'auth' | ||
auth = None | ||
|
||
from database.datastore import solObjects # get this from database.store / supabase-py in prod | ||
@app.route("/") | ||
def index(): | ||
return "Hello world" | ||
|
||
import time | ||
@app.route('/login', methods=['POST']) | ||
def login(): | ||
global auth # Use the global 'auth' variable to store authentication details | ||
|
||
app = Flask(__name__) | ||
|
||
@app.route('/', methods=['GET', 'POST']) | ||
def index(): | ||
return jsonify(solObjects) | ||
# Parse the JSON request data | ||
data = request.get_json() | ||
username = data.get('username') | ||
password = data.get('password') | ||
|
||
@app.route('/planet', methods=['GET', 'POST']) | ||
def index(): | ||
return jsonify(planets) | ||
# Check if username and password are provided | ||
if not username or not password: | ||
return jsonify({'error': 'Username and password are required'}), 400 | ||
|
||
@app.route('/time') | ||
def get_current_time(): | ||
return {'time': time.time()} | ||
# Send a POST request to the NASA Earthdata login API | ||
response = requests.post( | ||
'https://appeears.earthdatacloud.nasa.gov/api/login', | ||
auth=(username, password) | ||
) | ||
|
||
# Check if the request was successful | ||
if response.status_code == 200: | ||
token_response = response.json() | ||
# Store authentication details in the 'auth' variable | ||
auth = (username, password) | ||
return jsonify(token_response) | ||
else: | ||
return jsonify({'error': 'Login failed'}), 401 | ||
|
||
# GET request -> return all planets in storage/db in JSON format | ||
@app.route('/planets') | ||
def get_planets(): | ||
return jsonify({ | ||
'planets': planets, # Then present this on react frontend, port 5000 -> 3000 | ||
}) | ||
@app.route('/get_geolocation', methods=['POST']) | ||
def get_geolocation(): | ||
global auth # Use the global 'auth' variable for authentication | ||
|
||
@app.route('/planets/<planet_id>') | ||
def find_planet_by_id(planet_id): | ||
for planet in planets: | ||
if planet["id"] == int(planet_id): | ||
return jsonify({ | ||
"planet": planet, | ||
}) | ||
# Check if authentication details are available | ||
if not auth: | ||
return jsonify({'error': 'Authentication required'}), 401 | ||
|
||
@app.route('/planets/add', methods=['POST']) | ||
def add_planet(): | ||
# Parse the JSON request data | ||
data = request.get_json() | ||
try: | ||
title = data['title'] | ||
if title: | ||
data = add_planet_to_DB(title) | ||
return jsonify(data), 201 | ||
except: | ||
return Response('''{"message": "Bad Request"}''', status=400, mimetype='application/json') | ||
address = data.get('address') | ||
|
||
# Check if address is provided | ||
if not address: | ||
return jsonify({'error': 'Address is required'}), 400 | ||
|
||
# Send a POST request to fetch geolocation using stored authentication | ||
response = requests.get( | ||
f'https://geocode.maps.co/search?q={address}', | ||
auth=auth | ||
) | ||
|
||
# Check if the request was successful | ||
if response.status_code == 200: | ||
geoloc_data = response.json() | ||
return jsonify(geoloc_data) | ||
else: | ||
return jsonify({'error': 'Geolocation fetch failed'}), 500 | ||
|
||
@app.route('/generator') | ||
def generate(): | ||
# Generate the figure **without using pyplot**. | ||
res = 2048 # see generate blueprint above | ||
"""fig = Figure() | ||
ax = fig.subplots() | ||
ax.plot([1, 2]) | ||
# Save it to a temporary buffer. | ||
buf = BytesIO() | ||
fig.savefig(buf, format="png") | ||
# Embed the result in the html output. | ||
data = base64.b64encode(buf.getbuffer()).decode("ascii") | ||
return f"<img src='data:image/png;base64,{data}'/>"""#" | ||
if __name__ == "__main__": | ||
app.run() |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.