|
16 | 16 | import random |
17 | 17 | import logging |
18 | 18 | import click |
| 19 | +import yaml |
19 | 20 | import re |
20 | 21 | from beem.instance import set_shared_steem_instance, shared_steem_instance |
21 | 22 | from beem.amount import Amount |
@@ -1473,7 +1474,9 @@ def beneficiaries(authorperm, beneficiaries): |
1473 | 1474 | "allow_votes": c["allow_votes"], |
1474 | 1475 | "allow_curation_rewards": c["allow_curation_rewards"]} |
1475 | 1476 |
|
1476 | | - for w in beneficiaries[0].split(","): |
| 1477 | + if isinstance(beneficiaries, tuple) and len(beneficiaries) == 1: |
| 1478 | + beneficiaries = beneficiaries[0].split(",") |
| 1479 | + for w in beneficiaries: |
1477 | 1480 | account_name = w.strip().split(":")[0] |
1478 | 1481 | if account_name[0] == "@": |
1479 | 1482 | account_name = account_name[1:] |
@@ -1508,6 +1511,139 @@ def beneficiaries(authorperm, beneficiaries): |
1508 | 1511 | print(tx) |
1509 | 1512 |
|
1510 | 1513 |
|
| 1514 | +@cli.command() |
| 1515 | +@click.argument('body', nargs=1) |
| 1516 | +@click.option('--account', '-a', help='Account are you posting from') |
| 1517 | +@click.option('--title', '-t', help='Title of the post') |
| 1518 | +@click.option('--permlink', '-p', help='Manually set the permlink (optional)') |
| 1519 | +@click.option('--tags', help='A komma separated list of tags to go with the post.') |
| 1520 | +@click.option('--reply_identifier', help=' Identifier of the parent post/comment, when set a comment is broadcasted') |
| 1521 | +@click.option('--community', help=' Name of the community (optional)') |
| 1522 | +@click.option('--beneficiaries', '-b', help='Post beneficiaries (komma separated, e.g. a:10%,b:20%)') |
| 1523 | +@click.option('--no-parse-body', help='Disable parsing of links, tags and images', is_flag=True, default=False) |
| 1524 | +def post(body, account, title, permlink, tags, reply_identifier, community, beneficiaries, no_parse_body): |
| 1525 | + """Set beneficaries""" |
| 1526 | + stm = shared_steem_instance() |
| 1527 | + if stm.rpc is not None: |
| 1528 | + stm.rpc.rpcconnect() |
| 1529 | + |
| 1530 | + if not account: |
| 1531 | + account = stm.config["default_account"] |
| 1532 | + author = account |
| 1533 | + if not unlock_wallet(stm): |
| 1534 | + return |
| 1535 | + with open(body) as f: |
| 1536 | + content = f.read() |
| 1537 | + parameter = {} |
| 1538 | + body = "" |
| 1539 | + if len(content.split("---")) > 1: |
| 1540 | + body = content.split("---")[-1] |
| 1541 | + docs = yaml.load_all(content.split("---")[-2]) |
| 1542 | + |
| 1543 | + for doc in docs: |
| 1544 | + for k,v in doc.items(): |
| 1545 | + parameter[k] = v |
| 1546 | + else: |
| 1547 | + body = content |
| 1548 | + if title is not None: |
| 1549 | + parameter["title"] = title |
| 1550 | + if tags is not None: |
| 1551 | + parameter["tags"] = tags |
| 1552 | + if permlink is not None: |
| 1553 | + parameter["permlink"] = permlink |
| 1554 | + if beneficiaries is not None: |
| 1555 | + parameter["beneficiaries"] = beneficiaries |
| 1556 | + if reply_identifier is not None: |
| 1557 | + parameter["reply_identifier"] = reply_identifier |
| 1558 | + tags = None |
| 1559 | + if "tags" in parameter: |
| 1560 | + tags = [] |
| 1561 | + if len(parameter["tags"].split(",")) > len(parameter["tags"].split(" ")): |
| 1562 | + for tag in parameter["tags"].split(","): |
| 1563 | + tags.append(tag.strip()) |
| 1564 | + else: |
| 1565 | + for tag in parameter["tags"].split(" "): |
| 1566 | + tags.append(tag.strip()) |
| 1567 | + title = "" |
| 1568 | + if "title" in parameter: |
| 1569 | + title = parameter["title"] |
| 1570 | + if "author" in parameter: |
| 1571 | + author = parameter["author"] |
| 1572 | + permlink = None |
| 1573 | + if "permlink" in parameter: |
| 1574 | + permlink = parameter["permlink"] |
| 1575 | + reply_identifier = None |
| 1576 | + if "reply_identifier" in parameter: |
| 1577 | + reply_identifier = parameter["reply_identifier"] |
| 1578 | + community = None |
| 1579 | + if "community" in parameter: |
| 1580 | + community = parameter["community"] |
| 1581 | + if "parse_body" in parameter: |
| 1582 | + parse_body = parameter["parse_body"] |
| 1583 | + else: |
| 1584 | + parse_body = not no_parse_body |
| 1585 | + beneficiaries = None |
| 1586 | + if "beneficiaries" in parameter: |
| 1587 | + beneficiaries_list = [] |
| 1588 | + beneficiaries_accounts = [] |
| 1589 | + beneficiaries_sum = 0 |
| 1590 | + for w in parameter["beneficiaries"].split(","): |
| 1591 | + account_name = w.strip().split(":")[0] |
| 1592 | + if account_name[0] == "@": |
| 1593 | + account_name = account_name[1:] |
| 1594 | + a = Account(account_name, steem_instance=stm) |
| 1595 | + if a["name"] in beneficiaries_accounts: |
| 1596 | + continue |
| 1597 | + if w.find(":") == -1: |
| 1598 | + percentage = -1 |
| 1599 | + else: |
| 1600 | + percentage = w.strip().split(":")[1] |
| 1601 | + if "%" in percentage: |
| 1602 | + percentage = percentage.strip().split("%")[0].strip() |
| 1603 | + percentage = float(percentage) |
| 1604 | + beneficiaries_sum += percentage |
| 1605 | + beneficiaries_list.append({"account": a["name"], "weight": int(percentage * 100)}) |
| 1606 | + beneficiaries_accounts.append(a["name"]) |
| 1607 | + |
| 1608 | + missing = 0 |
| 1609 | + for bene in beneficiaries_list: |
| 1610 | + if bene["weight"] < 0: |
| 1611 | + missing += 1 |
| 1612 | + index = 0 |
| 1613 | + for bene in beneficiaries_list: |
| 1614 | + if bene["weight"] < 0: |
| 1615 | + beneficiaries_list[index]["weight"] = int((int(100 * 100) - int(beneficiaries_sum * 100)) / missing) |
| 1616 | + index += 1 |
| 1617 | + beneficiaries = sorted(beneficiaries_list, key=lambda beneficiaries_list: beneficiaries_list["account"]) |
| 1618 | + tx = stm.post(title, body, author=author, permlink=permlink, reply_identifier=reply_identifier, community=community, |
| 1619 | + tags=tags, beneficiaries=beneficiaries, parse_body=parse_body) |
| 1620 | + if stm.unsigned and stm.nobroadcast and stm.steemconnect is not None: |
| 1621 | + tx = stm.steemconnect.url_from_tx(tx) |
| 1622 | + tx = json.dumps(tx, indent=4) |
| 1623 | + print(tx) |
| 1624 | + |
| 1625 | + |
| 1626 | +@cli.command() |
| 1627 | +@click.argument('authorperm', nargs=1) |
| 1628 | +@click.argument('body', nargs=1) |
| 1629 | +@click.option('--account', '-a', help='Account are you posting from') |
| 1630 | +@click.option('--title', '-t', help='Title of the post') |
| 1631 | +def replay(authorperm, body, account, title): |
| 1632 | + """replies to a comment""" |
| 1633 | + stm = shared_steem_instance() |
| 1634 | + if stm.rpc is not None: |
| 1635 | + stm.rpc.rpcconnect() |
| 1636 | + |
| 1637 | + if not account: |
| 1638 | + account = stm.config["default_account"] |
| 1639 | + if not unlock_wallet(stm): |
| 1640 | + return |
| 1641 | + c = Comment(authorperm, steem_instance=stm) |
| 1642 | + if title is None: |
| 1643 | + title = "" |
| 1644 | + c.rely(body, title=title, author=account) |
| 1645 | + |
| 1646 | + |
1511 | 1647 | @cli.command() |
1512 | 1648 | @click.argument('witness', nargs=1) |
1513 | 1649 | @click.option('--account', '-a', help='Your account') |
|
0 commit comments