def new_post(self, title, content, date=datetime.datetime.utcnow()): post = Post(blog_id=self._id, title=title, content=content, author=self.author, created_date=date) post.save_to_mongo()
def create_new_post(blog_id): if request.method == 'GET': return render_template('new_post.html', blog_id=blog_id) else: title = request.form['title'] content = request.form['content'] user = Member.get_by_email(session['email']) new_post = Post(blog_id, title, content, user.email) new_post.save_to_mongo() return make_response(blog_posts(blog_id))
def add_post(self, login, comment, image_url, link, date): test_post = Post(str(login), str(comment), str(image_url), str(link), str(date)) print("Add new post") print(repr(test_post)) self.session.add(test_post) self.session.commit()
def test_create_post(self): 'post() create in workplace facebook' data = { 'token': 'token', 'group': 'group', 'user': '******', 'message': 'message', } response = Post().create(**data) not self.assertEqual(response, None)
def test_print_post(): """Tests the print post function.""" post = Post("Test Post", "Test Content") expected_print = """ --- Test Post --- Test Content """ with patch("builtins.print") as mocked_print: src.app.print_post(post) mocked_print.assert_called_with(expected_print)
def get_latest_n_posts_for_profile(profile: str, n: int = 5) -> List[Post]: insta_link = f'https://www.instagram.com/{profile}' posts = [] soup = BeautifulSoup(requests.get(insta_link).content, features='html.parser') script = soup.find('script', text=lambda text: text.startswith('window._sharedData')) json_string = script.text.split(' = ')[1].rstrip(';') json_data = json.loads(json_string) profile_object = json_data['entry_data']['ProfilePage'][0] for idx, post in enumerate(profile_object['graphql']['user'] ['edge_owner_to_timeline_media']['edges']): if idx > n: break post_link = post['node']['display_url'] post_caption = post['node']['edge_media_to_caption']['edges'][0][ 'node']['text'] post_timestamp = post['node']['taken_at_timestamp'] posts.append(Post(post_link, post_caption, post_timestamp)) return posts
def test_create_post(): """Test the creation of a post.""" post = Post("Test", "Test Content") assert post.title == "Test" assert post.content == "Test Content"
def test_json(): """Test the json representation of a post.""" post = Post("Test", "Test Content") expected = {"title": "Test", "content": "Test Content"} assert expected == post.json()
def get_posts(self): return Post.from_blog(self._id)
def create_post(self, title, content): """ Creates a post in the blog. """ self.posts.append(Post(title, content))
def push_results(self, results): if 'items' not in results: raise NoResultsError("No results found for {}".format( self.get_query())) for item in results['items']: self.results.append(Post(item))