def get_transactions(): id = "" bid ="" parameteraccount = "nextcolony" account = Account(parameteraccount) #this function is used to load transcations into a database account_history = list(account.get_account_history(-1, 10000, filter_by=["transfer"])) for transaction in account_history: try: memo = transaction["memo"] trx_id = transaction['trx_id'] timestamp =transaction['timestamp'] fromaccount = transaction["from"] if memo.startswith('nc'): #print (transaction) code, parameters = transaction["memo"].split("@") JSON = json.loads(parameters) #print(JSON) command = (JSON['command']) type = (JSON['type']) #print (type) #print (command) if type =="auctionbid": bid = command['bid'] id = command['id'] #print (id) #print (bid) #print (transaction) #write the transaction in the database # Connect to the database connection = pymysql.connect(host='localhost', user='******', password='******', db='steembattle', charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) with connection.cursor() as cursor: sql = ("SELECT * FROM `auction` WHERE `steem_trx` = '"+str(trx_id)+"'") #print(sql) cursor.execute(sql) results = cursor.fetchone() #print(results) if results == None: print ("Noch nicht vorhanden") with connection.cursor() as cursor: sql = ("INSERT INTO `auction` (`trx_id`, `steem_trx`, `timestamp`, `bid`, `planet_id`, `user`) VALUES (NULL, '"+str(trx_id)+"', '"+str(timestamp)+"', '"+str(bid)+"', '"+str(id)+"', '"+str(fromaccount)+"')") print(sql) cursor.execute(sql) connection.commit() connection.close() #print(JSON) except: continue return
def getsbdprice(): #get the last transactions of steemmonsters from the blockchain acc = Account('steemmonsters') account_history = acc.get_account_history(-1, 1000, filter_by=["custom_json"]) for custom_json in account_history: try: data = custom_json["json"] parsed_json = json.loads(data) code = custom_json["id"] if code == "sm_price_feed": sbd = parsed_json["sbd"] return (sbd) except: print("Error getting the SBD price")
def match(deckid): summoner1 = "C-0X3OXSYUA8" #Selenia Sky 56 summoner2 = "C-0X3OXSYUA8" #Selenia Sky 56 summoner3 = "C-0X3OXSYUA8" #Selenia Sky 56 summoner4 = "C-0X3OXSYUA8" #Selenia Sky 56 summoner5 = "C-YO2VWID2SW" summoner6 = "C-0X3OXSYUA8" #Selenia Sky 56 summoner7 = "C-YO2VWID2SW" # Tyrus Paladium 38 summoner8 = "C-0X3OXSYUA8" #Selenia Sky 56 summoner9 = "" summoner10 = "" monsters1 = ["C-AZOTS424PC", "C-6P55WBF9I8", "C-00PPXK0Q8G"] #293332 monsters2 = ["C-HYCFO8VNFK", "C-5J7RYS1QFK", "C-T506R4S8IO"] #505752 monsters3 = [ "C-136TZUST6O", "C-L810JLD0OG", "C-F8TXCLCALC", "C-DSJJNNWUXC" ] #8149 monsters4 = [ "C-HYCFO8VNFK", "C-T506R4S8IO", "C-RIW75UV0A8", "C-08AVYCGCW0" ] #50524657 monsters5 = [ "C-EQTZLJT1ZK", "C-C9WDZW485C", "C-QW8CYQ44FK", "C-RSYVGU0TF4" ] #3837423544 monsters6 = [ "C-HYCFO8VNFK", "C-5J9UIIUZ80", "C-T506R4S8IO", "C-8J1FFPX4C0", "C-RIW75UV0A8" ] #5054524651 monsters7 = [ "C-EQTZLJT1ZK", "C-C9WDZW485C", "C-QW8CYQ44FK", "C-RSYVGU0TF4" ] #37423544 monsters8 = [ "C-TIAFKU4DLC", "C-QFGL7LOLC0", "C-F8TXCLCALC", "C-DSJJNNWUXC", "C-L810JLD0OG" ] # monsters9 = [] monsters10 = [] monsters11 = [] deck1 = { 'summoner': summoner1, 'monsters': monsters1, 'mana': 17 } #56293332 deck2 = { 'summoner': summoner2, 'monsters': monsters2, 'mana': 17 } #56505752 deck3 = {'summoner': summoner3, 'monsters': monsters3, 'mana': 17} #568149 deck4 = {'summoner': summoner4, 'monsters': monsters4, 'mana': 20} deck5 = {'summoner': summoner5, 'monsters': monsters5, 'mana': 20} deck6 = { 'summoner': summoner6, 'monsters': monsters6, 'mana': 20 } #565054524651 deck7 = { 'summoner': summoner7, 'monsters': monsters7, 'mana': 20 } #3837423544 deck8 = {'summoner': summoner8, 'monsters': monsters8, 'mana': 20} deck9 = {'summoner': summoner9, 'monsters': monsters9, 'mana': 20} deck10 = {'summoner': summoner10, 'monsters': monsters10, 'mana': 20} deck11 = {'summoner': summoner11, 'monsters': monsters11, 'mana': 20} decks = { '1': deck1, '2': deck2, '3': deck3, '4': deck4, '5': deck5, '6': deck6, '7': deck7, '8': deck8, '9': deck9, '10': deck10, '11': deck11 } decknumber = randint(9, 11) deck = decks[str(decknumber)] deck = decks[str(deckid)] #deck = deck1 summoner = deck['summoner'] monsters = deck['monsters'] mana = deck['mana'] secret = "YkUGqe9hK0" secret = id_generator() print(secret) strg_to_hash = (summoner + ',' + ",".join(monsters) + ',' + secret) hashvalue = hashlib.md5(strg_to_hash.encode('utf-8')).hexdigest() print(hashvalue) json = '{"match_type":"Ranked","mana_cap":' + str( mana ) + ',"team_hash":"' + hashvalue + '","summoner_level":4,"ruleset":"Standard"}' print(json) # transmit the request to fight smfindmatch(json) # get the block id for the request to fight acc = Account(user) check = False while (check == False): account_history = list( acc.get_account_history(-1, 3, filter_by=["custom_json"])) for transaction in account_history: custom_json = transaction['json'] if custom_json == json: check = True trx_id = transaction['trx_id'] print(trx_id) status = 0 count = 0 timeout = False while status < 1 and timeout == False: count = count + 1 r = requests.get('https://steemmonsters.com/battle/status?id=' + str(trx_id)) data = r.json() status = data['status'] print("Waiting for opponent") if count > 500: timeout = True if timeout == False: print("Match found") show_json = '{"trx_id":"' + trx_id + '","summoner":"' + summoner + '","monsters":["' + '","'.join( monsters) + '"],"secret":"' + secret + '"}' print(show_json) smshowteam(show_json)
from steem.account import Account from datetime import datetime a = Account('whoami') # 계정명 입력 comment_histories = list(a.get_account_history(index = -1, limit = 20, filter_by=['comment'], raw_output=True)) comment_histories = [ comment for comment in comment_histories if comment[1]['op'][1]['title'] == '' ] comment_histories = [ comment for comment in comment_histories if comment[1]['op'][1]['author'] != 'maanya' ] unique_permlink = [] happy_comments = [] for comment in comment_histories: if comment[1]['op'][1]['permlink'] not in unique_permlink: unique_permlink.append(comment[1]['op'][1]['permlink']) happy_comments.append(comment) print('와! %d개의 고마운 댓글이 있어요.\n' % len(happy_comments)) for comment in happy_comments: print('작성자:', comment[1]['op'][1]['author']) print('작성시간:', datetime.strptime(comment[1]['timestamp'], '%Y-%m-%dT%H:%M:%S')) print('내용: ', comment[1]['op'][1]['body']) print('')
def get_all(user_id): try: acc = Account(user_id) except AccountDoesNotExistsException as e: raise NotFound( 'Account {} does not exists in blockchain'.format(user_id)) user_history = list(acc.get_account_history(-1, 10000)) posts = {} for item in user_history: if item['type'] != 'comment': continue if 'json_metadata' not in item: continue json_meta = json.loads(item['json_metadata']) if 'app' not in json_meta: continue if not json_meta['app'].startswith('donate.now/'): continue key = item['permlink'] if key in posts: continue if 'body' not in json_meta: continue if not json_meta['body']: continue posts[key] = { 'user_id': user_id, 'post_id': key, 'title': item['title'], 'body': json_meta['body'], 'timestamp': item['timestamp'], 'cover_image_url': json_meta['cover_image_url'] if 'cover_image_url' in json_meta else '', 'transactions': [], 'amount_sbd': 0, 'amount_steem': 0, } transactions = [] for item in user_history: if item['type'] != 'transfer': continue if 'memo' not in item: continue memo = item['memo'] comment = None if memo.endswith(')') and memo.rfind('(') != -1: comment = memo[0:memo.rfind('(')].strip() post_id = None for key in posts.keys(): k = '({})'.format(key) if (k in memo): print key comment = memo.replace(k, '').strip() post_id = key break if not comment: continue amount_sbd = 0.0 amount_steem = 0.0 if item['amount'].endswith('STEEM'): amount_steem = float(str(item['amount']).replace('STEEM', '')) if item['amount'].endswith('SBD'): amount_sbd = float(item['amount'].replace('SBD', '')) transaction = None if item['from'] == user_id: transaction = { 'amount_sbd': -amount_sbd, 'amount_steem': -amount_steem, 'comment': comment, 'counterparty': item['to'], 'timestamp': item['timestamp'], } if item['to'] == user_id: transaction = { 'amount_sbd': amount_sbd, 'amount_steem': amount_steem, 'comment': comment, 'counterparty': item['from'], 'timestamp': item['timestamp'], } if not transaction: continue if post_id in posts: posts[post_id]['transactions'].append(transaction) posts[post_id]['amount_sbd'] += transaction['amount_sbd'] posts[post_id]['amount_steem'] += transaction['amount_steem'] transactions.append(transaction) return { 'posts': posts, 'transactions': transactions, 'sbd_balance': acc["sbd_balance"] }
target_account = Account(account_name) s = Steem() latest_operation = s.get_account_history(account_name, index_from=-1, limit=0) total_operations = latest_operation[0][0] num_iteration = int(total_operations/1000) + 1 # Num of times we have to request get_account_history transfer_file = open('output/transfers_{}.csv'.format(account_name), 'w') vestbalance_file = open('output/reward_delegation_balance_{}.csv'.format(account_name), 'w') transfer_file.write('Timestamp,Transfer Type,Dealer,STEEM,SBD,TX ID\n') vestbalance_file.write('Timestamp,Type,STEEM,SBD,VEST,TX ID\n') for i in range(1, num_iteration+1): # i =0, 1,2,3,...num_iteration _index_from = i*1000 history = target_account.get_account_history(index=_index_from,limit=1000, order=1) for operation in history: # Check Transaction Timestamp timestamp = datetime.datetime.strptime(operation['timestamp'],"%Y-%m-%dT%H:%M:%S") if timestamp < start_date: continue elif timestamp > end_date: break if operation['type'] =='transfer': if operation['from'] == account_name: dealer = operation['to'] transfer_type = 'transfer to' amount = -1* Amount(operation['amount']).amount else: dealer = operation['from']
file.close file = open('indexfile.txt', 'w') file.write(str(lastIndex)) file.close() while True: if datetime.now().time().minute > lastMinute: lastMinute = datetime.now().time().minute checkMinute() if datetime.now().time().hour == 12: if checkedThisHour = False: checkHour() else: checkedThisHour = False gen = account.get_account_history(10000, 10000, (lastIndex + 1), None, -1, None, False) while True: try: nex = next(gen) iterateGenerator(nex) except StopIteration: print("Nothing here!") break #Roll candidateLength = len(candidates) if candidateLength > 0: randomInteger = randint(0, candidateLength - 1) print("Send " + str(pot) + " sbd to " + candidates[randomInteger] + ", who bought " + str(candidates.count(candidates[randomInteger])) + " tickets!")
def next_in_queue(self, steem): results = self.db.select('upvotes', ['id,link'], {'status': 'in queue'}, 'created ASC', '1') if len(results) > 0: link = results[0]['link'].split('#') if len(link) > 1: link = link[1].split('/') else: link = results[0]['link'].split('/') uri = link[-2][1:] + '/' + link[-1] post = steem.get_content(link[-2][1:], link[-1]) # check payout time cashoutts = time.mktime( datetime.datetime.strptime(post['cashout_time'], "%Y-%m-%dT%H:%M:%S").timetuple()) chaints = time.mktime( datetime.datetime.strptime(self.chain.info()['time'], "%Y-%m-%dT%H:%M:%S").timetuple()) if cashoutts - chaints < 60 * 60 * 12: print( "\nskipping '{}' because payout is in less than 12 hours..." .format(results[0]['link'])) self.db.update( 'upvotes', {'status': 'skipped voting due to payout approaching'}, {'id': results[0]['id']}) return self.next_in_queue(steem) # check if author used bitbots bidbots = [ 'alfanso', 'appreciator', 'bdvoter', 'bid4joy', 'boomerang', 'booster', 'brandonfrye', 'buildawhale', 'edensgarden', 'inciter', 'joeparys', 'leo.voter', 'luckyvotes', 'minnowbooster', 'minnowhelper', 'minnowvotes', 'ocdb', 'onlyprofitbot', 'postpromoter', 'profitvote', 'promobot', 'qustodian', 'redlambo', 'rocky1', 'sct.voter', 'smartmarket', 'smartsteem', 'sneaky-ninja', 'sportsvoter', 'spydo', 'steemyoda', 'thebot', 'therising', 'tipu', 'treeplanter', 'triplea.bot', 'upmewhale', 'upmyvote', 'whalepromobot' ] postaccount = Account(post['author'], steem) history = postaccount.get_account_history(-1, 2500, filter_by='transfer') for h in history: if h['to'] in bidbots: if (h['to'] == 'minnowbooster' or h['to'] == 'tipu') and h['memo'][:4] != 'http': continue print( "\nskipping '{}' because author bought vote...".format( results[0]['link'])) self.db.update( 'upvotes', {'status': 'skipped voting due to vote buying'}, {'id': results[0]['id']}) return self.next_in_queue(steem) last = h['timestamp'] txts = time.mktime( datetime.datetime.strptime( h['timestamp'], "%Y-%m-%dT%H:%M:%S").timetuple()) chaints = time.mktime( datetime.datetime.strptime( self.chain.info()['time'], "%Y-%m-%dT%H:%M:%S").timetuple()) if chaints - txts > 60 * 60 * 24 * 7: break return uri, results[0]['id'] else: return False, False
from datetime import datetime from steem import Steem from steem.account import Account s = Steem() # variables ACCOUNT_NAME = 'jjb777' a = Account(ACCOUNT_NAME) HISTORY_LIMIT = 100 timestamp = datetime.now().strftime('%Y_%m_%d__%H-%M') # start code history_events = a.get_account_history(index=-1, limit=HISTORY_LIMIT, filter_by=['vote'], raw_output=True) file = open('check_upvotes_{}_{}.html'.format(ACCOUNT_NAME, timestamp), 'w') file.write('<html><body>') file.write('<h3>Check upvotes for comments and posts for account - {} - {}</h3>'.format(ACCOUNT_NAME, timestamp)) file.write('<table><tr><th>user</th><th>post</th><th>time</th><tr>') for event in history_events: operation = event[1]['op'][0] name = event[1]['op'][1]['voter'] link = event[1]['op'][1]['permlink'] time = event[1]['timestamp'] if (name != ACCOUNT_NAME): file.write('<tr><td><a href="https://steemit.com/@{}" target="blank">{}</a></td><td align="left"><a href="https://steemit.com/@{}/{}" target="blank">{}</a></td><td align="tight">{}</td></tr>'.format(name, name, ACCOUNT_NAME, link, link, time)) file.write('</table></body></html>') file.close()
from steem.account import Account from steem.post import Post from steem import Steem import time acc_name = 'maanyabot' pkey = 'postkey' steem = Steem(keys=pkey, nodes=['https://api.steemit.com']) acc = Account(acc_name) voted_permlink = [] # 봇 실행 당시 가장 최근의 기록 번호를 seq_num에 저장 past_seq_num = list(acc.get_account_history(index=-1, limit=2, raw_output=True))[0][0] while True: # 최근 댓글 확인 recent_seq_num = list( acc.get_account_history(index=-1, limit=2, raw_output=True))[0][0] # 봇이 확인한 이후에 최근 댓글이 있으면 동작 if recent_seq_num > past_seq_num: comment_histories = list( acc.get_account_history(index=-1, limit=recent_seq_num - past_seq_num, raw_output=True)) replies = [ comment for comment in comment_histories if comment[1]['op'][0] == 'comment' and comment[1]['op'][1] ['title'] == '' and comment[1]['op'][1]['author'] != 'maanyabot'
from steem import Steem from steem.account import Account from steem.converter import Converter import re username = '******' # 계정명 입력 s = Steem(nodes=["https://api.steemit.com"]) converter = Converter(steemd_instance=s) a = Account(username) histories = list( a.get_account_history(index=-1, limit=5300, filter_by='claim_reward_balance', raw_output=True)) sum_steem = 0 sum_sbd = 0 sum_sp = 0 for history in histories: steem = history[1]['op'][1]['reward_steem'] steem = float(re.findall("([0-9]+(?:\.[0-9]+)?)(?:\s)", steem)[0]) sbd = history[1]['op'][1]['reward_sbd'] sbd = float(re.findall("([0-9]+(?:\.[0-9]+)?)(?:\s)", sbd)[0]) sp = history[1]['op'][1]['reward_vests'] sp = float(re.findall("([0-9]+(?:\.[0-9]+)?)(?:\s)", sp)[0]) sp = converter.vests_to_sp(sp)
def lastTransaction(self): acc = Account("steemybot", steemd_instance=self.s) steemd = list(acc.get_account_history(-1, 1, filter_by=["transfer"])) # print(steemd) return steemd