def_write_content(self, post): folder = self._get_content_folder() c = SteemComment(comment=post)
# retrieve necessary data from steem title = post.title.replace('"', '') body = post.body date_str = post.json()["created"] date = date_str.replace('T', ' ') tags = "\n".join(["- {}".format(tag) for tag in c.get_tags()]) category = c.get_tags()[0] thumbnail = c.get_pic_url() or'' url = c.get_url()
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 = a.get_profile("name") or"" # about = a.get_profile("about") or "" location = a.get_profile("location") or"" avatar = a.get_profile("profile_image") or"" website = a.get_profile("website") or""
# build config file with template template = get_message("config") config = template.format(organization=organization, language=language, name=name, author=author) 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))
# URL ## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/' url:http://{organization}.github.io root:/@{author}/ permalink::category/:post_title/ permalink_defaults:
@task(help={ }) defbuild_all(ctx): """ download the posts of all the accounts, and generate pages """
accounts = settings.get_env_var("STEEM_ACCOUNTS") or [] if accounts and len(accounts) > 0: for account in accounts.split(","): clean(ctx) download(ctx, account) build(ctx)
Posted from my blog with SteemPress : https://robertyan.000webhostapp.com/2019/05/%e7%94%a8github%e5%88%9b%e5%bb%basteem%e6%96%87%e7%ab%a0%e9%95%9c%e5%83%8f-mirroring-your-steem-blogs-on-github-%e5%85%8d%e8%b4%b9%e5%8d%9a%e5%ae%a2%e5%a4%87%e4%bb%bd%e6%9c%8d%e5%8a%a1%ef%bc%9a-st
cn-hello.reply reply to a post by cn-hello cn-hello.search search the latest posts by newbies cn-hello.summarize publish summary post for daily and weekly update cn-hello.vote vote a post by cn-hello cn-hello.welcome send welcome messages to newbies steem.list-posts list the post by account, tag, keyword, etc.
├── cn_hello │ ├── __init__.py │ ├── bot.py # the behaviors of the bot │ ├── command.py # the commands that trigger the bot to act │ ├── message.py # the messages for the bot to speak │ └── newbies.py # the data operations of newbies
defget_probabilities(self): if self.langprob isNone: self._detect_block() return self._sort_probability(self.langprob)
def_detect_block(self): self.cleaning_text() ngrams = self._extract_ngrams() ifnot ngrams: raise LangDetectException(ErrorCode.CantDetectError, 'No features in text.')
self.langprob = [0.0] * len(self.langlist)
self.random.seed(self.seed) for t in xrange(self.n_trial): prob = self._init_probability() alpha = self.alpha + self.random.gauss(0.0, 1.0) * self.ALPHA_WIDTH
i = 0 whileTrue: self._update_lang_prob(prob, self.random.choice(ngrams), alpha) if i % 5 == 0: if self._normalize_prob(prob) > self.CONV_THRESHOLD or i >= self.ITERATION_LIMIT: break if self.verbose: six.print_('>', self._sort_probability(prob)) i += 1 for j in xrange(len(self.langprob)): self.langprob[j] += prob[j] / self.n_trial if self.verbose: six.print_('==>', self._sort_probability(prob))
def_extract_ngrams(self): '''Extract n-grams from target text.''' RANGE = list(xrange(1, NGram.N_GRAM + 1))
result = [] ngram = NGram() for ch in self.text: ngram.add_char(ch) if ngram.capitalword: continue for n in RANGE: # optimized w = ngram.get(n) if len(ngram.grams) < n: break w = ngram.grams[-n:] if w and w != ' 'and w in self.word_lang_prob_map: result.append(w) return result
Posted from my blog with SteemPress : https://robertyan.000webhostapp.com/2019/05/%e5%80%9f%e9%97%ae%e5%b8%88%e5%8f%8b%e4%bd%95%e5%a4%84%e6%9c%89%ef%bc%8c%e9%97%a8%e7%ab%a5%e9%81%a5%e6%8c%87%e6%96%b0%e6%89%8b%e6%9d%91-%e5%85%b3%e4%ba%8e-cn-hello-%e5%b0%8f%e5%8f%8b%e7%9a%84