Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🍡🍌 ↝ 2 new microservices for planet content & crafting #14

Merged
merged 3 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added lightcurve.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 33 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
from flask import Flask, jsonify, request
import atexit
from flask import Flask, jsonify, request, send_file
from supabase_py import create_client
from flask_cors import CORS
import io
import matplotlib.pyplot as plt
import matplotlib
import lightkurve as lk
import logging

app = Flask(__name__)
CORS(app)
matplotlib.use('Agg')

# Initialize Supabase client
SUPABASE_URL = 'https://qwbufbmxkjfaikoloudl.supabase.co'
Expand Down Expand Up @@ -69,5 +76,30 @@ def craft_structure():

return jsonify({'status': 'proceed', 'message': 'Structure crafted successfully'}), 200


# Set up logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

@app.route('/generate_lightcurve_image', methods=['POST'])
def generate_lightcurve_image():
try:
tic_id = request.json.get('tic_id')
if not tic_id:
raise ValueError('TIC ID not provided')

# Download lightcurve and create image
lc = lk.search_lightcurve(f"TIC {tic_id}").download().PDCSAP_FLUX
ax = lc.plot()
image_path = 'lightcurve.png'
ax.figure.savefig(image_path)

# Send image file to the frontend
return send_file(image_path, mimetype='image/png')

except Exception as e:
logger.exception('Error generating lightcurve image')
return jsonify({'status': 'error', 'message': str(e)}), 500

if __name__ == '__main__':
app.run(debug=True)