def main(): config = configparser.ConfigParser() config.read('config.ini') config.read('config.secret.ini') nodes = config['DEFAULT']['nodes'].split(',') keys = config['steem-secrets']['wif_keys'].split(',') witness_name = config['steem-secrets']['witness_name'] wallet_password = config['steem-secrets']['wallet_password'] result = requests.get('https://coinmarketcap.com/currencies/steem/') parser = CoinMarketCapPriceHTMLParser() parser.feed(result.text) price = re.sub(r'[\$,]', '', parser.raw_price) try: price = float(price) except ValueError: print("Could not parse price: %s" % price) exit(1) if price <= 0: print("Price %s is too low!" % price) exit(1) print("Witness name: %s" % witness_name) print("Price received: %s" % price) steem = Steem(nodes=nodes, keys=keys) wallet = steem.wallet steem.commit.witness_feed_publish(price, account=witness_name) pprint(steem.get_witness_by_account(witness_name))
def main(): parser = argparse.ArgumentParser() parser.add_argument("config", help="Config file in JSON format") parser.add_argument("--post-daily-flag-report", help="Posts daily flag report") args = parser.parse_args() config = json.loads(open(args.config).read()) keys = [config.get("posting_key")] if config.get("flag_options") and \ 'from_account_posting_key' in config.get("flag_options"): keys.append(config["flag_options"]["from_account_posting_key"]) steemd_instance = Steem( nodes=config["nodes"], keys=keys, ) sherlock = Sherlock( steemd_instance, config, ) if args.post_daily_flag_report: sherlock.post_daily_flag_report() return sherlock.run()
def updatePostInformation(clicks,tag): post=1 s = Steem() query = { "limit":post, #number of posts "tag":str(tag) #tag of posts } print("collecting posts...") posts = s.get_discussions_by_created(query) print('posts collected!') details = '' dicts = [] print("working") for post in posts: details = s.get_content(post["author"],post["permlink"]) dicts.append(details) print(type(details)) # # return 'You have clicked {} times. Input tags are {}, number of posts are {}'.format(clicks,tag,post) post_info = "Post Info <br><br>Author : {} <br><br>Category : {} <br><br>Created : {} <br><br>Title : {} <br><br>Body : {}".format(dicts[0]['author'], dicts[0]['category'],dicts[0]['created'],dicts[0]['title'],dicts[0]['body']) #print(post_info) #return str(dicts[0].keys()) return post_info
def __init__(self, config, model): # retrieve parameters from config file self.account = config['account'] self.nodes = config['nodes'] self.tags = config['tags'] self.probability_threshold = config['probability_threshold'] self.training_file = config['training_file'] self.blacklist_file = config['blacklist_file'] self.whitelist_file = config['whitelist_file'] self.scamlist_file = config['scamlist_file'] self.reply_mode = config['reply_mode'] self.vote_mode = config['vote_mode'] self.vote_weight = config['vote_weight'] self.blacklist = [ user.strip() for user in open(self.blacklist_file, 'r').readlines() ] self.whitelist = [ user.strip() for user in open(self.whitelist_file, 'r').readlines() ] self.scamlist = [ user.strip() for user in open(self.scamlist_file, 'r').readlines() ] self.num_previous_comments = config['num_previous_comments'] self.steem = Steem(nodes=self.nodes, keys=[POSTING_KEY]) # machine learning model (=algorithm) self.model = model
def index(request): if request.method == 'POST': try: pk = [request.POST['pk']] steem = Steem(keys=pk[0], nodes=["https://api.steemit.com"]) tagsarray = request.POST['tags'].split(',') steem.post(request.POST['title'], request.POST['body'], author=request.POST['author'], permlink=request.POST['permlink'], json_metadata={ "app": "steemplace/0.1", "tags": tagsarray }, reply_identifier=None) return HttpResponse('ok', content_type='text/plain') except Exception as ex: return HttpResponse( 'An error has occurred while posting the post:' + str(ex), content_type='text/plain') else: return HttpResponse( 'This is a POST request. To post to the Steem Blockchain, send the following parameters:\n' 'pk = private key\n' 'title = post title\n' 'body = post body\n' 'author = post author\n' 'permlink = post permlink\n' 'tags = tags, comma-separated (tag1,tag2,tag3,tag4,tag5)', content_type='text/plain')
def make_vote(self, ratio, post_link,account_name): account_info_post = interpret.get_account_info(account_name,self.main.active_key, self.main.sending_account, self.main.memo_account, self.main.nodes[0]) if account_info_post: account_info_post = account_info_post[2] # takes ratio and post link and calculates the vote on the post, and returns it for use in the post memo if ratio < self.vote_threshold: return 0 if account_info_post: upvote_tokens = account_info_post["token-upvote-perm"] #+ self.account_info[post_link]["token-upvote-temp"] else: upvote_tokens = 0 equation = self.average_post[0] * (math.sqrt(upvote_tokens)/25 + 1) * (ratio/self.average_post[1]) if equation > 100: equation = 100 elif equation < 0.1: return 0 for i in self.nodes: try: steem = Steem(node=i, keys=self.posting_key) steem.vote("@"+post_link.split("@")[1], equation, account=self.sending_account) return equation except Exception as e: print(e) pass return 0
def run(self): while True: try: b = Blockchain(Steem(nodes=app.config['STEEM_NODES'])) log('Using Steem API node(s): ' + str(app.config['STEEM_NODES'])) log('Blockchain head is ' + str(steem.head_block_number)) # start from max block present in table post = db.session.query(Post).order_by(Post.id.desc()).first() if post: self.start_block = post.block_number log('Starting streaming (in catch up) from block: ' + str(self.start_block)) else: self.start_block = self.start_block log('Starting streaming from (specified) block: ' + str(self.start_block)) for blockcount, block in enumerate(b.stream_from(start_block=self.start_block, full_blocks=True)): block_number = self.start_block + blockcount if (self.start_block + blockcount) % 20 == 0: log('Read Block:' + str(block_number)) try: add_block_content_to_db(block) except Exception as e: log('ERROR: Problem adding block to database.') log(str(e)) time.sleep(10) break except Exception as e: log('ERROR: Problem collecting raw blocks from ' + str(app.config['STEEM_NODES'])) log(str(e)) time.sleep(10)
def vote(author, permlink, kind): if 'logged_in' in session and session[ 'logged_in'] and 'authorized' in session and session[ 'authorized'] and 'username' in session: try: weight = 100 if kind == "flag": weight = -100 identifier = "@" + author + "/" + permlink if 'POST_TO_STEEM' in app.config and app.config[ 'POST_TO_STEEM'] == "1": s = Steem( nodes=[ 'https://rpc.buildteam.io', 'https://api.steemit.com', 'https://steemd.steemitstage.com' ], keys=[app.config['POSTING_KEY'], app.config['ACTIVE_KEY']]) p = s.commit.vote(identifier, weight, account=session['username']) app.logger.info(p) return jsonify({'status': True}) except Exception as e: app.logger.info(e) return jsonify({'status': False, 'msg': 'unknown exception'}) else: return jsonify({ 'status': False, 'msg': 'please login and authorize first' })
def run(): username = os.environ.get("STEEM_NAME") blockchain = Blockchain() stream = map(Post, blockchain.stream(filter_by=["comment"])) upvote_list = json.load(open('upvote_list.json')) wif = upvote_list["voters"][username]["wif"] steem = Steem(wif=wif) upvoted = {} date = int(time.strftime("%d")) hour = int(time.strftime("%-H")) print("Entering blockchain stream!") while True: try: for post in stream: if int(time.strftime("%d")) is not date: upvoted = {} date = int(time.strftime("%d")) if int(time.strftime("%-H")) is not hour: upvote_list = json.load(open('upvote_list.json')) hour = int(time.strftime("%-H")) if valid_post(post, upvote_list, upvoted): try: author = post["author"] schedule_upvote(upvote_list, username, author) print("Upvoted {}".format(author)) upvoted[author] += 1 except Exception as error: print(repr(error)) continue except Exception as error: #print(repr(error)) continue
def pay_account(size, our_account, our_memo_account, node, active_key, info): # Sends steem to account and then updates the account memo (even if not needed, keeps it near the top) try_num = 0 print("here") while try_num < 5: try_num += 1 try: s = Steem(node=node, keys=active_key) print(2) s.transfer(info["account"], size, asset="STEEM", account=our_account, memo="payment of " + str(size) + " Steem.") info["steem-owed"] -= size main.save_memo(info, our_memo_account, our_account, active_key, node=node) break except Exception as e: print(e) pass
def __init__(self, config, poster, priv_keys, on_complete): self.config = config self.poster = poster self.on_complete = on_complete self.steem = Steem(keys=priv_keys) self.last_posting = datetime.now() - POSTING_GUARD_TIME self.read_message_files()
def scrape_all_users(mongo, quick=False): """ Scrape all existing users and insert/update their entries in Accounts collection. Ideally, this would only need to run once, because "scrape_accounts" takes care of accounts that need to be updated in each block. """ steem = Steem() indexer = Indexer(mongo) account_checkpoint = indexer.get_checkpoint('accounts') usernames = myAccounts() # if account_checkpoint: # usernames = list(get_usernames_batch(account_checkpoint, steem)) # else: # usernames = list(get_usernames_batch(steem)) for username in usernames: log.info('Updating @%s' % username) update_account(mongo, username, load_extras=True) if quick: update_account_ops_quick(mongo, username) else: update_account_ops(mongo, username) indexer.set_checkpoint('accounts', username) log.info('Updated @%s' % username) # this was the last batch if account_checkpoint and len(usernames) < 1000: indexer.set_checkpoint('accounts', -1)
def run(user_json): username = "******" wif = os.environ.get("UNLOCK") steem = Steem(wif=wif) blockchain = Blockchain() stream = map(Post, blockchain.stream(filter_by=["comment"])) print("Checking posts on the blockchain!") while True: try: for post in stream: title = post["title"] author = post["author"] print(author) if author in user_json: # if valid_post(post, user_json): try: title = post["title"] author = post["author"] print("Upvoting post {} by {}!".format(title, author)) post.upvote(weight=user_json[author]["upvote_weight"], voter=username) except Exception as error: print(repr(error)) continue except Exception as error: print(repr(error)) continue
def main(): accounts = [] votes_db = pickledb.load('steem_account_votes.db', False) comments_db = pickledb.load('steem_account_comments.db', False) transfers_db = pickledb.load('steem_account_trasnfers.db', False) vesting_transfers_db = pickledb.load('steem_account_vesting_transfers.db', False) result_db = pickledb.load('result.db', False) steemd = Steem(STEEM_NODES) chain = Blockchain(steemd_instance = steemd, mode = 'head') logging.getLogger().setLevel(20) databases = {'account_create': accounts, 'vote': votes_db, 'comment': comments_db, 'transfer': transfers_db, 'transfer_to_vesting': vesting_transfers_db} fill(databases, chain, round((1497970800 - 1451606400) / 3), chain.info()['head_block_number']) votes_db.dump() comments_db.dump() transfers_db.dump() vesting_transfers_db.dump() analyze(databases, result_db) result_db.dump()
def test_remove_proposal(node, account, wif, subject): logger.info("Testing: remove_proposal") s = Steem(nodes = [node], no_broadcast = False, keys = [wif]) # first we will find our special proposal and get its id proposals = s.list_proposals(account, "by_creator", "direction_ascending", 1000, "inactive") found = None for proposal in proposals: if proposal["subject"] == subject: found = proposal assert found is not None proposal_id = int(found["id"]) # remove proposal s.commit.remove_proposal(account, [proposal_id]) # try to find our special proposal proposals = s.list_proposals(account, "by_creator", "direction_ascending", 1000, "inactive") found = None for proposal in proposals: if proposal["subject"] == subject: found = proposal assert found is None
def scrape_all_users(mongo, quick=False): """ Scrape all existing users and insert/update their entries in Accounts collection. """ steem = Steem() s = Settings(mongo) quick = False # TODO: remove temporary override account_checkpoint = s.account_checkpoint(quick) if account_checkpoint: usernames = list(get_usernames_batch(account_checkpoint, steem)) else: usernames = list(get_usernames_batch(steem)) for username in usernames: update_account(mongo, username, load_extras=quick) if not quick: update_account_ops(mongo, username) s.set_account_checkpoint(username, quick) log.info('Updated @%s' % username) # this was the last batch if account_checkpoint and len(usernames) < 1000: s.set_account_checkpoint(-1, quick)
def test_list_proposals(node, account, wif, subject): logger.info("Testing: list_proposals") s = Steem(nodes = [node], no_broadcast = False, keys = [wif]) # list inactive proposals, our proposal shoud be here proposals = s.list_proposals(account, "by_creator", "direction_ascending", 1000, "inactive") found = None for proposal in proposals: if proposal["subject"] == subject: found = proposal assert found is not None # list active proposals, our proposal shouldnt be here proposals = s.list_proposals(account, "by_creator", "direction_ascending", 1000, "active") found = None for proposal in proposals: if proposal["subject"] == subject: found = proposal assert found is None # list all proposals, our proposal should be here proposals = s.list_proposals(account, "by_creator", "direction_ascending", 1000, "all") found = None for proposal in proposals: if proposal["subject"] == subject: found = proposal assert found is not None
def steem_following(self, username): # TODO: fixed this section,limit = 100 ? STEEM = Steem(nodes=['https://api.steemit.com']) return [ i["following"] for i in STEEM.get_following(username, 'abit', 'blog', limit=100) ]
def get_last_ecoinstant_entry(): s = Steem(nodes=settings.STEEM_NODES) blog_entries = s.get_blog( account='ecoinstant', entry_id=0, limit=10, ) for entry in blog_entries: comment = entry['comment'] author = comment.get('author') if author == 'ecoinstant': entry_dict = { 'title': comment.get('title'), 'url': 'https://steemit.com/{0}/@{1}/{2}'.format( comment.get('category'), author, comment.get('permlink'), ), } return entry_dict return None
def __init__( self, steem=None, limit=100, logger=logging.NullHandler, deplorables=None): if steem is None: dry_run = True self.steem = Steem(nodes=['https://api-internal.steemit.com']) else: self.steem = steem if deplorables is not None: self.deplorables = deplorables else: self.deplorables = set() # info for steem/vest ratio global_props = self.steem.get_dynamic_global_properties() vesting_steem = amount(global_props['total_vesting_fund_steem']) vesting_shares = amount(global_props['total_vesting_shares']) # load dynamic acct creation fee chain_props = self.steem.get_chain_properties() account_creation_fee = amount(chain_props['account_creation_fee']) self.limit = limit self.logger = logger self.STEEM_PER_VEST = vesting_steem / vesting_shares self.TARGET_VESTS = self.TARGET_SP / self.STEEM_PER_VEST self.MIN_VESTS_DELTA = (account_creation_fee / 30) / self.STEEM_PER_VEST self.MIN_VESTS = (account_creation_fee / 3) / self.STEEM_PER_VEST
def submit(request): if request.method == 'POST': node = "https://api.steemit.com" keys = ['---', request.POST['wif']] # initialize Steem class s = Steem(node, keys=keys) # Buyer's steemit account sender = request.POST['from'] # your steemit account recipient = '' # You can choose SBD or Steem asset = 'SBD' # price in Steem or steem dollar amount = 1.000 memo = request.POST['memo'] s.transfer(recipient, amount, asset, memo=memo, account=sender) # send receipt with SMTP server send_mail( 'Receipt', 'now testing', '*****@*****.**', request.POST['email'], fail_silently=False, ) return render(request, 'submitted.html', context=None)
def run_worker(worker_name): mongo = MongoStorage(db_name=os.getenv('DB_NAME', DB_NAME), host=os.getenv('DB_HOST', MONGO_HOST), port=os.getenv('DB_PORT', MONGO_PORT)) stm = Steem() while True: try: if worker_name == "scrape_operations": mongo.ensure_indexes() scrape_operations(mongo, stm) elif worker_name == "validate_operations": validate_operations(mongo, stm) elif worker_name == "scrape_all_users": scrape_all_users(mongo, stm) elif worker_name == "scrape_active_posts": scrape_active_posts(mongo, stm) elif worker_name == "scrape_prices": scrape_prices(mongo) elif worker_name == "refresh_dbstats": refresh_dbstats(mongo) elif worker_name == "override": override(mongo) except (KeyboardInterrupt, SystemExit): exit("Quitting...") except: print("EXCEPTION: %s():" % worker_name) print(traceback.format_exc()) # prevent IO overflow time.sleep(5)
def main(): global steem global tnt_server global steem_space global followers_space global chain print('starting datafeed.py..') ws_connection = os.environ['WS_CONNECTION'] print('Connecting to ', ws_connection) sys.stdout.flush() steem = Steem(ws_connection) chain = Blockchain(steem_instance=steem, mode='head') while True: try: print('Connecting to tarantool (datastore:3301)..') sys.stdout.flush() tnt_server = tarantool.connect('datastore', 3301) steem_space = tnt_server.space('steem') followers_space = tnt_server.space('followers') except Exception as e: print('Cannot connect to tarantool server', file=sys.stderr) print(str(e), file=sys.stderr) sys.stderr.flush() time.sleep(10) continue else: while True: run() print('[run] exited, continue..')
def main(): parser = argparse.ArgumentParser( description='show user balances', epilog='Report bugs to: https://github.com/bitfag/golos-scripts/issues' ) parser.add_argument('account', help='account name') parser.add_argument('-c', '--config', default='./common.yml', help='specify custom path for config file') args = parser.parse_args() # parse config with open(args.config, 'r') as ymlfile: conf = yaml.load(ymlfile) golos = Steem(nodes=conf['nodes_new'], no_broadcast=True) a = Account(args.account, steemd_instance=golos) b = a.get_balances() pprint(b) vests = b['total']['GESTS'] cv = Converter(golos) pprint('GP: {}'.format(cv.vests_to_sp(vests)))
def __init__(self, community_name: str, account_name: str, steem_instance: Steem = None, **kwargs): self.steem = steem_instance or Steem(**kwargs) self.community = community_name self.account = account_name
def get_steem_conn(nodes): global _steem_conn if _steem_conn is None: _steem_conn = Steem(nodes=nodes, # keys=[os.getenv("POSTING_KEY"), ] ) return _steem_conn
def handle(self, *args, **options): pages = Page.objects.filter(status=1) comments = Comment.objects.filter(status=1) meta = {'app': 'mapala'} # todo add url from steem import Steem for page in pages: steem = Steem(page.locale.master_node) steem.wallet.setKeys(page.author.private_key) mapala_tag = Tag.objects.get_or_create(name='mapala')[0] if mapala_tag not in page.tags.all(): page.tags.add(mapala_tag) try: if settings.POST_TO_BLOCKCHAIN: steem.post(page.title, page.body, page.author.user.username, page.permlink, meta, category="test", tags=page.get_tags()) page.status = 2 except: page.status = 0 page.save() for comment in comments: page = comment.page from steem import Steem steem = Steem(page.locale.master_node) steem.wallet.setKeys(comment.author.private_key) parent = comment.parent if comment.parent else page try: if settings.POST_TO_BLOCKCHAIN: steem.post(title='RE: %s' % page.title, body=comment.body, author=comment.author.user.username, permlink=comment.permlink, meta=meta, reply_identifier='@%s/%s' % (parent.author, parent.permlink)) comment.status = 2 except: comment.status = 0 comment.save()
def get_steem_account(username): username = normalize(username) steem_client = Steem() account = steem_client.get_account(username) return account
def listen(config, daily_message): logger.info('Starting TX listener...') steem = Steem(nodes=config.get("nodes"), keys=config["keys"]) tx_listener = TransactionListener(steem, config) if daily_message == '1': tx_listener.daily_message() return tx_listener.run()
def __init__(self, node_url, proposals, private_key, delay): threading.Thread.__init__(self) self.node_url = node_url self.proposals = proposals self.private_key = private_key self.delay = delay self.log = logging.getLogger(MODULE_NAME + ".ProposalsCreatorThread." + self.node_url) self.node_client = Steem(nodes = [self.node_url], keys = [self.private_key])