forked from jj9btcproj/CryptoCoin-Price-Indicator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcryptocoin-price-indicator.py
executable file
·742 lines (659 loc) · 31.4 KB
/
cryptocoin-price-indicator.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
#!/usr/bin/env python
# CryptoCoin-Price-Indicator
#--------------------------------------
# by jj9,
#
# generalizes and combines old btc version enhanced by RichHorrocks and Zapsoda (btcapicalls/setupfile maintainance for old btc version) and ltc version
#
# if you feel the need to share some bitcoin thanks or love
# do so here. If you use this please credit it
#
# send any donations
# BTC : 1ECXwPU9umqtsBAQesBW9981mx6sipPmyL
# LTC : LUJz8yaS4uL1zrzwARbA4CiMpAwbpUwWY6
# NMC : N1SKXkrcyhxVYwQGsbLTFMbGAgeqL2g9tZ
import sys
import gtk
import appindicator
import urllib2
import json
import os
from os.path import expanduser
HOME = expanduser("~")
SETTINGSFILE = os.path.abspath(HOME+"/.local/share/applications/settingsCryptoIndicator.dat")
BAD_RETRIEVE = 0.00001
class CryptoCoinPriceIndicator:
PING_FREQUENCY = 1 # seconds
BTCICON = os.path.abspath(HOME+"/.local/share/applications/bitcoinicon.png")
LTCICON = os.path.abspath(HOME+"/.local/share/applications/litecoinicon.png")
NMCICON = os.path.abspath(HOME+"/.local/share/applications/nmcicon.png")
PPCICON = os.path.abspath(HOME+"/.local/share/applications/peercoinicon.png")
YACICON = os.path.abspath(HOME+"/.local/share/applications/yacoinicon.png")
APPDIR = HOME+"/.local/share/applications/"
APPNAME = 'CryptoCoin Indicator';VERSION = '0.5'
BTCMODE = True; BTCInit = False;
LTCMODE = True; LTCInit = False;
NMCMODE = True; NMCInit = False;
PPCMODE = True; PPCInit = False;
YACMODE = True; YACInit = False;
def __init__(self):
self.initFromFile()
self.ind = appindicator.Indicator("new-bitcoin-indicator", self.BTCICON,appindicator.CATEGORY_APPLICATION_STATUS)
self.ind.set_status(appindicator.STATUS_ACTIVE)
self.menu_setup()
self.ind.set_menu(self.menu)
def main(self):
self.updateIndicators()
if self.BTCMODE:
gtk.timeout_add(self.PING_FREQUENCY * 1000, self.getNewPricesBTC)
if self.LTCMODE:
gtk.timeout_add(self.PING_FREQUENCY * 1000, self.getNewPricesLTC)
if self.NMCMODE:
gtk.timeout_add(self.PING_FREQUENCY * 1000, self.getNewPricesNMC)
if self.PPCMODE:
gtk.timeout_add(self.PING_FREQUENCY * 1000, self.getNewPricesPPC)
if self.YACMODE:
gtk.timeout_add(self.PING_FREQUENCY * 1000, self.getNewPricesYAC)
gtk.main()
def updateIndicators(self):
if self.BTCMODE:
self.updateBTCIndicator()
if self.LTCMODE:
self.updateLTCIndicator()
if self.NMCMODE:
self.updateNMCIndicator()
if self.PPCMODE:
self.updatePPCIndicator()
if self.YACMODE:
self.updateYACIndicator()
def updateBTCIndicator(self):
self.getNewPricesBTC()
def updateLTCIndicator(self):
self.getNewPricesLTC()
def updateNMCIndicator(self):
self.getNewPricesNMC()
def updatePPCIndicator(self):
self.getNewPricesPPC()
def updateYACIndicator(self):
self.getNewPricesYAC()
def initLTCAddOn(self,widget):
if (not self.LTCInit) or (widget is None):
self.indLTC = appindicator.Indicator("new-litecoin-indicator", self.LTCICON, appindicator.CATEGORY_APPLICATION_STATUS)
self.indLTC.set_status(appindicator.STATUS_ACTIVE)
self.menu_setupLTC()
self.indLTC.set_menu(self.menuLTC)
if (not self.LTCMODE) and (widget is not None):
self.LTCMODE = True
gtk.timeout_add(self.PING_FREQUENCY * 1000, self.getNewPricesLTC)
print "LTC Mode now On"
else:
self.noLTC(widget)
def initNMCAddOn(self,widget):
if (not self.NMCInit) or (widget is None):
self.indNMC = appindicator.Indicator("new-nmccoin-indicator", self.NMCICON, appindicator.CATEGORY_APPLICATION_STATUS)
self.indNMC.set_status(appindicator.STATUS_ACTIVE)
self.menu_setupNMC()
self.indNMC.set_menu(self.menuNMC)
if (not self.NMCMODE) and (widget is not None):
self.NMCMODE = True
gtk.timeout_add(self.PING_FREQUENCY * 1000, self.getNewPricesNMC)
print "NMC Mode now On"
else:
self.noNMC(widget)
def initPPCAddOn(self,widget):
if (not self.PPCInit) or (widget is None):
self.indPPC = appindicator.Indicator("new-ppccoin-indicator", self.PPCICON, appindicator.CATEGORY_APPLICATION_STATUS)
self.indPPC.set_status(appindicator.STATUS_ACTIVE)
self.menu_setupPPC()
self.indPPC.set_menu(self.menuPPC)
if (not self.PPCMODE) and (widget is not None):
self.PPCMODE = True
gtk.timeout_add(self.PING_FREQUENCY * 1000, self.getNewPricesPPC)
print "PPC Mode now On"
else:
self.noPPC(widget)
def initYACAddOn(self,widget):
if (not self.YACInit) or (widget is None):
self.indYAC = appindicator.Indicator("new-yaccoin-indicator", self.YACICON, appindicator.CATEGORY_APPLICATION_STATUS)
self.indYAC.set_status(appindicator.STATUS_ACTIVE)
self.menu_setupYAC()
self.indYAC.set_menu(self.menuYAC)
if (not self.YACMODE) and (widget is not None):
self.YACMODE = True
gtk.timeout_add(self.PING_FREQUENCY * 1000, self.getNewPricesYAC)
print "YAC Mode now On"
else:
self.noYAC(widget)
# setup gtk menus to toggle display of data
def menu_setup(self):
self.menu = gtk.Menu()
self.BTCtickers = None
self.btceBTC = gtk.RadioMenuItem(self.BTCtickers,"BTC-E"); self.btceBTC.connect("activate", lambda x: self.toggleBTCdisplay("btce")); self.btceBTC.show()
self.BTCtickers = self.btceBTC
self.mtgoxBTC = gtk.RadioMenuItem(self.BTCtickers,"MtGox"); self.mtgoxBTC.connect("activate", lambda x: self.toggleBTCdisplay("mtgox")); self.mtgoxBTC.show()
self.BTCtickers = self.mtgoxBTC
self.bitstampBTC = gtk.RadioMenuItem(self.BTCtickers,"BitStamp"); self.bitstampBTC.connect("activate", lambda x: self.toggleBTCdisplay("bitstamp")); self.bitstampBTC.show()
self.BTCtickers = self.bitstampBTC
self.blockchainBTC = gtk.RadioMenuItem(self.BTCtickers,"BlockChain"); self.blockchainBTC.connect("activate", lambda x: self.toggleBTCdisplay("blockchain")); self.blockchainBTC.show()
self.BTCtickers = self.blockchainBTC
self.defSet = gtk.MenuItem("Choose exchange : "); self.defSet.show()
self.menu.append(self.defSet)
self.menu.append(self.mtgoxBTC); self.menu.append(self.btceBTC)
self.menu.append(self.bitstampBTC); self.menu.append(self.blockchainBTC)
self.setRefreshMenu(self.menu)
self.ltcAdd = gtk.CheckMenuItem("LTC Price"); self.ltcAdd.connect("activate", self.initLTCAddOn);
if self.LTCMODE:
self.ltcAdd.activate();
self.ltcAdd.show();self.menu.append(self.ltcAdd)
self.nmcAdd = gtk.CheckMenuItem("NMC Price"); self.nmcAdd.connect("activate", self.initNMCAddOn);
if self.NMCMODE:
self.nmcAdd.activate();
self.nmcAdd.show();self.menu.append(self.nmcAdd)
self.ppcAdd = gtk.CheckMenuItem("PPC Price"); self.ppcAdd.connect("activate", self.initPPCAddOn);
if self.PPCMODE:
self.ppcAdd.activate();
self.ppcAdd.show();self.menu.append(self.ppcAdd)
self.yacAdd = gtk.CheckMenuItem("YAC Price"); self.yacAdd.connect("activate", self.initYACAddOn);
if self.YACMODE:
self.yacAdd.activate();
self.yacAdd.show();self.menu.append(self.yacAdd)
self.getNewPricesBTC()
self.about = gtk.MenuItem("About"); self.about.connect("activate",self.menu_about_response);self.about.show()
self.menu.append(self.about)
self.quit_item = gtk.MenuItem("Quit Indicator"); self.quit_item.connect("activate", self.quit); self.quit_item.show()
self.menu.append(self.quit_item)
def menu_setupLTC(self):
self.menuLTC = gtk.Menu()
self.LTCtickers = None
self.btceLTC = gtk.RadioMenuItem(self.LTCtickers,"BTC-E"); self.btceLTC.connect("activate", lambda x: self.toggleLTCdisplay("btce")); self.btceLTC.show()
self.LTCtickers = self.btceLTC
#self.mtgoxLTC = gtk.RadioMenuItem(self.LTCtickers,"MtGox"); self.mtgoxLTC.connect("activate", lambda x: self.toggleLTCdisplay("mtgox")); self.mtgoxLTC.show()
#self.BTCtickers = self.mtgoxBTC
defSetLTC = gtk.MenuItem("Choose exchange : "); defSetLTC.show()
self.menuLTC.append(defSetLTC)
self.menuLTC.append(self.btceLTC);#self.menuLTC.append(self.mtgoxLTC);
self.setRefreshMenu(self.menuLTC)
self.getNewPricesLTC()
self.kill_LTC = gtk.MenuItem("LTC Off"); self.kill_LTC.connect("activate", self.noLTC); self.kill_LTC.show(); self.menuLTC.append(self.kill_LTC)
self.quit_item = gtk.MenuItem("Quit Indicator"); self.quit_item.connect("activate", self.quit); self.quit_item.show()
self.menuLTC.append(self.quit_item)
self.LTCInit = True
def menu_setupNMC(self):
self.menuNMC = gtk.Menu()
self.NMCtickers = None
self.btceNMC = gtk.RadioMenuItem(self.NMCtickers,"BTC-E"); self.btceNMC.connect("activate", lambda x: self.toggleNMCdisplay("btce")); self.btceNMC.show()
self.NMCtickers = self.btceNMC
#self.mtgoxLTC = gtk.RadioMenuItem(self.LTCtickers,"MtGox"); self.mtgoxLTC.connect("activate", lambda x: self.toggleLTCdisplay("mtgox")); self.mtgoxLTC.show()
#self.BTCtickers = self.mtgoxBTC
defSetNMC = gtk.MenuItem("Choose exchange : "); defSetNMC.show()
self.menuNMC.append(defSetNMC)
self.menuNMC.append(self.btceNMC);#self.menuLTC.append(self.mtgoxLTC);
self.setRefreshMenu(self.menuNMC)
self.getNewPricesNMC()
self.kill_NMC = gtk.MenuItem("NMC Off"); self.kill_NMC.connect("activate", self.noNMC); self.kill_NMC.show();self.menuNMC.append(self.kill_NMC)
self.quit_item = gtk.MenuItem("Quit Indicator"); self.quit_item.connect("activate", self.quit); self.quit_item.show()
self.menuNMC.append(self.quit_item)
self.NMCInit = True
def menu_setupPPC(self):
self.menuPPC = gtk.Menu()
self.PPCtickers = None
self.btcePPC = gtk.RadioMenuItem(self.PPCtickers,"BTC-E"); self.btcePPC.connect("activate", lambda x: self.toggleNMCdisplay("btce")); self.btcePPC.show()
self.PPCtickers = self.btcePPC
#self.mtgoxLTC = gtk.RadioMenuItem(self.LTCtickers,"MtGox"); self.mtgoxLTC.connect("activate", lambda x: self.toggleLTCdisplay("mtgox")); self.mtgoxLTC.show()
#self.BTCtickers = self.mtgoxBTC
defSetPPC = gtk.MenuItem("Choose exchange : "); defSetPPC.show()
self.menuPPC.append(defSetPPC)
self.menuPPC.append(self.btcePPC);#self.menuLTC.append(self.mtgoxLTC);
self.setRefreshMenu(self.menuPPC)
self.getNewPricesPPC()
self.kill_PPC = gtk.MenuItem("PPC Off"); self.kill_PPC.connect("activate", self.noPPC); self.kill_PPC.show();self.menuPPC.append(self.kill_PPC)
self.quit_item = gtk.MenuItem("Quit Indicator"); self.quit_item.connect("activate", self.quit); self.quit_item.show()
self.menuPPC.append(self.quit_item)
self.PPCInit = True
def menu_setupYAC(self):
self.menuYAC = gtk.Menu()
self.YACtickers = None
self.bterYAC = gtk.RadioMenuItem(self.YACtickers,"Bter"); self.bterYAC.connect("activate", lambda x: self.toggleYACdisplay("bter")); self.bterYAC.show()
self.YACtickers = self.bterYAC
#self.mtgoxLTC = gtk.RadioMenuItem(self.LTCtickers,"MtGox"); self.mtgoxLTC.connect("activate", lambda x: self.toggleLTCdisplay("mtgox")); self.mtgoxLTC.show()
#self.BTCtickers = self.mtgoxBTC
defSetYAC = gtk.MenuItem("Choose exchange : "); defSetYAC.show()
self.menuYAC.append(defSetYAC)
self.menuYAC.append(self.bterYAC);#self.menuLTC.append(self.mtgoxLTC);
self.setRefreshMenu(self.menuYAC)
self.getNewPricesYAC()
self.kill_YAC = gtk.MenuItem("YAC Off"); self.kill_YAC.connect("activate", self.noYAC); self.kill_YAC.show();self.menuYAC.append(self.kill_YAC)
self.quit_item = gtk.MenuItem("Quit Indicator"); self.quit_item.connect("activate", self.quit); self.quit_item.show()
self.menuYAC.append(self.quit_item)
self.YACInit = True
def noLTC(self,widget):
self.indLTC.set_label("")
self.indLTC.set_icon("")
self.LTCMODE = False
self.LTCInit = False
def noNMC(self,widget):
self.indNMC.set_label("")
self.indNMC.set_icon("")
self.NMCMODE = False
self.NMCInit = False
def noPPC(self,widget):
self.indPPC.set_label("")
self.indPPC.set_icon("")
self.PPCMODE = False
self.PPCInit = False
def noYAC(self,widget):
self.indYAC.set_label("")
self.indYAC.set_icon("")
self.YACMODE = False
self.YACInit = False
def setRefreshMenu(self,menuIn):
refreshmenu = gtk.Menu()
refMenu =gtk.MenuItem("Set refresh rate :")
refMenu.set_submenu(refreshmenu)
self.refreshRates = None
menuRefresh1 = gtk.RadioMenuItem(self.refreshRates,"3s"); menuRefresh1.connect("activate",lambda x: self.setPing(3)); menuRefresh1.show()
self.refreshRates = menuRefresh1
menuRefresh2 = gtk.RadioMenuItem(self.refreshRates,"10s"); menuRefresh2.connect("activate",lambda x: self.setPing(10)); menuRefresh2.show()
self.refreshRates = menuRefresh2
menuRefresh3 = gtk.RadioMenuItem(self.refreshRates,"30s"); menuRefresh3.connect("activate",lambda x: self.setPing(30)); menuRefresh3.show()
self.refreshRates = menuRefresh3
menuRefresh4 = gtk.RadioMenuItem(self.refreshRates,"1m"); menuRefresh4.connect("activate",lambda x: self.setPing(60)); menuRefresh4.show()
self.refreshRates = menuRefresh4
menuRefresh5 = gtk.RadioMenuItem(self.refreshRates,"5m"); menuRefresh5.connect("activate",lambda x: self.setPing(300)); menuRefresh5.show()
self.refreshRates = menuRefresh5
menuRefresh6 = gtk.RadioMenuItem(self.refreshRates,"10m"); menuRefresh6.connect("activate",lambda x: self.setPing(600)); menuRefresh6.show()
self.refreshRates = menuRefresh6;
refreshmenu.append(menuRefresh1);refreshmenu.append(menuRefresh2);refreshmenu.append(menuRefresh3);
refreshmenu.append(menuRefresh4);refreshmenu.append(menuRefresh5);refreshmenu.append(menuRefresh6);
refMenu.show(); refreshmenu.show()
menuIn.append(refMenu)
def setPing(self,newTime):
self.PING_FREQUENCY = newTime
# toggle function for exchanges
def toggleBTCdisplay(self, exch):
self.exchange = exch
# toggle function for exchanges
def toggleLTCdisplay(self, exch):
self.exchangeLTC = exch
# toggle function for exchanges
def toggleNMCdisplay(self, exch):
self.exchangeNMC = exch
# toggle function for exchanges
def togglePPCdisplay(self, exch):
self.exchangePPC = exch
# toggle function for exchanges
def toggleYACdisplay(self, exch):
self.exchangeYAC = exch
# function that is being called by main which will refresh data
def getNewPricesBTC(self):
updatedRecently = self.update_priceBTC()
return True
def getNewPricesLTC(self):
updatedRecentlyLTC = self.update_priceLTC()
return True
def getNewPricesNMC(self):
updatedRecentlyNMC = self.update_priceNMC()
return True
def getNewPricesPPC(self):
updatedRecentlyPPC = self.update_pricePPC()
return True
def getNewPricesYAC(self):
updatedRecentlyYAC = self.update_priceYAC()
return True
# build string to be used by indicator and update the display label
def update_priceBTC(self):
dataOut = ""
priceNow = BAD_RETRIEVE
priceNow = self.getMtGoxData("")
if priceNow == BAD_RETRIEVE:
priceNow = "TempDown"
else:
priceNow = str(priceNow)+" USD"
if "mtgox" in self.exchange:
dataOut = dataOut + ' | ' if dataOut != "" else dataOut
dataOut = dataOut + "MtGox: "+priceNow
self.mtgoxBTC.set_label("MtGox| "+str(priceNow))
priceNow = self.getBTCEDataUSD("")
if priceNow == BAD_RETRIEVE:
priceNow = "TempDown"
else:
priceNow = str(priceNow)+" USD"
if "btce" in self.exchange:
dataOut = dataOut + ' | ' if dataOut != "" else dataOut
dataOut = dataOut + "BTC-E: "+priceNow
self.btceBTC.set_label("BTC-E | "+str(priceNow))
priceNow = self.getBitStampBTCPrice()
if priceNow == BAD_RETRIEVE:
priceNow = "TempDown"
else:
priceNow = str(priceNow)+" USD"
if "bitstamp" in self.exchange:
dataOut = dataOut + ' | ' if dataOut != "" else dataOut
dataOut = dataOut + "Bitstamp: "+priceNow
self.bitstampBTC.set_label("Bitstamp | "+str(priceNow))
priceNow = self.getBlockChainBTCPrice()
if priceNow == BAD_RETRIEVE:
priceNow = "TempDown"
else:
priceNow = str(priceNow)+" USD"
if "blockchain" in self.exchange:
dataOut = dataOut + ' | ' if dataOut != "" else dataOut
dataOut = dataOut + "Blockchain: "+priceNow
self.blockchainBTC.set_label("Blockchain | "+str(priceNow))
self.ind.set_label(dataOut)
return True
# build string to be used by indicator and update the display label
def update_priceLTC(self):
dataOut = ""
priceNow = BAD_RETRIEVE
#priceNow = self.getMtGoxData("ltc")
#if priceNow == BAD_RETRIEVE:
# priceNow = "TempDown"
#else:
# priceNow = str(priceNow)+" USD"
#if self.exchangeLTC is "mtgox":
# dataOut = dataOut + ' | ' if dataOut != "" else dataOut
# dataOut = dataOut + "MtGox: "+priceNow
#self.mtgoxLTC.set_label("MtGox| "+str(priceNow))
priceNow = self.getBTCEDataUSD("ltc")
if priceNow == BAD_RETRIEVE:
priceNow = "TempDown"
else:
priceNow = str(priceNow)+" USD"
if "btce" in self.exchangeLTC:
dataOut = dataOut + ' | ' if dataOut != "" else dataOut
dataOut = dataOut + "BTC-E: "+priceNow
self.btceLTC.set_label("BTC-E | "+str(priceNow))
if self.LTCMODE:
self.indLTC.set_label(dataOut)
return True
# build string to be used by indicator and update the display label
def update_priceNMC(self):
dataOut = ""
priceNow = BAD_RETRIEVE
priceNow = self.getBTCEDataUSD("nmc")
if priceNow == BAD_RETRIEVE:
priceNow = "TempDown"
else:
priceNow = str(priceNow)+" USD"
if "btce" in self.exchangeNMC:
dataOut = dataOut + ' | ' if dataOut != "" else dataOut
dataOut = dataOut + "BTC-E: "+priceNow
self.btceNMC.set_label("BTC-E | "+str(priceNow))
if self.NMCMODE:
self.indNMC.set_label(dataOut)
return True
# build string to be used by indicator and update the display label
def update_pricePPC(self):
dataOut = ""
priceNow = BAD_RETRIEVE
priceNow = self.getBTCEDataUSD("ppc")
if priceNow == BAD_RETRIEVE:
priceNow = "TempDown"
else:
priceNow = str(priceNow)+" USD"
if "btce" in self.exchangePPC:
dataOut = dataOut + ' | ' if dataOut != "" else dataOut
dataOut = dataOut + "BTC-E: "+priceNow
self.btcePPC.set_label("BTC-E | "+str(priceNow))
if self.PPCMODE:
self.indPPC.set_label(dataOut)
return True
# build string to be used by indicator and update the display label
def update_priceYAC(self):
dataOut = ""
priceNow = BAD_RETRIEVE
priceNow = self.getBterDataBTC("yac")
if priceNow == BAD_RETRIEVE:
priceNow = "TempDown"
else:
priceNow = str(priceNow)+" USD"
if "bter" in self.exchangeYAC:
dataOut = dataOut + ' | ' if dataOut != "" else dataOut
dataOut = dataOut + "Bter: "+priceNow
self.bterYAC.set_label("Bter | "+str(priceNow))
if self.YACMODE:
self.indYAC.set_label(dataOut)
return True
# get mtgox data using JSON
def getMtGoxData(self,coin):
lstMtGox = BAD_RETRIEVE
try :
if coin is "ltc":
web_page = urllib2.urlopen("http://data.mtgox.com/api/1/LTCUSD/ticker").read()
elif coin is "nmc":
web_page = urllib2.urlopen("http://data.mtgox.com/api/1/NMCUSD/ticker").read()
else:
web_page = urllib2.urlopen("http://data.mtgox.com/api/1/BTCUSD/ticker").read()
data = json.loads(web_page)
lstMtGox = data['return']['last']['value']
except urllib2.HTTPError :
print("HTTPERROR!")
except urllib2.URLError :
print("URLERROR!")
except ValueError: # includes simplejson.decoder.JSONDecodeError
print 'Decoding JSON has failed'
return "{0:,.2f}".format(float(lstMtGox))
# get btc-e data using json
def getBTCEDataUSD(self,coin):
lstBTCEprice = BAD_RETRIEVE
try :
if coin is "ltc":
web_page = urllib2.urlopen("https://btc-e.com/api/2/ltc_usd/ticker").read()
elif coin is "nmc":
web_page = urllib2.urlopen("https://btc-e.com/api/2/nmc_usd/ticker").read()
elif coin is "ppc":
web_page = urllib2.urlopen("https://btc-e.com/api/2/ppc_usd/ticker").read()
else:
web_page = urllib2.urlopen("https://btc-e.com/api/2/btc_usd/ticker").read()
data = json.loads(web_page)
lstBTCEprice = data['ticker']['last']
except urllib2.HTTPError :
print("HTTPERROR!")
except urllib2.URLError :
print("URLERROR!")
return "{0:,.2f}".format(float(lstBTCEprice))
# get btc-e data using json
def getBTCEDataEUR(self,coin):
lstBTCEprice = BAD_RETRIEVE
try :
if coin is "ltc":
web_page = urllib2.urlopen("https://btc-e.com/api/2/ltc_eur/ticker").read()
else:
web_page = urllib2.urlopen("https://btc-e.com/api/2/btc_eur/ticker").read()
data = json.loads(web_page)
lstBTCEprice = data['ticker']['last']
except urllib2.HTTPError :
print("HTTPERROR!")
except urllib2.URLError :
print("URLERROR!")
return "{0:,.2f}".format(float(lstBTCEprice))
# get btc-e data using json
def getBTCEDataBTC(self,coin):
lstBTCEprice = BAD_RETRIEVE
try :
if coin is "nmc":
web_page = urllib2.urlopen("https://btc-e.com/api/2/nmc_btc/ticker").read()
elif coin is "nvc":
web_page = urllib2.urlopen("https://btc-e.com/api/2/nvc_btc/ticker").read()
elif coin is "xpm":
web_page = urllib2.urlopen("https://btc-e.com/api/2/xom_btc/ticker").read()
elif coin is "ftc":
web_page = urllib2.urlopen("https://btc-e.com/api/2/ftc_btc/ticker").read()
elif coin is "ppc":
web_page = urllib2.urlopen("https://btc-e.com/api/2/ppc_btc/ticker").read()
else:
web_page = urllib2.urlopen("https://btc-e.com/api/2/ltc_btc/ticker").read()
data = json.loads(web_page)
lstBTCEprice = data['ticker']['last']
except urllib2.HTTPError :
print("HTTPERROR!")
except urllib2.URLError :
print("URLERROR!")
return "{0:,.2f}".format(float(lstBTCEprice))
# get bter data using json
def getBterDataBTC(self,coin):
lstBterprice = BAD_RETRIEVE
try :
if coin is "nmc":
web_page = urllib2.urlopen("http://data.bter.com/api/1/ticker/nmc_btc").read()
elif coin is "yac":
web_page = urllib2.urlopen("http://data.bter.com/api/1/ticker/yac_btc").read()
elif coin is "nvc":
web_page = urllib2.urlopen("http://data.bter.com/api/1/ticker/nvc_btc").read()
elif coin is "xpm":
web_page = urllib2.urlopen("http://data.bter.com/api/1/ticker/xpm_btc").read()
elif coin is "ftc":
web_page = urllib2.urlopen("http://data.bter.com/api/1/ticker/ftc_btc").read()
elif coin is "ppc":
web_page = urllib2.urlopen("http://data.bter.com/api/1/ticker/ppc_btc").read()
else:
web_page = urllib2.urlopen("http://data.bter.com/api/1/ticker/ltc_btc").read()
data = json.loads(web_page)
lstBterprice = data['last']
except urllib2.HTTPError :
print("HTTPERROR!")
except urllib2.URLError :
print("URLERROR!")
return "{0:,.2f}".format(float(lstBterprice))
# get BlockChain data using json
def getBlockChainBTCPrice(self):
lstBlockChain = BAD_RETRIEVE
try :
web_page = urllib2.urlopen("https://blockchain.info/ticker").read()
data = json.loads(web_page)
lstBlockChain = data['USD']['last']
except urllib2.HTTPError :
print("HTTPERROR!")
except urllib2.URLError :
print("URLERROR!")
except ValueError: # includes simplejson.decoder.JSONDecodeError
print 'Decoding JSON has failed'
return "{0:,.2f}".format(float(lstBlockChain))
# get BitStamp data using json
def getBitStampBTCPrice(self):
lstBitStamp = BAD_RETRIEVE
try :
web_page = urllib2.urlopen("https://www.bitstamp.net/api/ticker/").read()
data = json.loads(web_page)
lstBitStamp = data['last']
except urllib2.HTTPError :
print("HTTPERROR!")
except urllib2.URLError :
print("URLERROR!")
except ValueError: # includes simplejson.decoder.JSONDecodeError
print 'Decoding JSON has failed'
return "{0:,.2f}".format(float(lstBitStamp))
#############################################
##########Settings###File####################
#############################################
# grab settings from file
def initFromFile(self):
try:
with open(SETTINGSFILE): pass
except IOError:
print 'Need to make new file.'
file = open(SETTINGSFILE, 'w')
file.write(os.getcwd()+'\n')
file.write('10 \n')
file.write('mtgox \n')
file.write('True \n')
file.write('btce \n')
file.write('True \n')
file.write('btce \n')
file.write('True \n')
file.write('btce \n')
file.write('True \n')
file.write('bter \n')
file.write('True \n')
file.close()
f = open(SETTINGSFILE, 'r')
lines = f.readlines()
currDir = (lines[0].strip())
if ".local/share/applicatins" not in currDir:
self.setAppDir(currDir)
print "App Directory : "+self.APPDIR
print "Refresh rate:",int(lines[1]),"seconds"
self.PING_FREQUENCY = int(lines[1])
print "BTC Exchange :",(lines[2].strip())," Display :",self.str2bool(lines[3].strip())
self.exchange = (lines[2].strip())
self.BTCMODE = self.str2bool(lines[3].strip())
print "LTC Exchange :",(lines[4].strip())," Display :",self.str2bool(lines[5].strip())
self.exchangeLTC = (lines[4].strip())
self.LTCMODE = self.str2bool(lines[5].strip())
print "NMC Exchange : ",(lines[6].strip())," Display :",self.str2bool(lines[7].strip())
self.exchangeNMC = (lines[6].strip())
self.NMCMODE = self.str2bool(lines[7].strip())
print "PPC Exchange : ",(lines[8].strip())," Display :",self.str2bool(lines[9].strip())
self.exchangePPC = (lines[8].strip())
self.PPCMODE = self.str2bool(lines[9].strip())
print "YAC Exchange : ",(lines[10].strip())," Display :",self.str2bool(lines[11].strip())
self.exchangeYAC = (lines[10].strip())
self.YACMODE = self.str2bool(lines[11].strip())
f.close()
def setAppDir(self,currDir):
self.BTCICON = os.path.abspath(currDir+"/res/bitcoinicon.png")
self.LTCICON = os.path.abspath(currDir+"/res/litecoinicon.png")
self.NMCICON = os.path.abspath(currDir+"/res/nmcicon.png")
self.PPCICON = os.path.abspath(currDir+"/res/peercoinicon.png")
self.YACICON = os.path.abspath(currDir+"/res/yacoinicon.png")
self.APPDIR = currDir
# utility function for settings file grab
def str2bool(self,word):
return word.lower() in ("yes", "true", "t", "1","ok")
def quit(self, widget, data=None):
gtk.main_quit()
# save settings at quit and kill indicator
def quit(self, widget):
try:
print 'Saving Last State.'
file = open(SETTINGSFILE, 'w')
file.write(str(self.APPDIR)+'\n')
file.write(str(self.PING_FREQUENCY)+'\n')
file.write(str(self.exchange)+'\n')
file.write(str(self.BTCMODE)+'\n')
file.write(str(self.exchangeLTC)+'\n')
file.write(str(self.LTCMODE)+'\n')
file.write(str(self.exchangeNMC)+'\n')
file.write(str(self.NMCMODE)+'\n')
file.write(str(self.exchangePPC)+'\n')
file.write(str(self.PPCMODE)+'\n')
file.write(str(self.exchangeYAC)+'\n')
file.write(str(self.YACMODE)+'\n')
file.close()
except IOError:
print " ERROR WRITING QUIT STATE"
gtk.main_quit()
sys.exit(0)
def menu_about_response(self,widget):
self.menu.set_sensitive(False)
widget.set_sensitive(False)
ad=gtk.AboutDialog()
ad.set_name(self.APPNAME)
ad.set_version(self.VERSION)
ad.set_comments("A bitcoin ticker indicator")
ad.set_license(''+
'This program is free software: you can redistribute it and/or modify it\n'+
'under the terms of the GNU General Public License as published by the\n'+
'Free Software Foundation, either version 3 of the License, or (at your option)\n'+
'any later version.\n\n'+
'This program is distributed in the hope that it will be useful, but\n'+
'WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\n'+
'or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\n'+
'more details.\n\n'+
'You should have received a copy of the GNU General Public License along with\n'+
'this program. If not, see <http://www.gnu.org/licenses/>.')
ad.set_website('https://github.com/jj9btcproj/Bitcoin-Price-Indicator')
ad.set_authors(['Written by jj9: \n If you want to tip the following are jj9 addressess \n'+
'BTC: 1ECXwPU9umqtsBAQesBW9981mx6sipPmyL \n '+
'LTC : LUJz8yaS4uL1zrzwARbA4CiMpAwbpUwWY6 \n '+
' NMC: N1SKXkrcyhxVYwQGsbLTFMbGAgeqL2g9tZ \n \n'+
'special thanks to RichHorrocks and Zapsoda for updating setup file and some btce api calls\n\n'+
'---jj9'])
ad.run()
ad.destroy()
self.menu.set_sensitive(True)
widget.set_sensitive(True)
if __name__ == "__main__":
indicator = CryptoCoinPriceIndicator()
indicator.main()