Ejemplo n.º 1
0
    def _write_content(self, post):
        folder = self._get_content_folder()
        c = SteemComment(comment=post)

        # retrieve necessary data from steem
        title = self._yaml_compatible(post.title, "''")
        permlink = post["permlink"]
        body = c.get_compatible_markdown()
        position = self._get_position(body)
        date_str = post.json()["created"]
        date = date_str.replace('T', ' ')
        tags = "\n".join(["- {}".format(tag) for tag in c.get_tags()])
        category = 'cross-posting'
        if len(c.get_tags()) > 0:
            category = c.get_tags()[0]
        thumbnail = self._yaml_compatible(c.get_pic_url(), "")
        url = c.get_url()

        # build content with template
        template = get_message("blog", footer=True)
        content = template.format(title=title, permlink=permlink,
                                position=position, date=date,
                                tags=tags, category=category,
                                thumbnail=thumbnail, body=body, url=url)

        # write into MD files
        filename = os.path.join(folder, "{}_{}.md".format(date_str.split('T')[0], permlink))
        with open(filename, "w", encoding="utf-8") as f:
            f.write(content)

        logger.info("Download post [{}] into file {}".format(title, filename))
Ejemplo n.º 2
0
    def read_posts(self, start=0):
        c_list = {}
        posts = []

        if self.limit:
            blogs = self.account.get_blog(start_entry_id=start, limit=self.limit)
        else:
            blogs = self.account.blog_history(start=start, limit=self.limit, reblogs=False)

        days_done = False
        for c in blogs:
            if c.permlink in c_list:
                continue
            if not c.is_comment() and c.author == self.username:
                sc = SteemComment(comment=c)
                tags = sc.get_tags()
                if self.tag is None or self.tag in tags:
                    if self.keyword is None or self.keyword in c.title:
                        days_done = self.days is not None and not in_recent_n_days(c, self.days)
                        if days_done:
                            break
                        else:
                            c = sc.refresh()
                            sc.log()
                            c_list[c.permlink] = 1
                            posts.append(c)

        print ('{} posts are fetched'.format(len(posts)))
        return posts
Ejemplo n.º 3
0
    def read_posts(self, start=0):
        if not self.exists:
            return []

        c_list = {}
        posts = []

        if self.reblog:
            blogs = self.account.history_reverse(only_ops=["custom_json"])
        elif self.limit:
            blogs = self.account.get_blog(start_entry_id=start,
                                          limit=self.limit)
        else:
            blogs = self.account.blog_history(start=start,
                                              limit=self.limit,
                                              reblogs=self.reblog)

        days_done = False
        for c in blogs:
            if self.reblog:
                if c['id'] == "follow":
                    json_data = json.loads(c['json'])
                    if len(json_data) > 0 and json_data[0] == "reblog":
                        info = json_data[1]
                        authorperm = "@{}/{}".format(info["author"],
                                                     info["permlink"])
                        timestamp = c["timestamp"]
                        c = Comment(authorperm)
                        c["reblogged"] = timestamp
                    else:
                        continue
                else:
                    continue
            if c.authorperm in c_list:
                continue
            if not c.is_comment():
                if ((not self.reblog) and c.author == self.username) or (
                        self.reblog and c.author != self.username):
                    sc = SteemComment(comment=c)
                    tags = sc.get_tags()
                    if self.tag is None or self.tag in tags:
                        if self.keyword is None or self.keyword in c.title:
                            days_done = self.days is not None and not in_recent_n_days(
                                c, self.days, self.reblog)
                            if days_done:
                                break
                            else:
                                c = sc.refresh()
                                sc.log()
                                c_list[c.authorperm] = 1
                                posts.append(c)

        print('{} posts are fetched'.format(len(posts)))
        return posts