def _get_github_pat(self): github_pat = settings.get_env_var("GITHUB_PAT") or None if github_pat: github_pat += "@" else: github_pat = "" return github_pat
def build_all(ctx, accounts=None, host="github", debug=False, production=False): """ download the posts of all the accounts, and generate pages """ if not debug: debug_setting = settings.get_env_var("DEBUG") if debug_setting and debug_setting.lower() == "true": debug = True accounts = accounts or settings.get_env_var("STEEM_ACCOUNTS") or [] if accounts and len(accounts) > 0: if production: setup(ctx) for account in accounts.split(","): clean(ctx) count = download(ctx, account=account, host=host, debug=debug, production=production) if count > 0: build(ctx, debug)
def set_smart_duration(self): if not self.account: return if self._source_repo_exists() and self._blog_exists(): self.days = settings.get_env_var("DURATION") or 1.5 logger.info("The download duration has been set to {} days".format(self.days)) else: self.days = None logger.info("The download duration has been expanded to the entire lifetime of the account")
def download(ctx, account=None, tag=None, days=None, host="github", debug=False, clear=False, production=False): """ download the posts to local by the account """ if debug: settings.set_debug_mode() if clear: clean(ctx) settings.set_steem_node() account = account or settings.get_env_var("STEEM_ACCOUNT") tag = tag or settings.get_env_var("STEEM_TAG") days = days or settings.get_env_var("DURATION") clean_build = settings.get_env_var("CLEAN_BUILD") if clean_build and clean_build.lower() == "true": clean_build = True else: clean_build = False if clean_build: incremental = False else: incremental = production builder = BlogBuilder(account=account, tag=tag, days=days, host=host) if production and not clean_build: builder.set_smart_duration() builder.update_config(incremental=incremental) count = builder.download() if production: builder.update_workspace() if incremental: if production and count > 0: count = len(builder.list_new_posts()) else: count = len(builder.list_all_posts()) return count
def build_all(ctx, accounts=None, host="github", debug=False, production=False): """ download the posts of all the accounts, and generate pages """ if not debug: debug_setting = settings.get_env_var("DEBUG") if debug_setting and debug_setting.lower() == "true": debug = True accounts = accounts or settings.get_env_var("STEEM_ACCOUNTS") or [] if accounts and len(accounts) > 0: if production: setup(ctx) for account in accounts.split(","): try: logger.info("Start generating pages for account @{} ...".format(account)) clean(ctx) count = download(ctx, account=account, host=host, debug=debug, production=production) if count > 0: build(ctx, debug) except: logger.error("Failed when generating pages for account @{}.\nError: {}".format(account, traceback.format_exc()))
def update_config(self, incremental=False): if not self.account: return domain = self._get_domain() organization = BLOG_ORGANIZATION logo = BLOG_AVATAR favicon = BLOG_FAVICON language = settings.get_env_var("LANGUAGE") or "en" a = SteemAccount(self.account) author = self.account name = self._yaml_compatible(a.get_profile("name"), "") avatar = self._yaml_compatible(a.avatar(), "") # about = a.get_profile("about") or "" location = self._yaml_compatible(a.get_profile("location"), "") website = self._yaml_compatible(a.get_profile("website"), "''") incremental = "true" if incremental else "false" # build config file with template template = get_message("config") config = template.format(organization=organization, domain=domain, language=language, name=name, author=author, incremental=incremental) filename = CONFIG_FILE with open(filename, "w", encoding="utf-8") as f: f.write(config) logger.info("{} file has been updated for the account @{}".format( filename, author)) # build config theme file with template template = get_message("config.theme") config = template.format(organization=organization, favicon=favicon, logo=logo, author=author, name=name, location=location, avatar=avatar, website=website) filename = CONFIG_THEME_FILE with open(filename, "w", encoding="utf-8") as f: f.write(config) logger.info("{} file has been updated for the account @{}".format( filename, author))
def generate(ctx, account="teamcn-shop", tag=None, days=None, debug=False, production=False): """ generate the roster from the specified sources """ if debug: settings.set_debug_mode() settings.set_steem_node() account = account or settings.get_env_var("STEEM_ACCOUNT") tag = tag or settings.get_env_var("STEEM_TAG") days = days or settings.get_env_var("DURATION") incremental = settings.get_env_var("INCREMENTAL") or False crawler = RosterBuilder(account=account, tag=tag, days=days, incremental=incremental) crawler.crawl() return crawler.build()
def deploy(ctx, host="hexo"): """ deploy the static blog to the GitHub pages """ logger.info("launch the deploy on [{}]".format(host)) if host == "hexo": build(ctx) os.system("hexo deploy") elif host == "netlify": hook_id = settings.get_env_var("NETLIFY_HOOK") or None if hook_id: build_hook = "curl -X POST -d {} https://api.netlify.com/build_hooks/" + hook_id os.system(build_hook) else: logger.error("Failed: we need the hook ID to deploy") elif host == "github": pass else: pass
from steem.comment import SteemComment from steem.account import SteemAccount from steem.writer import Writer from steem.voter import Voter from steem.uploader import Uploader from steem.collector import get_comments, get_posts from steem.settings import settings, STEEM_HOST, STEEMD_HOST, STEEM_API_NODES from data.reader import SteemReader from cn_hello.newbies import Newbies from cn_hello.message import get_message, verify_message, build_table from cn_hello.analysis import draw_weekly_data, draw_quarterly_data, draw_all_data from utils.logging.logger import logger CN_HELLO_REVIEW_DURACTION = 3 # days CN_HELLO_ACCOUNT = settings.get_env_var("CN_HELLO_ACCOUNT") or "cn-hello" VOTE_WEIGHT = settings.get_env_var("CN_HELLO_VOTE_WEIGHT") or 50 SUMMARY_POST_TAGS = ["cn", "cn-hello", "cn-stats", "newbie", "zzan"] DAILY_SUMMARY_PREFIX = "CN区每日新人统计 Newbies Daily" WEEKLY_SUMMARY_PREFIX = "CN区每周新人数据汇总 Newbies Weekly" ACCESSIBLE_STEEM_HOST = "https://steem.buzz" CURRENT_API_NODE = settings.get_env_var('API_NODE') or STEEM_API_NODES[4] class CnHelloBot(SteemReader): def __init__(self, tag="cn", days=CN_HELLO_REVIEW_DURACTION): SteemReader.__init__(self, tag=tag, days=days) self.attributes = [
def __init__(self): self.sender = settings.get_env_var("TRANSFER_SENDER") self.wallet = SteemTransfer(account=self.sender)
def __init__(self): self.claimer_author = settings.get_env_var(PILOT_ACCOUNT_KEY) or DEFAULT_PILOT_ACCOUNT self.claimer_account = SteemAccount(author=self.claimer_author)