Skip to content

Commit

Permalink
🍌🍫 ↝ Merge pull request #14 from Signal-K/GP-11-Create-microservice-f…
Browse files Browse the repository at this point in the history
…or-crafting-items

🍡🍌 ↝ 2 new microservices for planet content & crafting
  • Loading branch information
Gizmotronn authored Mar 11, 2024
2 parents 0f66522 + 8372915 commit 9fe94a6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
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)

0 comments on commit 9fe94a6

Please sign in to comment.