-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
25 lines (21 loc) · 889 Bytes
/
Copy pathapp.py
File metadata and controls
25 lines (21 loc) · 889 Bytes
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
from flask import Flask
from flask_cors import CORS, cross_origin
import requests
import os
import json
import urllib
app = Flask(__name__)
CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
@app.route('/pages/views/<path:keywords>/<start>/<end>')
@cross_origin()
def fetch_wikipedia_pageviews_metric(keywords, start, end):
encoded_keywords = urllib.parse.quote(keywords)
url = f"""https://wikimedia.org/api/rest_v1/metrics/pageviews/per-article/fr.wikipedia/all-access/user/{encoded_keywords}/daily/{start}/{end}"""
# 1st method: I don't know why it broke in the middle of january 2021
# response = requests.get(url, allow_redirects=True)
# print(f"response.text => {response.text}")
# json_object = response.json()
# 2nd method: I don't know why, but curl was working
json_object = json.loads(os.popen(f"curl {url}").read())
return json_object