Created
May 24, 2021 10:15
-
-
Save anna-anisienia/8dad962a1830c5c0cf05d7b44253a2dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import boto3 | |
import uuid | |
import time | |
import json | |
client = boto3.client('kinesis', region_name='eu-central-1') | |
partition_key = str(uuid.uuid4()) | |
def send_data_record(crypto="BTC"): | |
base_url = "https://min-api.cryptocompare.com/data" | |
r = requests.get(f"{base_url}/price?fsym={crypto}&tsyms=USD") | |
data = r.json() | |
data["timestamp"] = str(int(time.time())) | |
data["crypto"] = crypto | |
result = client.put_record(StreamName="crypto_prices", | |
Data=json.dumps(data), | |
PartitionKey=crypto) | |
print(result) | |
while True: | |
send_data_record("BTC") | |
send_data_record("ETH") | |
time.sleep(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment