Created
February 9, 2016 19:11
-
-
Save Jzarecta/2cbb36f982ad4293e280 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
#!/bin/env python2 | |
__title__ = "TrendBot" | |
__author__ = "JZA" | |
__email__ = "[email protected]" | |
__license__ = "Apache Foundation License v2" | |
__version__ = "0.5 Alpha" | |
# TrendBot - A bot for checking out trend on the | |
# Bitcoin price. | |
import time, urllib2, json, os, dbus | |
from datetime import datetime | |
source='http://api.coindesk.com/v1/bpi/currentprice.json' | |
intervals=5 | |
price_list=[] | |
knotify= dbus.SessionBus().get_object("org.kde.knotify", "/Notify") | |
while intervals==5: | |
if intervals is None: | |
intervals=5 | |
coindesk=urllib2.urlopen(source) | |
data=coindesk.read() | |
jobject = json.loads(data, 'utf-8') | |
val=jobject['bpi']['USD']['rate'] | |
quote = u'{:,.2f}'.format(float(val), '.2f') | |
price_list.append(quote) | |
if len(price_list) > 4: | |
price_list.pop(0) | |
time.sleep(intervals*60) | |
else: | |
coindesk=urllib2.urlopen(source) | |
data=coindesk.read() | |
jobject = json.loads(data, 'utf-8') | |
val=jobject['bpi']['USD']['rate'] | |
quote = float(val) | |
price_list.append(quote) | |
if len(price_list) > 4: | |
price_list.pop(0) | |
time.sleep(intervals*60) | |
volatility=[y - x for x, y in zip(price_list, price_list[1:])] | |
if volatility and volatility[-1] > 0.8: | |
knotify.event("notification", "kde", [], "Aviso", "We are mooning "+ str(volatility[1]), [], [], 0, 0, dbus_interface="org.kde.KNotify") | |
elif volatility and volatility[-1] < -0.8: | |
knotify.event("warning", "kde", [], "Aviso", "Sell sell!!!"+ str(volatility[1]), [], [], 0, 0, dbus_interface="org.kde.KNotify") | |
timestamp= datetime.strftime(datetime.now(), '%H:%M') | |
print timestamp+ ' '+ str(volatility) | |
if all(items > 0 for items in volatility) == True: | |
knotify.event("notification", "kde", [], "Aviso", "Tendencia <strong>Positiva</strong> "+ str(sum(volatility)), [], [], 0, 0, dbus_interface="org.kde.KNotify") | |
# print 'Tendencia ' + '\033[1m' +'positiva'+'\033[0m' | |
elif all (items < 0 for items in volatility) == True: | |
knotify.event("warning", "kde", [], "Aviso", "Tendencia <strong>Negativa</strong> "+ str(sum(volatility)), [], [], 0, 0, dbus_interface="org.kde.KNotify") | |
else: | |
print 'Aun no hay tendencia' | |
#print price_list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment