-
Notifications
You must be signed in to change notification settings - Fork 0
/
tweet.py
49 lines (37 loc) · 1.24 KB
/
tweet.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
import tweepy
import logging
from config import create_api
import time
import requests
import json
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger()
# Powered by CoinDesk
# BTC
response = requests.get('https://api.coindesk.com/v1/bpi/currentprice.json')
data = response.json()
print(data["bpi"]["USD"]["rate"])
# Powered by CoinGecko
# ETH
response_Eth = requests.get(
'https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd')
Eth = response_Eth.json()
print(Eth['ethereum']['usd'])
# DOGE
response_Doge = requests.get(
'https://api.coingecko.com/api/v3/simple/price?ids=dogecoin&vs_currencies=usd')
Doge = response_Doge.json()
print(Doge['dogecoin']['usd'])
# Tweet a Crypto update
def crypto_updates(api):
logger.info("Retrieving BTC, ETH, and DOGE updates")
api.update_status('Daily Crypto Report: $BTC is at $' + (
data["bpi"]["USD"]["rate"]) + ', $ETH is at $' + str((
Eth['ethereum']['usd'])) + ', $DOGE is at $' + str((Doge['dogecoin']['usd'])) + '. That is the current pricing today, remember to HODL! Vires in Numeris')
def main():
api = create_api()
while True:
crypto_updates(api)
time.sleep(24 * 3600)
if __name__ == "__main__":
main()