sw-jobs-api/api/api.py

24 lines
590 B
Python
Raw Normal View History

2024-05-29 21:28:58 +00:00
from flask import Flask, jsonify
import json
import os
app = Flask(__name__)
2024-05-29 21:48:58 +00:00
# Path to your JSON file for production
2024-05-29 21:28:58 +00:00
db_file = os.path.join('scrapers', 'jobs_db.json')
2024-05-29 21:48:58 +00:00
# Path to db JSON file for development
#db_file = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'scrapers', 'jobs_db.json')
@app.route('/jobs', methods=['GET'])
2024-05-29 21:28:58 +00:00
def get_jobs():
if os.path.exists(db_file):
with open(db_file, 'r') as file:
jobs = json.load(file)
else:
jobs = []
return jsonify(jobs)
if __name__ == '__main__':
2024-05-29 23:20:54 +00:00
app.run(debug=False, host='0.0.0.0')