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, steem_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])
def staff_pick_section(staff_picks): """Creates the staff pick section for the Utopian weekly post.""" LOGGER.info("Generating staff pick statistics section...") section = "## Staff Picks" for staff_pick in staff_picks["staff_picks"]: url = staff_pick["url"] post = Comment(url) title = post.json()["title"] # If title can't be retrieved set it to the post's URL if not title: title = url author = staff_pick['author'] category = staff_pick['category'] # Add staff pick to the string section += ( f"<br><br>### <a href='{url}'>{title}</a> by @{author} " f"[{category}]<br><br>[Image (contributor profile image / image from " "the post)]<br><br>[Paragraph: Background info on project etc.]" "<br><br>[Paragraph: CM review, including etc.]<br><br>" f"Total payout: {staff_pick['total_payout']:.2f} STU<br>" f"Number of votes: {staff_pick['total_votes']}") return section
def contribution(row): """Create a dictionary for a contribution post. :param row: list of values from worksheet :return: dict for contribution """ url_split = row[2].split('/') author = url_split[4][1:] if url_split[4][0] == "@" else url_split[3][1:] permlink = url_split[5] if url_split[4][0] == "@" else url_split[4] review_date = parse_date_to_iso(row[1]) repo_split = row[3].split('/') if 'github.com' in row[3] else [] staff_pick = { 'picked_by': row[8], 'date': parse_date_to_iso(row[7]) } if row[6].lower() == 'yes' else None repo_full_name = f'{repo_split[3]}/{repo_split[4].split("?")[0]}' \ if len(repo_split) > 4 else '' score = float(row[5]) if row[5] else 0 category = row[4] post = Comment(f'@{author}/{permlink}') post_meta = post.json_metadata post_json = post.json() created = parse_date_to_iso(post_json['created']) contrib = { 'author': author, 'permlink': permlink, 'post_category': 'utopian-io', 'moderator': { 'account': (row[0]), 'date': review_date }, 'repository': { 'full_name': repo_full_name, 'html_url': (f'https://github.com/{repo_full_name}' if repo_full_name else '') }, 'score': score, 'status': get_status(row), 'category': category or (post_meta.get('tags')[1] if len(post_meta.get('tags')) > 1 else ''), 'tags': (post_meta.get('tags')), 'created': created, 'body': (post_json.get('body', '')), 'utopian_vote': (get_utopian_vote(post)), 'staff_pick': staff_pick } return contrib
def info(permalink): post = Comment(permalink) p_export = post.json() p_info = [{ "body": p_export["body"], "title": p_export["title"], "author": p_export["author"], "permalink": p_export["permlink"] }] return p_info
def get_utopian_vote(post: Comment): """Get information about Utopian vote. :param post: post data from blockchain :return: dict with the vote information """ voters = post.json()['active_votes'] for voter in voters: if voter['voter'] == 'utopian-io': return voter return None
def test_export(self, node_param): if node_param == "non_appbase": bts = self.bts content = bts.rpc.get_content(self.author, self.permlink) else: bts = self.appbase content = bts.rpc.get_discussion({'author': self.author, 'permlink': self.permlink}, api="tags") c = Comment(self.authorperm, steem_instance=bts) keys = list(content.keys()) json_content = c.json() for k in keys: if k not in "json_metadata" and k != 'reputation' and k != 'active_votes': self.assertEqual(content[k], json_content[k])
def __resolve_authorperm(self): if self.authorperm is None or self.authorperm == "": return author, permlink = resolve_authorperm(self.authorperm) comment = Comment(self.authorperm) created = comment.json()["created"] acc = Account(author) body_versions = [] for h in acc.history_reverse(only_ops=["comment"]): if h["permlink"] != permlink: continue body_versions.append({"timestamp": h["timestamp"], "body": h["body"]}) if h["timestamp"] == created: break if len(body_versions) > 0: self.__main_window_ui.fileTreeView.grid() self.__main_window_ui.fileTreeYScrollbar.grid() self.__main_window_ui.fileTreeXScrollbar.grid() self.__main_window_ui.fileTreeView.delete(*self.__main_window_ui.fileTreeView.get_children()) self.__main_window_ui.fileTreeView.heading('#0', text=self.authorperm, anchor=W) body_left = "" body_right = "" for entry in body_versions[::-1]: if body_right == "": body_right = entry["body"] body_left = "" elif entry["body"].find("@@") > -1: import diff_match_patch as dmp_module dmp = dmp_module.diff_match_patch() patches = dmp.patch_fromText(entry["body"]) body_left = body_right body_right = dmp.patch_apply(patches, body_right)[0] else: body_left = body_right body_right = entry["body"] bindValue=(body_left, body_right, "") oid = self.__main_window_ui.fileTreeView.insert("", 'end', text=entry["timestamp"], value=bindValue, open=False, tags=('simple'))
def unvote_post(row, previous, current): """ Unvotes the given post and updates the spreadsheet to reflect this. """ url = row[2] account = Account(ACCOUNT) post = Comment(url, steem_instance=steem) # Check if actually voted on post votes = [vote["voter"] for vote in post.json()["active_votes"]] if ACCOUNT not in votes: logger.info(f"Never voted on {url} in the first place!") return # Unvote the post try: logger.info(f"Unvoting {url}") post.vote(0, account=account) time.sleep(3) # Edit comment update_comment(post) except Exception as error: logger.error(error) # Just in case sheet was updated in the meantime previous_reviewed = sheet.worksheet(title_previous) current_reviewed = sheet.worksheet(title_current) # Update row depending on which sheet it's in if row in previous: row_index = previous.index(row) + 1 previous_reviewed.update_cell(row_index, 10, "Unvoted") previous_reviewed.update_cell(row_index, 11, 0) elif row in current: row_index = current.index(row) + 1 current_reviewed.update_cell(row_index, 10, "Unvoted") current_reviewed.update_cell(row_index, 11, 0)
def contribution(row, status): """ Convert row to dictionary, only selecting values we want. """ contribution = Contribution(row) url = contribution.url if url == "": return if contribution.staff_pick.lower() == "yes": staff_picked = True else: staff_picked = False try: review_date = parse(contribution.review_date) except Exception: review_date = datetime(1970, 1, 1) if ((datetime.now() - review_date).seconds > 561600 and status != "unreviewed"): return total_payout = 0 # Check if post deleted try: comment = Comment(url) except Exception: return if contribution.review_status == "Pending": for reply in comment.get_replies(): if reply.author == contribution.moderator: review_date = reply["created"] comment_url = reply.permlink break else: review_date = datetime(1970, 1, 1) comment_url = "" else: comment_url = "" # Calculate total (pending) payout of contribution if comment.time_elapsed() > timedelta(days=7): total_payout = Amount(comment.json()["total_payout_value"]).amount else: total_payout = Amount(comment.json()["pending_payout_value"]).amount # Get votes, comments and author votes = comment.json()["net_votes"] comments = comment.json()["children"] author = comment.author # Add status for unvoted and pending if contribution.vote_status == "Unvoted": status = "unvoted" elif contribution.vote_status == "Pending": status = "pending" try: utopian_vote = Vote(f"{comment.authorperm}|utopian-io").sbd except Exception: voted_on = False utopian_vote = 0 if utopian_vote: voted_on = True else: voted_on = False # Check for when contribution not reviewed if contribution.score == "": score = None else: try: score = float(contribution.score) except Exception: score = None # Create contribution dictionary and return it new_contribution = { "moderator": contribution.moderator.strip(), "author": author, "review_date": review_date, "url": url, "repository": contribution.repository, "category": contribution.category, "staff_picked": staff_picked, "picked_by": contribution.picked_by, "status": status, "score": score, "voted_on": voted_on, "total_payout": total_payout, "total_votes": votes, "total_comments": comments, "utopian_vote": utopian_vote, "created": comment["created"], "title": comment.title, "review_status": contribution.review_status.lower(), "comment_url": comment_url } return new_contribution
def contribution(row, status): """ Convert row to dictionary, only selecting values we want. """ if row[2] == "": return # Check if contribution was staff picked if row[6].lower() == "yes": staff_picked = True else: staff_picked = False # Try and get date, since some people don't enter it correctly try: review_date = parse(row[1]) except Exception: review_date = datetime(1970, 1, 1) # If post > 7 days old don't check unless unreviewed if (datetime.now() - review_date).days > 7 and status != "unreviewed": return url = row[2] total_payout = 0 # Check if post deleted try: comment = Comment(url) except Exception: return # Calculate total (pending) payout of contribution if comment.time_elapsed() > timedelta(days=7): total_payout = Amount(comment.json()["total_payout_value"]).amount else: total_payout = Amount(comment.json()["pending_payout_value"]).amount # Get votes, comments and author votes = comment.json()["net_votes"] comments = comment.json()["children"] author = comment.author # Add status for unvoted and pending if row[9] == "Unvoted": status = "unvoted" elif row[9] == "Pending": status = "pending" # Check if contribution was voted on if row[9] == "Yes": voted_on = True try: utopian_vote = Vote(f"{comment.authorperm}|utopian-io").sbd except Exception: voted_on = False utopian_vote = 0 else: voted_on = False utopian_vote = 0 # Check for when contribution not reviewed if row[5] == "": score = None else: try: score = float(row[5]) except Exception: score = None # Create contribution dictionary and return it new_contribution = { "moderator": row[0].strip(), "author": author, "review_date": review_date, "url": url, "repository": row[3], "category": row[4], "staff_picked": staff_picked, "picked_by": row[8], "status": status, "score": score, "voted_on": voted_on, "total_payout": total_payout, "total_votes": votes, "total_comments": comments, "utopian_vote": utopian_vote, "created": comment["created"], "title": comment.title } return new_contribution