-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
22 lines (20 loc) · 898 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import requests
from flask import Flask, redirect, abort
from elg import Corpus
app = Flask(__name__)
@app.route("/<string:id>")
def web_service(id):
corpus = Corpus.from_id(id,auth_file="tokens.json")
corpus.authentication.refresh_if_needed()
headers = {"Authorization": f"Bearer {corpus.authentication.access_token}"}
headers["accept-licence"] = "True"
headers["filename"] = str(corpus.distributions[0].filename)
headers["elg-resource-distribution-id"] = str(corpus.distributions[0].pk)
response = requests.post(
f"https://live.european-language-grid.eu/catalogue_backend/api/management/download/{corpus.distributions[0].corpus_id}/",
headers=headers
)
if response.ok:
return redirect(response.json()["s3-url"], code=307)
else:
abort(500, f"Something went wrong when calling ELG API, response:{response.text}")