-
Notifications
You must be signed in to change notification settings - Fork 1
/
extract_lambda_function.py
74 lines (54 loc) · 2.46 KB
/
extract_lambda_function.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
import json
import os
from botocore.vendored import requests
import requests
# import pandas as pd
import time
import boto3
from datetime import datetime
def lambda_handler(event, context):
# TODO implement
# get data NASDAQ:Composite from Yahoo finance
url = "https://apidojo-yahoo-finance-v1.p.rapidapi.com/stock/v3/get-chart"
querystring = {"interval":"1d","symbol":"^IXIC","range":"1mo","region":"US"
,"includePrePost":"false","useYfid":"true","includeAdjustedClose":"true"
,"events":"capitalGain,div,split"}
headers = {
"X-RapidAPI-Key": os.environ.get('XRapidAPIKey'),
"X-RapidAPI-Host": "apidojo-yahoo-finance-v1.p.rapidapi.com"
}
response = requests.get(url, headers=headers, params=querystring)
nasdaq_index = response.json()
# get data Vinfast and Tesla from Yahoo finance
url = "https://real-time-finance-data.p.rapidapi.com/stock-time-series"
querystring = {"symbol":"VFS:NASDAQ","period":"1M","language":"en"}
headers = {
"X-RapidAPI-Key": os.environ.get('XRapidAPIKey'),
"X-RapidAPI-Host": "real-time-finance-data.p.rapidapi.com"
}
response = requests.get(url, headers=headers, params=querystring)
data_vinfast = response.json()
querystring = {"symbol":"TSLA:NASDAQ","period":"1M","language":"en"}
headers = {
"X-RapidAPI-Key": os.environ.get('XRapidAPIKey'),
"X-RapidAPI-Host": "real-time-finance-data.p.rapidapi.com"
}
response = requests.get(url, headers=headers, params=querystring)
data_tesla = response.json()
# send dat to AWS S3
s3 = boto3.client('s3')
data = json.dumps(nasdaq_index)
filename_nasdaq = "rapidapicoin_raw_nasdaq_index"+str(datetime.now()) +'.json'
s3.put_object( Body= data,
Bucket="nasdaq-index-etl",
Key="raw_data/to_processed/"+filename_nasdaq)
data = json.dumps(data_vinfast)
filename_vinfast = "rapidapicoin_raw_vinfast"+str(datetime.now()) +'.json'
s3.put_object( Body= data,
Bucket="nasdaq-index-etl",
Key="raw_data/to_processed/"+filename_vinfast)
data = json.dumps(data_tesla)
filename_tesla = "rapidapicoin_raw_tesla"+str(datetime.now()) +'.json'
s3.put_object( Body= data,
Bucket="nasdaq-index-etl",
Key="raw_data/to_processed/"+filename_tesla)