Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. import requests
  2. import json
  3. from time import sleep
  4. from kafka import KafkaProducer
  5.  
  6. producer = KafkaProducer(bootstrap_servers=['master:9092'], api_version=(0, 10))
  7. value = (133,144,232,54,2482,33228)
  8. while True:
  9. try:
  10. for i in value:
  11. response = requests.get("https://api.coinlore.com/api/ticker/?id="+str(i))
  12. raw_stats = response.json()
  13. key_bytes = bytes(raw_stats[0]["name"], encoding='utf-8')
  14. value_bytes = bytes(raw_stats[0]["percent_change_1h"], encoding='utf-8')
  15.  
  16. producer.send('warchulCurrency', key=key_bytes, value=value_bytes)
  17. producer.flush()
  18.  
  19. print(raw_stats[0]["name"] + " - " + raw_stats[0]["percent_change_1h"])
  20. print()
  21. sleep(20)
  22. except:
  23. print("Blad")
  24.  
  25. producer.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement