-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprediction_api.py
38 lines (30 loc) · 1.24 KB
/
prediction_api.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
from flask import Flask, jsonify
from flask_restful import Resource, Api
import boto3
from boto3.dynamodb.conditions import Key
application = Flask(__name__)
api = Api(application)
TABLE_NAME = 'game_predictions'
class Predictions(Resource):
def get(self, home_team, away_team):
dynamo_conn = boto3.resource('dynamodb', region_name='us-east-2', aws_access_key_id='', aws_secret_access_key='')
table = dynamo_conn.Table(TABLE_NAME)
scan_kwargs = {
'FilterExpression': Key('HOME_TEAM').eq(home_team) & Key('AWAY_TEAM').eq(away_team),
'ProjectionExpression': "HOME_TEAM, AWAY_TEAM, WINNER, PROBABILITY",
# 'ExpressionAttributeNames': {"#yr": "year"}
}
done = False
start_key = None
while not done:
if start_key:
scan_kwargs['ExclusiveStartKey'] = start_key
response = table.scan(**scan_kwargs)
#display_movies(response.get('Items', []))
start_key = response.get('LastEvaluatedKey', None)
done = start_key is None
preds = response['Items']
return preds
api.add_resource(Predictions, '/get/<home_team>/<away_team>')
if __name__ == '__main__':
application.run(debug=True)