예제 #1
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()