Skip to content

Instantly share code, notes, and snippets.

@anna-anisienia
Created May 24, 2021 10:16
Show Gist options
  • Save anna-anisienia/215d88ca41891d2094692f5a0bc4b94a to your computer and use it in GitHub Desktop.
Save anna-anisienia/215d88ca41891d2094692f5a0bc4b94a to your computer and use it in GitHub Desktop.
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"] = 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