def refresh(self): post_author, post_permlink = resolve_identifier(self.identifier) post = self.steemd.get_content(post_author, post_permlink) if not post["permlink"]: raise PostDoesNotExist("Post does not exist: %s" % self.identifier) # If this 'post' comes from an operation, it might carry a patch if "body" in post and re.match("^@@", post["body"]): self.patched = True # Parse Times parse_times = ["active", "cashout_time", "created", "last_payout", "last_update", "max_cashout_time"] for p in parse_times: post[p] = parse_time(post.get(p, "1970-01-01T00:00:00")) # Parse Amounts sbd_amounts = [ "total_payout_value", "max_accepted_payout", "pending_payout_value", "curator_payout_value", "total_pending_payout_value", "promoted", ] for p in sbd_amounts: post[p] = Amount(post.get(p, "0.000 SBD")) # turn json_metadata into python dict meta_str = post.get("json_metadata", "{}") post['json_metadata'] = silent(json.loads)(meta_str) or {} post["tags"] = [] post['community'] = '' if isinstance(post['json_metadata'], dict): if post["depth"] == 0: post["tags"] = ( post["parent_permlink"], *get_in(post, ['json_metadata', 'tags'], default=[]) ) post['community'] = get_in(post, ['json_metadata', 'community'], default='') # If this post is a comment, retrieve the root comment self.root_identifier, self.category = self._get_root_identifier(post) self._store_post(post)
def profile(self): try: return get_in(self, ['json_metadata', 'profile'], default={}) except TypeError: pass return {}
def normalize_host(label, host_config): """Given a host entry, resolve it provided.""" # already OK, skip if sc.valid(scc.host, host_config): return host_config # malformed entry, incomplete & missing required entries if not sc.valid(scc.json_host, host_config): if 'address' not in host_config: reason = "missing 'address' field" elif 'profile' not in host_config: reason = "missing 'profile' field. Incomplete entries must refer to a profile" else: reason = None # will offer a generic default msg raise HostEntryError(label, host_config, reason=reason) # fetch referenced profile profile = get_in(conf, ['profiles', host_config['profile']]) if not profile: raise HostEntryProfileMissing(label, host_config) host_entry = {**profile['connection'], **host_config} try: return scc.host(host_entry) except Invalid as exc: raise HostEntryError( label, host_entry, reason=( "merging entry with profile '{}' does not produce a valid host entry" .format(host_config['profile'])), error=exc)
def compile_role_entry(role_entry): """creates a roledef entry in fabric's format. Resolves the referenced host labels into actual host_strings (fabric) and merges in the environment values. """ return { **role_entry.get('env', {}), 'hosts': [ cp.host_string(get_in(conf, ['hosts', label])) for label in role_entry['hosts'] ] }
def __init__(self, *, url=None, **kwargs): self.url = url or os.environ.get('DPAYD_HTTP_URL', 'https://greatchain.dpays.io') self.kwargs = kwargs self.session = kwargs.get('session', None) self.connector = get_in(kwargs, ['session', 'connector']) if not self.connector: self.connector = self._new_connector() if not self.session: self.session = self._new_session() self._batch_request_size = self.kwargs.get('batch_request_size', 150) self._concurrent_tasks_limit = self.kwargs.get( 'concurrent_tasks_limit', 10) self.verify_responses = kwargs.get('verify_responses', False) self._perf_history = deque(maxlen=2000) self._batch_request_count = 0 self._request_count = 0
def profile(self): with suppress(TypeError): return get_in(self, ['json_metadata', 'profile'], default={}) return {}
def role_host_strings(conf, role_label): """xx""" return [ host_string(get_in(conf, ['hosts', label])) for label in get_in(conf, ['roles', role_label, 'hosts'], []) ]
def undefined_host(host_label): """Returns input host label iff host could not be found in config.""" if not get_in(conf, ['hosts', host_label]): return host_label return False