Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import urllib2, os
- import gspread, datetime, time
- #----------------------------------------
- #------------Get Doge--------------------
- #----------------------------------------
- gc = gspread.login('XXXXXXXXXXXXX','XXXXXXXXXXXXXX')
- sh = gc.open("Investments")
- worksheet = sh.get_worksheet(0)
- values_list = worksheet.col_values(7)
- doge = values_list[len(values_list) - 1]
- worksheet.update_acell('C1', doge)
- print('You currently have ' + doge + ' DOGE \n')
- spentvalue = worksheet.acell('B6').value
- print('You currently have spent ' + spentvalue + '\n')
- spent = float(spentvalue[1:len(spentvalue)])
- #---------------------------------------
- #-------------DOGE to USD---------------
- #---------------------------------------
- print 'Current Market Values'
- print '--------------------------'
- print 'DOGE'
- dogecode = urllib2.urlopen("http://coinmarketcap.com")
- page_source = dogecode.read()
- dogecoin_section = page_source.find("img/DogeCoin.png")
- dogecoin_price_section = page_source.find("price", dogecoin_section)
- dogecoin_price_start = page_source.find("$", dogecoin_price_section)
- dogecoin_price_end = page_source.find("</a>", dogecoin_price_start)
- value = float(page_source[(dogecoin_price_start)+2:dogecoin_price_end])
- dogeUSDValue = value
- print("$" + str(value) + " USD")
- #---------------------------------------
- #------Doge current satoshi value-------
- #---------------------------------------
- dogecryptsy = urllib2.urlopen("https://www.cryptsy.com/")
- page_source = dogecryptsy.read()
- dogecryptsy_section = page_source.find("DOGE/BTC <span")
- dogecryptsy_price_start = page_source.find("market_price_132", dogecryptsy_section)
- dogecryptsy_price_starts1 = page_source.find(">", dogecryptsy_price_start)
- dogecryptsy_price_end = page_source.find("</span>", dogecryptsy_price_starts1)
- satoshi = float(page_source[(dogecryptsy_price_starts1) + 1:dogecryptsy_price_end])
- dogeBTCValue = satoshi
- satoshi = int(satoshi * 100000000)
- print(str(satoshi) + " SAT")
- worksheet.update_acell('E10', dogeBTCValue)
- #---------------------------------------
- #---------BTC current value-------------
- #---------------------------------------
- print '\n' + "BTC - Coinbase"
- btccoinbase = urllib2.urlopen("https://www.coinbase.com/")
- page_source = btccoinbase.read()
- btccoinbase_section = page_source.find("Current Buy Price")
- btccoinbase_price_start = page_source.find("$", btccoinbase_section)
- btccoinbase_price_end = page_source.find("</a>", btccoinbase_price_start)
- value = float(page_source[(btccoinbase_price_start) + 1:btccoinbase_price_end])
- btcValue = value
- worksheet.update_acell('J10', btcValue)
- print("$" + str(value) + " USD")
- print '--------------------------'
- #---------------------------------------
- #---------Your current earnings---------
- #---------------------------------------
- dogeUSD = float(doge) * float(dogeUSDValue)
- dogeBTC = float(doge) * float(dogeBTCValue)
- totalUSD = dogeUSD
- totalBTC = dogeBTC
- print '\n'
- print("You currently have:")
- print("%.7f" + " BTC or " "$" + "%.2f" + " USD" + " in DogeCoin") % (dogeBTC, dogeUSD)
- print '\n'
- if(spent > 0):
- print("You have spent $" + '%.2f' + " and ") % spent
- print("You currently have $" + '%.2f') % totalUSD
- if(spent > 0):
- print("You have earned a whopping $" + '%.2f' % (float(totalUSD) - float(spent)) + " or " + str(float('%.2f' % (totalUSD/spent)) * 100) + "% from your initial investment!")
- if(doge > 0):
- print("TO THE MOON!")
- #--------------------------------------
- #-----------Data analysis--------------
- #--------------------------------------
- worksheet = sh.get_worksheet(1)
- dcolumn = worksheet.col_values(1)
- tcolumn = worksheet.col_values(2)
- pcolumn = worksheet.col_values(3)
- ccolumn = worksheet.col_values(4)
- date = datetime.datetime.now().strftime('%m' + "/" +'%d' + "/" + '%y')
- time = datetime.datetime.now().strftime("%H:%M")
- currentUSD = ('%.2f' % (float(totalUSD) - float(spent)))
- def formatdate(x):
- date = str(x)
- string = date.replace("/", " ")
- partslist = string.split()
- partslist[2] = str("20" + partslist[2])
- count = 0
- for i in partslist:
- partslist[count] = str(int(i))
- count += 1
- date = str(partslist[0] + "/" + partslist[1] + "/" + partslist[2])
- return date
- date = formatdate(date)
- def formattime(x):
- #14:12:00
- x = str(x)
- index = x.find(":")
- part1 = x[0:index]
- part2 = str(x[index+1:index+3])
- if(int(part1) > 11):
- part3 = " PM"
- else:
- part3 = " AM"
- if(int(part1) > 12):
- part1 = int(part1) - 12
- if(int(part1) == 0):
- part1 = 12
- return str('%s' + ":" + '%s' + '%s') % (part1, part2, part3)
- time = formattime(time)
- def checksign(x):
- x = str(x)
- if "-" in x:
- return str(x)
- else:
- return str("+" + x)
- lastUSD = pcolumn[len(pcolumn)-1]
- change = str('%.2f' % (float(currentUSD) - float((lastUSD)[1:len(lastUSD)])))
- toAppend = [date, time, str(currentUSD), change, "", totalUSD, spent, str(float('%.2f' % (totalUSD/spent))*100)]
- if(float(change) == 0.0):
- print("\nDid not append to spreadsheet. No change in price.")
- print("Last change in profit was " + str(checksign(str(ccolumn[len(ccolumn)-1]))) + " from " + pcolumn[len(pcolumn)-2] + " to " + pcolumn[len(pcolumn)-1] + " at " + tcolumn[len(tcolumn)-1])
- print("Done\n")
- else:
- print("\n[Appending to Investments > Data]")
- print("\n Appended " + str(toAppend) +"\n")
- worksheet.append_row(toAppend)
- print("Done\n")
- #------------------------------------
- #---------Average daily data---------
- #------------------------------------
- #--- Get Average Profit---
- cell_list = worksheet.findall("Day End")
- lastdaycell = cell_list[(len(cell_list) -1)]
- cellrow = lastdaycell.row+1
- plist = pcolumn[cellrow:len(dcolumn)]
- vlistofp = worksheet.range(str(('C'+str(cellrow))+":"+('C'+str(len(dcolumn)))))
- total = 0
- for value in vlistofp:
- total = float(value.value[1:len(value.value)]) + float(total)
- avgProfit = total / len(vlistofp)
- #---Get Average Profit'---
- clist = ccolumn[cellrow:len(dcolumn)]
- vlistofc = worksheet.range(str(('D'+str(cellrow))+":"+('D'+str(len(dcolumn)))))
- total = 0
- for value in vlistofc:
- x = value.value
- x = x.replace('$','')
- total = float(x) + float(total)
- avgCProfit = total / len(vlistofc)
- #---Get Sum of change for day---
- sumCProfit = total
- #--- check for Day End---
- if(((dcolumn[len(dcolumn)-1]) != date)):
- print dcolumn[len(dcolumn)-1]
- print date
- print("Appending averages for previous day on [Investments > Data] and [Investments > Averages]")
- toAppend = ["Day End", "Averages follow", avgProfit, avgCProfit, sumCProfit]
- worksheet.append_row(toAppend)
- print(" Appended " + str(toAppend) + '\n')
- #---averages and sums for days---
- worksheet = sh.get_worksheet(2)
- toAppend = [date, time, '%.4f' % (avgProfit), '%.4f' % (avgCProfit), sumCProfit]
- worksheet.append_row(toAppend)
- print(" Appended " + str(toAppend) + '\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement