-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrypto_fg_ifttt_request.py
36 lines (28 loc) · 1.13 KB
/
crypto_fg_ifttt_request.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
import requests
from datetime import datetime
def get_fng_data(url):
"""Gets latest BTC FNG index"""
try:
data = requests.get(url).json()
value = data.get('data')[0].get('value')
classification = data.get('data')[0].get('value_classification')
return value, classification
except IndexError as e:
print('[{}] {} {}'.format(datetime.now(), type(e), e))
def create_payload(index_value, classification):
"""Writes json payload with information to provide to IFTTT"""
dict = {"value1": classification, "value2": index_value}
return dict
def send_ifttt_request(event, api_key, data):
"""Sends event to IFTTT"""
maker_url = 'https://maker.ifttt.com/trigger/{}/with/key/{}'.format(event, api_key)
print("Sending request to IFTTT")
requests.post(maker_url, data=data)
if __name__ == '__main__':
api_key = 'YOURKEYHERE'
event = 'crypto_fg_index'
fng_url = 'https://api.alternative.me/fng/'
index_value, classification = get_fng_data(fng_url)
data = create_payload(index_value, classification)
send_ifttt_request(event, api_key, data)
# print(json_file)