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
import praw
import gspread
import time
import litecoinrpc
from decimal import *
import math
import os, sys
lib_path = os.path.abspath('C:\Users\Josh\Desktop\PyCryptsy-master')
sys.path.append(lib_path)
from PyCryptsy import *
import urllib2
import unicodedata


#Connect to Dogecoin
location = "C:\Users\Josh\AppData\Roaming\DogeCoin\dogecoin.conf"
conn =  litecoinrpc.connect_to_local(location)

#Open Google Drive Worksheet
gc = gspread.login('--sensitive-data--', '--sensitive-data--')
sh = gc.open('Users')
wks = sh.get_worksheet(0)

#Login to Reddit
user_agent="dogetb: A Dogecoin trade bot built from scratch in python!"
r = praw.Reddit(user_agent=user_agent)
acct.login('--sensitive-data--', '--sensitive-data--')

#Get Mention
mention = list(acct.get_mentions(limit=1))

#Get Message
remove = 0
messages = list(acct.get_inbox(limit=None))
number = len(messages)
number = int(number)
msglist = list()
for line in messages:
    number = number - 1
    if number > 0:
        line = str(line)
        if "From: " in line:
            if "+" in line:
                msglist.append(line)
msglist = "\n".join(msglist)
msglist = msglist.split('\n')
msglist = [x for x in msglist if x]
for item in msglist:
    if item[0] == 'S':
        msglist.remove(item)
msglist = iter(msglist)
msglist = map(':'.join, itertools.izip(msglist, msglist))
msglist = '\n'.join(msglist)
msglist = msglist.replace('From: ', '')
msglist = msglist.replace(':', ' ')
msglist = msglist.splitlines()
comfile = open('commands.txt', 'w+')
readfile = [line for line in comfile.readlines()]
readfile = map(lambda s: s.strip(), readfile)
readfile = ([s.replace('-', '') for s in readfile])
newfile = msglist + list(set(readfile) - set(msglist))
with open('commands.txt') as finddashes:
    dashes = finddashes.read()
dashlist = list()
for item in dashes.split("\n"):
    if "-" in item:
        dashlist.append(item.strip())
dashlist = ([s.replace('-', '') for s in dashlist])
newlist = list()
for element in dashlist:
    if element in newfile:
        print element
        newlist.append("-" + element)
    if element not in newfile:
        newlist.append(element)
newlist = list(OrderedDict.fromkeys(newlist))
newlist = "\n".join(newlist)
comfile.write(newlist)
comfile.close()

rg = "+register"
if rg in msg:
    reg = 1
    print reg
    msg = msg.replace("+register ","",1)
    find = str(wks.findall(sender))
    print find
    if find == "[]":
        rows = wks.row_count
        int(rows)
        print rows
        row = rows + 1
        wks.add_rows(1)
        wks.update_cell(row, 1, sender)
        wks.update_cell(row, 4, msg)
        wks.update_cell(row, 3, 0)
        wks.update_cell(row, 2, 0)
        wks.update_cell(row, 5, 0)
        wks.update_cell(row, 6, 0)
        acct.send_message(sender, "Dogecoin Tip Bot", "You have been entered into the system, thanks for joining!")

sent = 0
walleturl = "http://dogechain.info/chain/Dogecoin/q/getreceivedbyaddress/"
rg = "+deposit"
if rg in msg:
    dep = 1
    print dep
    newaddr = conn.getnewaddress()
    acct.send_message(sender, "Dogecoin Tip Bot","Your personal dogecoin address is: "+str(newaddr)+", please send your desired amount of dogecoins here.")
    addrrow = str(wks.find(sender))
    addrrow = addrrow[7:]
    addrrow = addrrow[:1]
    recell = "B"+str(addrrow)+""
    received = wks.acell(recell).value
    received = walleturl + received
    for line in urllib2.urlopen(received):
        received = line
        received = float(received)
        wks.update_cell(addrrow, 5, received)
    secell = "F"+str(addrrow)+""
    sent = wks.acell(secell).value
    received = float(received)
    sent = float(sent)
    balance = received - sent
    wks.update_cell(addrrow, 3, balance)

wdrw = "+withdraw"
if wdrw in msg:
    withdrw = 1
    print withdrw
    msg = msg.replace("+withdraw ","",1)
    amount = float(msg)
    print amount
    addrrow = str(wks.find(sender))
    addrrow = addrrow[7:]
    addrrow = addrrow[:1]
    recell = "B"+str(addrrow)+""
    received = wks.acell(recell).value
    received = walleturl + received
    for line in urllib2.urlopen(received):
        received = float(received)
        wks.update_cell(addrrow, 5, received)
    secell = "F"+str(addrrow)+""
    sent = wks.acell(secell).value
    received = float(received)
    sent = float(sent)
    balance = received - sent
    wks.update_cell(addrrow, 3, balance)
    balance = "C"+str(addrrow)+""
    balance = wks.acell(balance).value
    print balance
    balance = float(balance)
    amount = float(amount)
    if balance >= amount:
        waddr = "D"+str(addrrow)+""
        dogeaddr = wks.acell(waddr).value
        balance = balance - amount
        newbalance = wks.update_cell(addrrow, 3, balance)
        print dogeaddr
        acct.send_message(sender, "Dogecoin Tip Bot", "Your command to withdraw "+str(amount)+" dogecoins has been received. Thank you for using Dogetb!")
        conn.sendtoaddress(dogeaddr, amount)
    else:
        print "Not enough dogecoins in account to withdraw this amount, sending message."
        acct.send_message(sender, "Dogecoin Tip Bot", "I'm sorry, but you do not have enough dogecoins in your account to withdraw: "+str(amount)+" dogecoins.\nIf you would still like to withdraw dogecoins, please choose another amount.\n\nYour current balance is: "+str(balance)+" dogecoins.")

api=PyCryptsy('--sensite-data--', '--sensitive-data--')
info = "+info"
if info in msg:
    addrrow = str(wks.find(sender))
    addrrow = addrrow[7:]
    addrrow = addrrow[:1]
    recell = "B"+str(addrrow)+""
    received = wks.acell(recell).value
    received = walleturl + received
    for line in urllib2.urlopen(received):
        received = line
        received = float(received)
        wks.update_cell(addrrow, 5, received)
    secell = "F"+str(addrrow)+""
    sent = wks.acell(secell).value
    received = float(received)
    sent = float(sent)
    balance = received - sent
    wks.update_cell(addrrow, 3, balance)
    balance = Decimal(balance)
    price = api.GetBuyPrice("DOGE", "BTC")
    price = str(price)
    if "e" in price:
        price = price.split("e", 1)
        pwr = float(price[1])
        pwr = Decimal(pwr)
        pwr = 10**pwr
        value = Decimal(price[0])
        cvalue = value * pwr
        total = balance * cvalue
    table = '''    Coin     |        Balance       |    Value
               :-----------:|:--------------------:|:-----------:
                  Dogecoin  |    {blc} Dogecoin    |{cv} BTC/DOGE
                            |                      |
                     TOTAL  |                      |   {tl} BTC          '''.format(blc=balance, cv=cvalue, tl=total)
    acct.send_message(sender, "Dogecoin Tip Bot", table)

sendcmd = "+/u/dogetb"
#if sendcmd in mention:

transactions = "+transactions"
if transactions in msg:
    addrrow = str(wks.find(sender))
    addrrow = addrrow[7:]
    addrrow = addrrow[:1]
    cell = "B"+str(addrrow)+""
    dogeaddr = wks.acell(cell).value
    trans = conn.listtransactions(address=dogeaddr, count=10)
    print trans
    acct.send_message(sender, "Dogecoin Tip Bot", trans)

This paste never expires. View raw. Pasted through import.