-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
87 lines (61 loc) · 2.31 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import sentry_sdk
from sentry_sdk.integrations.flask import FlaskIntegration
from flask import Flask, request, jsonify
from flask_cors import CORS
from dotenv import load_dotenv
import os
load_dotenv()
from apis.authors import fetch_author
from apis.batch import generate_and_store_topics
from apis.single import enrich_single
from apis.creators import get_creator_bio
from apis.descriptions import get_description
sentry_key = os.getenv("SENTRY_KEY")
sentry_org = os.getenv("SENTRY_ORG")
sentry_project = os.getenv("SENTRY_PROJECT")
if os.getenv("FLASK_ENV") != "development":
sentry_sdk.init(
dsn=f"https://{sentry_key}@{sentry_org}.ingest.sentry.io/{sentry_project}",
integrations=[FlaskIntegration()],
)
app = Flask(__name__)
cors = CORS(app, resources={r"/api/*": {"origins": "*"}})
@app.route("/")
def welcome():
return "Data Enrichment API"
@app.route("/author")
def author_enrichment():
name = request.args.get("name")
work = request.args.get("work")
enriched_author = fetch_author(name, work)
return jsonify(creator=enriched_author)
@app.route("/creator")
def creator_enrichment():
name = request.args.get("name")
work = request.args.get("work")
enriched_creator = get_creator_bio(name, work)
return jsonify(creator=enriched_creator)
@app.route("/description")
def description_enrichment():
work = request.args.get("work")
creatorList = request.args.getlist("creators")
enriched_description = get_description(work, creatorList)
return jsonify(description=enriched_description)
@app.route("/topics")
def topic_enrichment():
medium = request.args.get("medium")
title = request.args.get("title")
specifier = request.args.get("specifier")
enriched_topics = enrich_single(medium, title, specifier)
return jsonify(topics=enriched_topics)
@app.route("/batch_topics", methods=["POST"])
def batch_enrichment():
data = request.get_json()
batch = data.get("batch")
if not batch:
return jsonify({"error": "No batch data provided"}), 400
generate_and_store_topics(batch)
return jsonify({"message": "Successfully processed contents"}), 200
if __name__ == "__main__":
port = int(os.environ.get("PORT", 8000))
app.run(port=port)