예제 #1
0
    def test_export(self):
        bts = self.bts

        if bts.rpc.get_use_appbase():
            content = bts.rpc.get_discussion(
                {
                    'author': self.author,
                    'permlink': self.permlink
                }, api="tags")
        else:
            content = bts.rpc.get_content(self.author, self.permlink)

        c = Comment(self.authorperm, hive_instance=bts)
        keys = list(content.keys())
        json_content = c.json()
        exclude_list = ["json_metadata", "reputation", "active_votes"]
        for k in keys:
            if k not in exclude_list:
                if isinstance(content[k], dict) and isinstance(
                        json_content[k], list):
                    self.assertEqual(list(content[k].values()),
                                     json_content[k])
                elif isinstance(content[k], str) and isinstance(
                        json_content[k], str):
                    self.assertEqual(content[k].encode('utf-8'),
                                     json_content[k].encode('utf-8'))
                else:
                    self.assertEqual(content[k], json_content[k])
예제 #2
0
 def test_delete(self):
     bts = self.bts
     bts.txbuffer.clear()
     c = Comment(self.authorperm, hive_instance=bts)
     tx = c.delete(account="test")
     self.assertEqual((tx["operations"][0][0]), "delete_comment")
     op = tx["operations"][0][1]
     self.assertIn(self.author, op["author"])
예제 #3
0
 def test_reply(self):
     bts = self.bts
     bts.txbuffer.clear()
     c = Comment(self.authorperm, hive_instance=bts)
     tx = c.reply(body="Good post!", author="test")
     self.assertEqual((tx["operations"][0][0]), "comment")
     op = tx["operations"][0][1]
     self.assertIn("test", op["author"])
예제 #4
0
 def test_edit_replace(self):
     bts = self.bts
     bts.txbuffer.clear()
     c = Comment(self.authorperm, hive_instance=bts)
     body = c.body + "test"
     tx = c.edit(body, meta=c["json_metadata"], replace=True)
     self.assertEqual((tx["operations"][0][0]), "comment")
     op = tx["operations"][0][1]
     self.assertIn(self.author, op["author"])
     self.assertEqual(body, op["body"])
예제 #5
0
 def test_edit(self):
     bts = self.bts
     bts.txbuffer.clear()
     c = Comment(self.authorperm, hive_instance=bts)
     c.edit(c.body, replace=False)
     body = c.body + "test"
     tx = c.edit(body, replace=False)
     self.assertEqual((tx["operations"][0][0]), "comment")
     op = tx["operations"][0][1]
     self.assertIn(self.author, op["author"])
예제 #6
0
    def test_vote(self):
        bts = self.bts
        c = Comment(self.authorperm, hive_instance=bts)
        bts.txbuffer.clear()
        tx = c.vote(100, account="test")
        self.assertEqual((tx["operations"][0][0]), "vote")
        op = tx["operations"][0][1]
        self.assertIn("test", op["voter"])
        c.hive.txbuffer.clear()
        tx = c.upvote(weight=150, voter="test")
        op = tx["operations"][0][1]
        self.assertEqual(op["weight"], 10000)
        c.hive.txbuffer.clear()
        tx = c.upvote(weight=99.9, voter="test")
        op = tx["operations"][0][1]
        self.assertEqual(op["weight"], 9990)

        c.hive.txbuffer.clear()
        tx = c.downvote(weight=150, voter="test")
        op = tx["operations"][0][1]
        self.assertEqual(op["weight"], -10000)
        c.hive.txbuffer.clear()
        tx = c.downvote(weight=99.9, voter="test")
        op = tx["operations"][0][1]
        self.assertEqual(op["weight"], -9990)
예제 #7
0
 def test_comment(self, node_param):
     if node_param == "instance":
         set_shared_hive_instance(self.bts)
         o = Comment(self.authorperm)
         self.assertIn(o.hive.rpc.url, self.urls)
         with self.assertRaises(RPCConnection):
             Comment(self.authorperm,
                     hive_instance=Hive(node="https://abc.d",
                                        autoconnect=False,
                                        num_retries=1))
     else:
         set_shared_hive_instance(
             Hive(node="https://abc.d", autoconnect=False, num_retries=1))
         hv = self.bts
         o = Comment(self.authorperm, hive_instance=hv)
         self.assertIn(o.hive.rpc.url, self.urls)
         with self.assertRaises(RPCConnection):
             Comment(self.authorperm)
예제 #8
0
파일: views.py 프로젝트: holgern/hiveview
def post_detail(request, author, permlink, **args):
    author_perm = construct_authorperm(author, permlink)
    post = Comment(author_perm, hive_instance=hv)
    if post:
        replies = hvpy.get_content_replies(author, permlink)
        post = strip(post)
        for reply in replies:
            reply = strip(reply)
    return render(request, 'blog/post_detail.html', {'post': post, 'replies': replies})
예제 #9
0
    def test_comment_dict(self):
        bts = self.bts
        title = ''
        cnt = 0
        while title == '' and cnt < 5:
            c = Comment({
                'author': self.author,
                'permlink': self.permlink
            },
                        hive_instance=bts)
            c.refresh()
            title = c.title
            cnt += 1
            if title == '':
                c.hive.rpc.next()
                c.refresh()
                title = c.title

        self.assertEqual(c.author, self.author)
        self.assertEqual(c.permlink, self.permlink)
        self.assertEqual(c.authorperm, self.authorperm)
        self.assertEqual(c.category, self.category)
        self.assertEqual(c.parent_author, '')
        self.assertEqual(c.parent_permlink, self.category)
        self.assertEqual(c.title, self.title)
예제 #10
0
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)
예제 #11
0
def main(args=None):
    """pandoc -s test.md  --from markdown-blank_before_header-blank_before_blockquote+lists_without_preceding_blankline    -o test.pdf"""
    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"]
    if True:
        md = '% Title:\t ' + title + '\n'
        md += '% Author:\t' + author + '(%.2f) ' % (rep) + '\n'
        md += '% Date:\t' + time_created.strftime("%d.%m.%Y") + '\n'
        md += '% Comment:\n'
    else:
        md = '# ' + title + '\n'
        md += author + '(%.2f) ' % (rep) + ' ' + time_created.strftime(
            "%d.%m.%Y") + '\n\n'
    md += comment["body"]

    args.out.write(md)
예제 #12
0
 def test_comment(self):
     bts = self.bts
     with self.assertRaises(exceptions.ContentDoesNotExistsException):
         Comment("@abcdef/abcdef", hive_instance=bts)
     title = ''
     cnt = 0
     while title == '' and cnt < 5:
         c = Comment(self.authorperm, hive_instance=bts)
         title = c.title
         cnt += 1
         if title == '':
             c.hive.rpc.next()
             c.refresh()
             title = c.title
     self.assertTrue(isinstance(c.id, int))
     self.assertTrue(c.id > 0)
     self.assertEqual(c.author, self.author)
     self.assertEqual(c.permlink, self.permlink)
     self.assertEqual(c.authorperm, self.authorperm)
     self.assertEqual(c.category, self.category)
     self.assertEqual(c.parent_author, '')
     self.assertEqual(c.parent_permlink, self.category)
     self.assertEqual(c.title, self.title)
     self.assertTrue(len(c.body) > 0)
     self.assertTrue(isinstance(c.json_metadata, dict))
     self.assertTrue(c.is_main_post())
     self.assertFalse(c.is_comment())
     if c.is_pending():
         self.assertFalse(
             (c.time_elapsed().total_seconds() / 60 / 60 / 24) > 7.0)
     else:
         self.assertTrue(
             (c.time_elapsed().total_seconds() / 60 / 60 / 24) > 7.0)
     self.assertTrue(isinstance(c.get_reblogged_by(), list))
     self.assertTrue(len(c.get_reblogged_by()) > 0)
     self.assertTrue(isinstance(c.get_votes(), list))
     self.assertTrue(len(c.get_votes()) > 0)
     self.assertTrue(isinstance(c.get_votes()[0], Vote))
예제 #13
0
 def test_rehive(self):
     bts = self.bts
     bts.txbuffer.clear()
     c = Comment(self.authorperm, hive_instance=bts)
     tx = c.rehive(account="test")
     self.assertEqual((tx["operations"][0][0]), "custom_json")
예제 #14
0
    def vote(self, vote_event):
        def process_vote_content(event):
            start_rshares = 0.0
            for vote in event["active_votes"]:
                if vote["voter"] == vote_event["voter"] and float(
                        vote["rshares"]) < 0:
                    if start_rshares + float(vote["rshares"]) < 0:
                        flag_power = 0 - start_rshares - float(vote["rshares"])
                    else:
                        flag_power = 0
                    downvote_power = 0 - vote["rshares"] - flag_power
                    self.wtw.update(vote["voter"], vote_event["author"],
                                    downvote_power, flag_power)

        def lookup_accounts(acclist):
            def user_info(accounts):
                if len(acclist) != len(accounts):
                    print("OOPS:", len(acclist), len(accounts), acclist)
                for index in range(0, len(accounts)):
                    a = accounts[index]
                    account = acclist[index]
                    vp = (a["vesting_shares"].amount +
                          a["received_vesting_shares"].amount -
                          a["delegated_vesting_shares"].amount) / 1000000.0
                    fish = "redfish"
                    if vp >= 1.0:
                        fish = "minnow"
                    if vp >= 10.0:
                        fish = "dolphin"
                    if vp >= 100:
                        fish = "orca"
                    if vp > 1000:
                        fish = "whale"
                    racc = None
                    proxy = None
                    related = list()
                    if a["recovery_account"] != "hive" and a[
                            "recovery_account"] != "":
                        related.append(a["recovery_account"])
                    if a["proxy"] != "":
                        related.append(a["proxy"])
                    self.wtw.set_account_info(account, fish, related)
                    accl2 = list()
                    if racc is not None and racc not in self.looked_up:
                        accl2.append(racc)
                    if proxy is not None and proxy not in self.looked_up:
                        accl2.append(proxy)
                    if len(accl2) > 0:
                        lookup_accounts(accl2)

            accounts = []
            for a in acclist:
                accounts.append(Account(a))
            user_info(accounts)

        if vote_event["weight"] < 0:
            authorperm = construct_authorperm(vote_event["author"],
                                              vote_event["permlink"])
            # print(authorperm)
            try:
                process_vote_content(Comment(authorperm))
            except exceptions.ContentDoesNotExistsException:
                print("Could not find Comment: %s" % (authorperm))
            al = list()
            if not vote_event["voter"] in self.looked_up:
                al.append(vote_event["voter"])
                self.looked_up.add(vote_event["voter"])
            if not vote_event["author"] in self.looked_up:
                al.append(vote_event["author"])
                self.looked_up.add(vote_event["author"])
            if len(al) > 0:
                lookup_accounts(al)
예제 #15
0
def benchmark_node(node, how_many_minutes=10, how_many_seconds=30):
    block_count = 0
    history_count = 0
    access_time = 0
    follow_time = 0
    blockchain_version = u'0.0.0'
    successful = True
    error_msg = None
    start_total = timer()
    max_batch_size = None
    threading = False
    thread_num = 16

    authorpermvoter = u"@gtg/hive-pressure-4-need-for-speed|gandalf"
    [author, permlink, voter] = resolve_authorpermvoter(authorpermvoter)
    authorperm = construct_authorperm(author, permlink)
    last_block_id = 19273700
    try:
        hv = Hive(node=node, num_retries=3, num_retries_call=3, timeout=30)
        blockchain = Blockchain(hive_instance=hv)
        blockchain_version = hv.get_blockchain_version()

        last_block = Block(last_block_id, hive_instance=hv)

        stopTime = last_block.time() + timedelta(seconds=how_many_minutes * 60)
        total_transaction = 0

        start = timer()
        for entry in blockchain.blocks(start=last_block_id, max_batch_size=max_batch_size, threading=threading, thread_num=thread_num):
            block_no = entry.identifier
            block_count += 1
            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:
                last_block_id = block_no
                break
            if timer() - start > how_many_seconds or quit_thread:
                break
    except NumRetriesReached:
        error_msg = 'NumRetriesReached'
        block_count = -1
    except KeyboardInterrupt:
        error_msg = 'KeyboardInterrupt'
        # quit = True
    except Exception as e:
        error_msg = str(e)
        block_count = -1

    try:
        hv = Hive(node=node, num_retries=3, num_retries_call=3, timeout=30)
        account = Account("gtg", hive_instance=hv)
        blockchain_version = hv.get_blockchain_version()

        start = timer()
        for acc_op in account.history_reverse(batch_size=100):
            history_count += 1
            if timer() - start > how_many_seconds or quit_thread:
                break
    except NumRetriesReached:
        error_msg = 'NumRetriesReached'
        history_count = -1
        successful = False
    except KeyboardInterrupt:
        error_msg = 'KeyboardInterrupt'
        history_count = -1
        successful = False
        # quit = True
    except Exception as e:
        error_msg = str(e)
        history_count = -1
        successful = False

    try:
        hv = Hive(node=node, num_retries=3, num_retries_call=3, timeout=30)
        account = Account("gtg", hive_instance=hv)
        blockchain_version = hv.get_blockchain_version()

        start = timer()
        Vote(authorpermvoter, hive_instance=hv)
        stop = timer()
        vote_time = stop - start
        start = timer()
        Comment(authorperm, hive_instance=hv)
        stop = timer()
        comment_time = stop - start
        start = timer()
        Account(author, hive_instance=hv)
        stop = timer()
        account_time = stop - start
        start = timer()
        account.get_followers()
        stop = timer()
        follow_time = stop - start
        access_time = (vote_time + comment_time + account_time + follow_time) / 4.0
    except NumRetriesReached:
        error_msg = 'NumRetriesReached'
        access_time = -1
    except KeyboardInterrupt:
        error_msg = 'KeyboardInterrupt'
        # quit = True
    except Exception as e:
        error_msg = str(e)
        access_time = -1
    return {'successful': successful, 'node': node, 'error': error_msg,
            'total_duration': timer() - start_total, 'block_count': block_count,
            'history_count': history_count, 'access_time': access_time, 'follow_time': follow_time,
            'version': blockchain_version}