Example #1
0
 def post(self, title, text=''):
     arg = ' '.join(title)
     try:
         with open(arg, 'r'):
             post = Post.from_file(arg)
     except Exception:
         try:
             post = Post.from_slugish(arg)
             assert post is not None
         except Exception:
             post = Post.from_title(arg, text)
     return post
Example #2
0
File: stag.py Project: noah/stag
 def post(self, title, text=''):
     arg = ' '.join(title)
     try:
         with open(arg, 'r'):
             post = Post.from_file(arg)
     except Exception:
         try:
             post = Post.from_slugish(arg)
             assert post is not None
         except Exception:
             post = Post.from_title(arg, text)
     return post
Example #3
0
 def create_posts(self):
     for user in self.users:
         for _ in range(random.randint(1, int(self.max_posts_per_user))):
             post = Post(title=fake.sentence(nb_words=6,
                                             variable_nb_words=True,
                                             ext_word_list=None),
                         text=fake.text(max_nb_chars=250,
                                        ext_word_list=None))
             code, data = user.login(self.url + 'api/token/')
             if code == 200:
                 post.publish(self.url + 'api/posts/', user.token)
                 self.posts.append(post)
     return self.posts
    path = dirpath + "/system/" + str(postid) + ".jpg"

    if r.status_code == 200:
        with open(path, 'wb') as f:
            r.raw.decode_content = True
            shutil.copyfileobj(r.raw, f)

    md5 = md5sum(path)

    # transform description
    description = re.sub(r"#insta(^\s)*", "", description)
    description = re.sub(r"\s@", " ", description)
    description = re.sub(r"^@", " ", description)

    # save in DB
    post = Post(description=description,
                key=postid,
                url=post_link,
                from_network="Instagram",
                use_on_twitter=False,
                use_on_pinterest=False,
                md5=md5,
                url_target=url_target,
                posted_at=post_datetime)

    session.add(post)
    session.commit()

driver.close()
Example #5
0
 def posts(self, sortby='created', reverse=True):
     s_posts = glob(path.join(config["posts_path"], "*.md"))
     return sorted([Post.from_file(path=p) for p in s_posts],
                   key=attrgetter(sortby),
                   reverse=reverse)
Example #6
0
File: stag.py Project: noah/stag
 def posts(self, sortby='created', reverse=True):
     s_posts = glob(path.join(config["posts_path"], "*.md"))
     return sorted([Post.from_file(path=p) for p in s_posts],
                   key=attrgetter(sortby), reverse=reverse)
Example #7
0
 def posts(self):
     s_posts = sorted(glob("%s/*.md" % config["posts_path"]), reverse=True)
     return [Post.from_file(path=p) for p in s_posts]