From ff2b08fc2d2b3f9069c8c9142c3535a2a7c28e7e Mon Sep 17 00:00:00 2001 From: Dylan De Faoite Date: Tue, 27 Jan 2026 11:50:56 +0000 Subject: [PATCH] update gitignore --- .gitignore | 6 +++++- server/app.py | 29 ++++++++++++++++++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 22d887a..6c77293 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,8 @@ __pycache__/ *.pyc *.jsonl *.code-workspace -.env \ No newline at end of file +.env + +# React App Vite +node_modules/ +dist/ \ No newline at end of file diff --git a/server/app.py b/server/app.py index 7d89cee..053e813 100644 --- a/server/app.py +++ b/server/app.py @@ -1,14 +1,29 @@ -from flask import Flask -from connectors.reddit_api import RedditAPI +from flask import Flask, jsonify, request +import pandas as pd app = Flask(__name__) -reddit_connector = RedditAPI() +@app.route('/upload', methods=['POST']) +def upload_data(): + if "file" not in request.files: + return jsonify({"error": "No file part in the request"}), 400 + + file = request.files["file"] -@app.route('/fetch_subreddit//', methods=['GET']) -def fetch_subreddit(subreddit, limit = 10): - posts = reddit_connector.get_top_subreddit_posts(subreddit, limit=limit, timeframe='all') - return {"status": "success", "posts": [post.__dict__ for post in posts]} + if file.filename == "": + return jsonify({"error": "Empty filename"}), 400 + + if not file.filename.endswith('.jsonl'): + return jsonify({"error": "Invalid file type. Only .jsonl files are allowed."}), 400 + + try: + df = pd.read_json(file, lines=True) + except ValueError as e: + return jsonify({"error": f"Failed to read JSONL file: {str(e)}"}), 400 + except Exception as e: + return jsonify({"error": f"An unexpected error occurred: {str(e)}"}), 500 + + return jsonify({"message": "File uploaded successfully", "data_preview": df.head().to_dict(orient='records')}), 200 if __name__ == "__main__": app.run(debug=True) \ No newline at end of file