-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
29 lines (23 loc) · 895 Bytes
/
server.py
File metadata and controls
29 lines (23 loc) · 895 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
26
27
28
29
from flask import Flask
from flask_cors import CORS
import os
from github_query.model.authentication import PersonalAccessTokenAuthenticator
from github_query.github_graphql.github_client import GitHubClient
from github_query.queries.contributions.user_login import UserLogin
app = Flask(__name__)
# Allow all origins to access routes with '/api/' prefix
CORS(app, resources={r"/api/*": {"origins": "*"}})
# Initialize GitHub client
client = GitHubClient(
host="api.github.com", is_enterprise=False,
authenticator=PersonalAccessTokenAuthenticator(token=os.environ.get("GITHUB_PERSONAL_ACCESS_TOKEN"))
)
@app.route('/api/github/userlogin')
def fetch_github_data():
response = client.execute(
query=UserLogin(), substitutions={"user": "torvalds"}
)
return response
# Run the app on 0.0.0.0
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)