예제 #1
0
파일: blog.py 프로젝트: OzaKomal/SWAP2shop
 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()
예제 #2
0
파일: app.py 프로젝트: OzaKomal/SWAP2shop
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))
예제 #3
0
 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()
예제 #4
0
 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)
예제 #5
0
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)
예제 #6
0
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
예제 #7
0
def test_create_post():
    """Test the creation of a post."""
    post = Post("Test", "Test Content")

    assert post.title == "Test"
    assert post.content == "Test Content"
예제 #8
0
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()
예제 #9
0
파일: blog.py 프로젝트: OzaKomal/SWAP2shop
 def get_posts(self):
     return Post.from_blog(self._id)
예제 #10
0
 def create_post(self, title, content):
     """ Creates a post in the blog. """
     self.posts.append(Post(title, content))
예제 #11
0
파일: searcher.py 프로젝트: jonpemby/jobbr
 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))