-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlambda_function.py
31 lines (25 loc) · 1005 Bytes
/
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
import json
import time
import requests
import boto3
from bs4 import BeautifulSoup
def lambda_handler(event, context):
session = boto3.Session()
client = session.client('timestream-write')
page = requests.get('https://money.cnn.com/data/fear-and-greed')
content = BeautifulSoup(page.content, 'html.parser')
fearGreedText = content.find(id='needleChart').select('li')[0].text
fearGreedValue = fearGreedText.split('Fear & Greed Now:')[1].split()[0]
record = {
'Dimensions': [{'Name': 'Name', 'Value': 'FearGreedIndex'}],
'MeasureName': 'FearGreedIndexValue',
'MeasureValue': fearGreedValue,
'MeasureValueType': 'BIGINT',
'Time': str(int(round(time.time() * 1000)))
}
client.write_records(DatabaseName='StockData', TableName='FearAndGreedIndex',
Records=[record], CommonAttributes={})
return {
'statusCode': 200,
'body': json.dumps('Complete')
}