def main(args=None):
    args = parse_args(args)
    authorperm = args.authorperm
    comment = Comment(authorperm)
    title = comment["title"]
    author = comment["author"]
    rep = reputation_to_score(comment["author_reputation"])
    time_created = comment["created"]
    utc = pytz.timezone('UTC')
    td_created = utc.localize(datetime.utcnow()) - time_created
    md = '# ' + title + '\n' + author
    md += '(%.2f) ' % (rep)
    md += formatTimedelta(td_created) + '\n\n'
    md += comment["body"]
    extensions = ['extra', 'smarty']
    html = markdown.markdown(md, extensions=extensions, output_format='html5')
    doc = jinja2.Template(TEMPLATE).render(content=html, title=title)
    args.out.write(doc)
 def test_formatTimedelta(self):
     now = datetime.now()
     self.assertEqual(formatTimedelta(now - now), '0:00:00')
示例#3
0
                block_no = entry.identifier
                if "block" in entry:
                    trxs = entry["block"]["transactions"]
                else:
                    trxs = entry["transactions"]

                for tx in trxs:
                    for op in tx["operations"]:
                        total_transaction += 1
                if "block" in entry:
                    block_time = parse_time(entry["block"]["timestamp"])
                else:
                    block_time = parse_time(entry["timestamp"])

                if block_time > stopTime:
                    total_duration = formatTimedelta(datetime.now() -
                                                     startTime)
                    last_block_id = block_no
                    avtran = total_transaction / (last_block_id - 19273700)
                    break
            start_time = time.time()

            stopOP = virtual_op_count - how_many_virtual_op + 1
            i = 0
            for acc_op in account.history_reverse(stop=stopOP):
                i += 1
            total_duration_acc = formatTimedelta(datetime.now() - startTime)

            print("* Processed %d blockchain minutes in %s" %
                  (how_many_minutes, total_duration))
            print("* Processed %d account ops in %s" % (i, total_duration_acc))
            print("* blockchain version: %s" % (blockchain_version))
示例#4
0
    def update_account_hist(self):
        if self.hist_account is None:
            return
        votes = []
        daily_curation = 0
        daily_author_SP = 0
        daily_author_SBD = 0
        daily_author_STEEM = 0
        self.append_account_hist()

        new_op_found = False

        start_block = self.account_hist_info["start_block"]
        if start_block == 0:
            first_call = True
        else:
            first_call = False
        trx_ids = self.account_hist_info["trx_ids"]

        for op in self.account_history:
            if op["block"] < start_block:
                # last_block = op["block"]
                continue
            elif op["block"] == start_block:
                if op["trx_id"] in trx_ids:
                    continue
                else:
                    trx_ids.append(op["trx_id"])
            else:
                trx_ids = [op["trx_id"]]
            start_block = op["block"]
            new_op_found = True
            op_timedelta = formatTimedelta(
                addTzInfo(datetime.utcnow()) -
                formatTimeString(op["timestamp"]))
            op_local_time = formatTimeString(op["timestamp"]).astimezone(
                tz.tzlocal())
            # print("Read %d" % op["index"])
            if op["type"] == "vote":
                if op["voter"] == self.hist_account["name"]:
                    continue
                if op["weight"] >= 0:

                    self.lastUpvotesListWidget.insertItem(
                        0, "%s - %s (%.2f %%) upvote %s" %
                        (op_timedelta, op["voter"], op["weight"] / 100,
                         op["permlink"]))
                    hist_item = "%s - %s - %s (%.2f %%) upvote %s" % (
                        op_local_time, op["type"], op["voter"],
                        op["weight"] / 100, op["permlink"])
                    tray_item = "%s - %s (%.2f %%) upvote %s" % (
                        op["type"], op["voter"], op["weight"] / 100,
                        op["permlink"])
                else:
                    hist_item = "%s - %s - %s (%.2f %%) downvote %s" % (
                        op_local_time, op["type"], op["voter"],
                        op["weight"] / 100, op["permlink"])
                    tray_item = "%s - %s (%.2f %%) downvote %s" % (
                        op["type"], op["voter"], op["weight"] / 100,
                        op["permlink"])

                self.accountHistListWidget.insertItem(0, hist_item)
            elif op["type"] == "curation_reward":
                curation_reward = self.stm.vests_to_sp(
                    Amount(op["reward"], steem_instance=self.stm))
                self.lastCurationListWidget.insertItem(
                    0, "%s - %.3f HP for %s" %
                    (op_timedelta, curation_reward,
                     construct_authorperm(op["comment_author"],
                                          op["comment_permlink"])))
                hist_item = "%s - %s - %.3f HP for %s" % (
                    op_local_time, op["type"], curation_reward,
                    construct_authorperm(op["comment_author"],
                                         op["comment_permlink"]))
                tray_item = "%s - %.3f HP for %s" % (
                    op["type"], curation_reward,
                    construct_authorperm(op["comment_author"],
                                         op["comment_permlink"]))
                self.accountHistListWidget.insertItem(0, hist_item)
            elif op["type"] == "author_reward":
                sbd_payout = (Amount(op["sbd_payout"],
                                     steem_instance=self.stm))
                steem_payout = (Amount(op["steem_payout"],
                                       steem_instance=self.stm))
                sp_payout = self.stm.vests_to_sp(
                    Amount(op["vesting_payout"], steem_instance=self.stm))
                self.lastAuthorListWidget.insertItem(
                    0, "%s - %s %s %.3f HP for %s" %
                    (op_timedelta, str(sbd_payout), str(steem_payout),
                     sp_payout, op["permlink"]))
                hist_item = "%s - %s - %s %s %.3f SP for %s" % (
                    op_local_time, op["type"], str(sbd_payout),
                    str(steem_payout), sp_payout, op["permlink"])
                tray_item = "%s - %s %s %.3f SP for %s" % (
                    op["type"], str(sbd_payout), str(steem_payout), sp_payout,
                    op["permlink"])
                self.accountHistListWidget.insertItem(0, hist_item)
            elif op["type"] == "custom_json":
                hist_item = "%s - %s - %s" % (op_local_time, op["type"],
                                              op["id"])
                tray_item = "%s - %s" % (op["type"], op["id"])
                self.accountHistListWidget.insertItem(0, hist_item)
            elif op["type"] == "transfer":
                hist_item = "%s - %s - %s from %s" % (
                    op_local_time, op["type"],
                    str(Amount(op["amount"],
                               steem_instance=self.stm)), op["from"])
                tray_item = "%s - %s from %s" % (
                    op["type"],
                    str(Amount(op["amount"],
                               steem_instance=self.stm)), op["from"])
                self.accountHistListWidget.insertItem(0, hist_item)
            elif op["type"] == "comment":
                comment_type = "post"
                if op["parent_author"] != "":
                    hist_item = "%s - comment on %s - %s from %s" % (
                        op_local_time,
                        construct_authorperm(
                            op["parent_author"],
                            op["parent_permlink"]), op["title"], op["author"])
                    tray_item = "comment from %s: %s on %s" % (
                        op["author"], op["body"][:100], op["title"])
                else:
                    hist_item = "%s - post - %s from %s" % (
                        op_local_time, op["title"], op["author"])
                    tray_item = "post from %s: %s" % (op["author"],
                                                      op["title"])
                self.accountHistListWidget.insertItem(0, hist_item)
            else:
                hist_item = "%s - %s" % (op_local_time, op["type"])
                tray_item = "%s" % (op["type"])
                self.accountHistListWidget.insertItem(0, hist_item)

            if self.accountHistNotificationCheckBox.isChecked(
            ) and not first_call:
                self.tray.showMessage(self.hist_account["name"], tray_item)

        if new_op_found:
            self.account_hist_info["start_block"] = start_block
            self.account_hist_info["trx_ids"] = trx_ids

            for op in self.account_history:
                if op["type"] == "vote":
                    if op["voter"] == self.hist_account["name"]:
                        continue
                    votes.append(op)
                elif op["type"] == "curation_reward":
                    curation_reward = self.stm.vests_to_sp(
                        Amount(op["reward"], steem_instance=self.stm))
                    daily_curation += curation_reward
                elif op["type"] == "author_reward":
                    sbd_payout = (Amount(op["sbd_payout"],
                                         steem_instance=self.stm))
                    steem_payout = (Amount(op["steem_payout"],
                                           steem_instance=self.stm))
                    sp_payout = self.stm.vests_to_sp(
                        Amount(op["vesting_payout"], steem_instance=self.stm))
                    daily_author_SP += sp_payout
                    daily_author_STEEM += float(steem_payout)
                    daily_author_SBD += float(sbd_payout)

            reward_text = "Curation reward (last 24 h): %.3f HP\n" % daily_curation
            reward_text += "Author reward (last 24 h):\n"
            reward_text += "%.3f HP - %.3f HIVE - %.3f HBD" % (
                daily_author_SP, (daily_author_STEEM), (daily_author_SBD))
            self.text2.setText(reward_text)
示例#5
0
    def update_account_hist(self):
        if self.hist_account is None:
            return        
        votes = []
        daily_curation = 0
        daily_author_SP = 0
        daily_author_SBD = 0
        daily_author_STEEM = 0
        self.append_account_hist()
        
        new_op_found = False
        
        start_block = self.account_hist_info["start_block"]
        if start_block == 0:
            first_call = True
            b = Blockchain()
            start_block = b.get_current_block_num() - 20 * 60 * 24 * 7
            self.account_hist_info["start_block"] = start_block
        else:
            first_call = False

        ops = self.db.load_account_hist(start_block)
     
        for op in ops:
            if op["block"] < start_block:
                # last_block = op["block"]
                continue

            start_block = op["block"]
            new_op_found = True
            tray_item = None
            op_timedelta = formatTimedelta(addTzInfo(datetime.utcnow()) - addTzInfo(op["timestamp"]))
            op_local_time = addTzInfo(op["timestamp"]).astimezone(tz.tzlocal())
            # print("Read %d" % op["index"])
            self.accountHistTableWidget.insertRow(0)
            self.accountHistTableWidget.setItem(0, 4, QTableWidgetItem(str(op_local_time)))
            if op["type"] == "vote":
                
                
                if op["voter"] == self.hist_account["name"]:
                    self.accountHistTableWidget.setItem(0, 0, QTableWidgetItem("Vote"))
                    self.accountHistTableWidget.setItem(0, 1, QTableWidgetItem(op["author"]))
                    
                elif op["weight"] >= 0:
                    self.accountHistTableWidget.setItem(0, 0, QTableWidgetItem("Vote Post"))
                    self.accountHistTableWidget.setItem(0, 1, QTableWidgetItem(op["voter"]))
                    tray_item = "%s - %s (%.2f %%) vote %s" % (op["type"], op["voter"], op["weight"] / 100, op["permlink"])
                else:
                    self.accountHistTableWidget.setItem(0, 0, QTableWidgetItem("Dowvote Post"))
                    self.accountHistTableWidget.setItem(0, 1, QTableWidgetItem(op["voter"]))
                    # hist_item.setToolTip(0, op["permlink"])
                    tray_item = "%s - %s (%.2f %%) downvote %s" % (op["type"], op["voter"], op["weight"] / 100, op["permlink"])
                
                
                self.accountHistTableWidget.setItem(0, 2, QTableWidgetItem("%.2f %%" % (op["weight"] / 100)))
                
            elif op["type"] == "curation_reward":
                self.accountHistTableWidget.setItem(0, 0, QTableWidgetItem(op["type"]))
                
                curation_reward = self.stm.vests_to_sp(Amount(op["reward"], steem_instance=self.stm))
                self.accountHistTableWidget.setItem(0, 1, QTableWidgetItem("%.3f HP" % curation_reward))
                self.accountHistTableWidget.setItem(0, 2, QTableWidgetItem(construct_authorperm(op["comment_author"], op["comment_permlink"])))
                hist_item = "%s - %s - %.3f HP for %s" % (op_local_time, op["type"], curation_reward, construct_authorperm(op["comment_author"], op["comment_permlink"]))
                tray_item = "%s - %.3f HP for %s" % (op["type"], curation_reward, construct_authorperm(op["comment_author"], op["comment_permlink"]))
            elif op["type"] == "author_reward":
                self.accountHistTableWidget.setItem(0, 0, QTableWidgetItem(op["type"]))
                sbd_payout = (Amount(op["sbd_payout"], steem_instance=self.stm))
                steem_payout = (Amount(op["steem_payout"], steem_instance=self.stm))
                sp_payout = self.stm.vests_to_sp(Amount(op["vesting_payout"], steem_instance=self.stm))
                
                hist_item = "%s - %s - %s %s %.3f SP for %s" % (op_local_time, op["type"], str(sbd_payout), str(steem_payout), sp_payout, op["permlink"])
                tray_item = "%s - %s %s %.3f SP for %s" % (op["type"], str(sbd_payout), str(steem_payout), sp_payout, op["permlink"])
            elif op["type"] == "custom_json":
                self.accountHistTableWidget.setItem(0, 0, QTableWidgetItem(op["type"]))
                self.accountHistTableWidget.setItem(0, 1, QTableWidgetItem(op["json_id"]))
                json_data = QTableWidgetItem(op["json"])
                json_data.setToolTip(op["json"])
                self.accountHistTableWidget.setItem(0, 2, json_data)
                hist_item = "%s - %s - %s" % (op_local_time, op["type"], op["id"])
                tray_item = "%s - %s" % (op["type"], op["json_id"])
            elif op["type"] == "transfer":
                self.accountHistTableWidget.setItem(0, 0, QTableWidgetItem(op["type"]))
                hist_item = "%s - %s - %s from %s" % (op_local_time, op["type"], str(Amount(op["amount"], steem_instance=self.stm)), op["from"])
                tray_item = "%s - %s from %s" % (op["type"], str(Amount(op["amount"], steem_instance=self.stm)), op["from"])
            elif op["type"] == "comment":
                
                
                if op["parent_author"] != "":
                    comment_type = "comment"
                    hist_item = "%s - comment on %s - %s from %s" % (op_local_time, construct_authorperm(op["parent_author"], op["parent_permlink"]), op["title"], op["author"])
                    tray_item = "comment from %s: %s on %s" % (op["author"], op["body"][:100], op["title"])
                    self.accountHistTableWidget.setItem(0, 0, QTableWidgetItem(op["type"]))
                    self.accountHistTableWidget.setItem(0, 1, QTableWidgetItem(op["author"]))
                    body = QTableWidgetItem(op["body"])
                    body.setToolTip(op["body"])
                    self.accountHistTableWidget.setItem(0, 2, body)
                else:
                    comment_type = "post"
                    hist_item = "%s - post - %s from %s" % (op_local_time, op["title"], op["author"])
                    tray_item = "post from %s: %s" % (op["author"], op["title"])
                self.accountHistTableWidget.setItem(0, 0, QTableWidgetItem(comment_type))
            elif op["type"] == "producer_reward":
                self.accountHistTableWidget.setItem(0, 0, QTableWidgetItem(op["type"]))
                self.accountHistTableWidget.setItem(0, 1, QTableWidgetItem(" %.3f HP" % float(self.stm.vests_to_sp(Amount(op["vesting_shares"])))))
                hist_item = "%s - %s" % (op_local_time, op["type"])
                tray_item = "%s - %.3f HP" % (op["type"], float(self.stm.vests_to_sp(Amount(op["vesting_shares"]))))               
            else:
                self.accountHistTableWidget.setItem(0, 0, QTableWidgetItem(op["type"]))
                hist_item = "%s - %s" % (op_local_time, op["type"])
                tray_item = "%s" % (op["type"])
            
            if self.accountHistNotificationCheckBox.isChecked() and not first_call and tray_item is not None:
                self.tray.showMessage(self.hist_account["name"], tray_item)

        if new_op_found:
            self.account_hist_info["start_block"] = start_block
            
            for op in ops:
                if op["type"] == "vote":
                    if op["voter"] == self.hist_account["name"]:
                        continue
                    votes.append(op)
                elif op["type"] == "curation_reward":
                    curation_reward = self.stm.vests_to_sp(Amount(op["reward"], steem_instance=self.stm))
                    daily_curation += curation_reward
                elif op["type"] == "author_reward":
                    sbd_payout = (Amount(op["sbd_payout"], steem_instance=self.stm))
                    steem_payout = (Amount(op["steem_payout"], steem_instance=self.stm))
                    sp_payout = self.stm.vests_to_sp(Amount(op["vesting_payout"], steem_instance=self.stm))
                    daily_author_SP += sp_payout
                    daily_author_STEEM += float(steem_payout)
                    daily_author_SBD += float(sbd_payout)        
        
            
            reward_text = "Curation reward (last 24 h): %.3f HP\n" % daily_curation
            reward_text += "Author reward (last 24 h):\n"
            reward_text += "%.3f HP - %.3f HIVE - %.3f HBD" % (daily_author_SP, (daily_author_STEEM), (daily_author_SBD))
            self.text2.setText(reward_text)