Ejemplo n.º 1
0
 def receive(self, message):
     post = Post()
     html_bodies = message.bodies('text/html')
     img_links = []
     video_links = []
     for content_type, body in html_bodies:
         decoded_body = body.decode()
         img_links.extend(self.find_image_links(decoded_body))
         video_links.extend(self.find_video_links(decoded_body))
 
     if hasattr(message, "attachments") and message.attachments:
         post.attachments = []
         for attachment in message.attachments:
             post.attachments.append(db.Blob(attachment[1].decode()))
 
     plaintext_bodies = message.bodies('text/plain')
     allBodies = '';
     for body in plaintext_bodies:
         allBodies = allBodies + body[1].decode()
 
     if hasattr(message, "subject"):
         subject, encoding = decode_header(message.subject)[0]
         post.caption = unicode(subject)
     post.author = message.sender
     post.content = allBodies
     post.images = img_links
     post.videos = video_links
     post.source = "email"
     post.put()
Ejemplo n.º 2
0
    def __init__(self, src_path, exclude=() ):
        post_list = []
        
        for file_path in os.listdir(src_path):
            if not file_path.endswith('.py') or file_path in SOURCE_EXCLUDE:
                # TODO convert to regex matching
                continue
            full_path = os.path.join(src_path, file_path)
            try:
                post = Post(full_path)
                post_list.append(post)
            except Exception as e:
                import traceback
                traceback.print_exc()
                print 'Error creating Post from '+str(full_path)+':'+str(e)
                continue

        self.posts = sorted(post_list, key=lambda p: p.updated)

        self._check_monotonic()
        self._resolve_links()
        
        for post in self.posts:
            errors = post.get_errors()
            for error in errors:
                print 'Error in',post.filename,'on line',str(error.line)+': ',error.message,
                if error.text: print '('+error.text+')'
                print
Ejemplo n.º 3
0
 def update_site(self):
     """Updates only the static pages"""
     files = os.listdir(self.datadir)
     for f in files:
         if f[0] != '.':  # leave out hidden files
             post = Post(self.datadir+f)
             post.write(self.posts, self.tags)
Ejemplo n.º 4
0
def main():	

	# READ TEMPATE HTML FILES
	base_html = open("templates/base.html")
	post_html = open("templates/post.html")

	# CREATE PAGE
	page = base_html.readlines()
	posts = []

	# OPEN POST TXT FILES
	postfiles = [ f for f in listdir("posts") if isfile(join("posts",f)) ]

	for postfile in postfiles:
		temp = open("posts/" + postfile, "r")
		postlines = temp.readlines()
		post_obj = Post(postlines[0], postlines[1], postlines[2:])
		posts.append("".join(post_obj.render(post_html)))
		post_html.seek(0)
		temp.close()

	# INSERT POSTS INTO PAGE
	for i in range(len(page)):
		page[i] = page[i].replace("[[posts]]", "\n\n".join(posts))

	# WRITE PAGE TO OUTPUT HTML FILE
	final = open("output/final.html", "a+")
	final.write("".join(page))

	# CLOSE FILES
	base_html.close()
	post_html.close()
Ejemplo n.º 5
0
def print_post(args):
    if 'all' in args.postid:
        posts = Post.load()
    else:
        try:
            ids = [int(x) for x in args.postid]
        except ValueError:
            print('Post IDs should be numbers')
            return
        posts = Post.load(ids)
    if not len(posts):
        print('Post ID(s) not found: {}'.format(' '.join(args.postid)))
        return
    if args.s:
        posts = order_by_date(posts)
    for postid in posts.keys():
        if len(posts[postid]['body']) > 74:
            body = '\n      '.join(trunc(posts[postid]['body'], 74))
        else:
            body = posts[postid]['body']
        print('Title: {}\nPost ID: {}, last modification date: {}\nBody: {}'
              .format(posts[postid]['title'],
                      postid,
                      posts[postid]['date'],
                      body))
        print('-' * 80)
Ejemplo n.º 6
0
def publish(post_meta):


    doc_id = Post.url_friendly_text(post_meta["title"])
    
    # Open the database
    couch = couchdb.Server()
    db = couch["mrvoxel_blog"]
    
    # Load the database settings
    blog_settings = settings.loadSettings(db)
    
    # Check to see if we have a valid category
    if not post_meta["category"] in blog_settings["blog_categories"]:
        raise ValueError("No such category: %s" % post_meta["category"])
    
    print "checking for [%s]" % doc_id
    
    # Load the post (if it exists in our database)
    post = Post.load(db, doc_id)
    
    # If it exists, warn the user
    if post:
        raw = raw_input("This will replace an existing post of the same title...\nContinue? (y/N)")
        
        # if the existing post is published but we're trying to preview
        if (post["published"] == False) and post_meta["published"]:
            raise ValueError("Cannot yet preview posts that are already published")
        
        if raw != "y":
            print "Canceling publish."
            return None
        else:
            for k, v in post_meta.iteritems():
                if k not in ["published", "title"]:
                    print k
                    post[k] = v
            
            print post
            
            """
            post.markdown = mdtext
            post.html = html
            post.author = author
            post.timestamp = timestamp
            post.published = not preview
            post.title = title
            post.tags = tags
            post.category = category
            """
            
            post.store(db)
    else:
        
        post = Post.create(**post_meta)
        print post["_id"]
        post.store(db)
        print post["_id"]
    return post["_id"]
Ejemplo n.º 7
0
 def load_post(self):
     """ load post
     """
     for post_source in glob.glob(self.post_path + self.post_pattern):
         post = Post()
         post.load_from_file(post_source)
         # self.posts.append(post)
         self.post_mapping[post.link] = post
Ejemplo n.º 8
0
 def post(self):
     user = users.get_current_user()
     
     if user:
         post = Post(parent = Post.post_db_key(), author = user, content = self.request.get("content"))
         post.put()
     
     self.redirect('/')
Ejemplo n.º 9
0
 def new_post(self, title, content, date=datetime.datetime.utcnow()):
     post = Post(blog_id=self._id,
                 title=title,
                 content=content,
                 author=self.author,
                 # formats the date string object into datetime
                 date=date)
     post.save_to_mongo()
Ejemplo n.º 10
0
def mod_post(args):
    posts = Post.load()
    if not args.title and not args.body:
        print('Either title or body are required for post modificaion')
    else:
        p = Post(args.title or posts[args.postid]['title'],
                 args.body or posts[args.postid]['body'],
                 postid=args.postid)
        p.save()
Ejemplo n.º 11
0
    def get(self):
        post_id = self.request.get('post_id')
        user_id = self.user.key().id()

        if user_id and post_id and not LikePostRelation.check_like_status(user_id,post_id):
            Post.updateLike(post_id)
            like_post_relation = LikePostRelation.create_like_post_relation(user_id,post_id)
            like_post_relation.put()

        self.redirect('/blog/%s' % post_id)
Ejemplo n.º 12
0
    def render_latest_posts(self, limit):
        accu = ''
        for post_path in self.latest_posts(limit):
            post = Post(post_path)
            accu += post.render('short-post')

        output = open(os.path.join(
            self.__render_base_path, 'latest_posts.rst'), 'w')
        output.write(accu)
        output.close()
Ejemplo n.º 13
0
    def render_latest_posts(self, limit):
        accu = ''
        for post_path in self.latest_posts(limit):
            post = Post(post_path)
            accu += post.render("short-post")

        output = open(os.path.join(
            self.__render_base_path, "latest_posts.rst"), "w", encoding='utf-8')
        output.write(accu)
        output.close()
Ejemplo n.º 14
0
    def get_post(self, post_id):
        post = self.loaded_posts.get(post_id, None)
        if post is None:
            path = u"{0}/{1}.md".format(self.working_dir, post_id)
            if os.path.exists(path):
                post = Post(post_id, working_dir=self.working_dir)
                self.loaded_posts[post_id] = post
        else:
            post.refresh()

        return post
Ejemplo n.º 15
0
    def get(self):
        post_id = self.request.get('post_id')
        
        if not self.user or not post_id:
            self.redirect('/blog/%s' % post_id)
        post = Post.by_id(post_id)
        
        if post and post.created_by == self.user.key().id():
            Post.delete(post_id)

        self.redirect('/blog')
Ejemplo n.º 16
0
    def post(self):
        user = users.get_current_user()
        if not user or not users.is_current_user_admin():
            self.redirect(users.create_login_url(self.request.uri))
            return

        post = Post()
        post.title = self.request.POST['title']
        post.put()

        self.redirect('/admin/posts/edit/' + str(post.key.id()))
Ejemplo n.º 17
0
def post(arg):
    """defines post command"""

    postTypes = ["text", "photo", "quote", "link", "chat", "audio", "video"]
    postStates = ["published", "draft", "queue", "private"]

    args = arg.split(" ")

    if args[0] in postTypes:
        if args[0] == "text":
            if '"' in args[1]:
                quote_text = re.findall('"([^"]*)"', arg)
                text = ""

                if len(quote_text) > 1:
                    text = quote_text[0]

                text_post = {"title": "", "state": "", "blog": "", "tags": []}

                if "--title" in args:
                    if len(quote_text) == 1:
                        text_post['title'] = quote_text[0]
                    else:
                        text_post['title'] = quote_text[1]

                if "-s" in args:
                    state = args[args.index('-s') + 1]
                    if state in postStates:
                        text_post['state'] = state
                    else:
                        print "Invalid state value found: " + state
                        print "Posting now"

                if "-b" in args:
                    text_post['blog'] = args[args.index('-b') + 1]
                else:
                    text_post['blog'] = USERNAME

                if "-t" in args:
                    for s in args[args.index("-t") + 1:]:
                        if s not in ["--title", "-b", "-s"]:
                            text_post['tags'].append(s)
                        else:
                            break

                print text_post
                newPost = Post(client, text_post['blog'], "text", text_post['tags'])
                newPost.publish(text_post['state'], title=text_post['title'], body=text)

            else:
                print "No text content found! Text must be in quotes."
    else:
        print "Invalid post type: " + args[0]
Ejemplo n.º 18
0
 def get(self, post_id=None, action=None):
     if action is None:
         posts = Post.all()
         self.response.out.write(helper.render('admin/posts', { 'posts': posts }))
     elif action == "delete":
         Post.get_by_id(int(post_id)).delete()
         return self.redirect('/admin/posts')
     elif action == "confirm":
         post = Post.get_by_id(int(post_id))
         post.confirmed_at = datetime.datetime.today()
         post.put()
         return self.redirect('/admin/posts')
Ejemplo n.º 19
0
    def run(self):
        while 1 == 1:
            try:
                for url in self.urls:
                    self.urls.remove(url)
                    print(url)

                    opener = urllib2.build_opener()
                    opener.addheaders = [('User-agent', 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)')]
                    response = opener.open(url)

                    html = response.read()
                    soup = BeautifulSoup(html, 'html.parser')
                    text = soup.text
                    links = soup.find_all('a')
                    images = soup.find_all('img')

                    post = Post(self.connection, url, url, 'url')
                    post.save()

                    download_path = 'sites/' + url
                    if not os.path.exists(download_path):
                        os.makedirs(download_path)

                    for image in images:
                        print('image')
                        src = urljoin(url, image.get('src'))
                        if src.startswith("http") or src.startswith("https"):
                                fname = self.basename(src)
                                if fname != None:
                                    self.download_file(src, download_path + fname)

                    print('ok')

                    '''self.reset_config()
                    for p in self.config:
                        textElements = re.findall(p['regex'], text)

                        if textElements != None:
                            for element in textElements:
                                post = Post(self.connection, element, element, p['type'])
                                post.save()'''
                    
                    for link in links:
                        href = urljoin(url, link.get('href'))
                        if href.startswith("http") or href.startswith("https"):
                            fname = self.basename(href)
                            if fname in self.extensions:
                                self.download_file(href, download_path + fname)
                            self.urls.append(href)
            except:
                pass
Ejemplo n.º 20
0
def create_post_with_bugs(data, cur, bugs=None):
    post = Post(data)
    if bugs != None:
        post.populatebugs(bugs)
    else:
        cur.execute('''SELECT titles.title, bug.bugid, bug.status
                       FROM bugtitles AS titles, postbugs AS bug
                       WHERE bug.userid = ?
                         AND bug.postdate = ?
                         AND bug.bugid = titles.bugid''',
                    (post.userid, post.postdate.toordinal()))
        post.populatebugs([Bug(title, id, statusnum) for title, id, statusnum in cur.fetchall()])
    return post
Ejemplo n.º 21
0
    def post(self,post_id):

        if not self.user:
            self.redirect('/blog/%s' % post_id)

        subject = self.request.get('subject')
        content = self.request.get('content')
        user_id = self.user.key().id()
        last_modified = datetime.datetime.now()
        post = Post.by_id(post_id)
        if post and post.created_by == user_id:
           Post.update(post_id,subject,content,last_modified)
        self.redirect('/blog/%s' % post_id)
Ejemplo n.º 22
0
def main():
    try:
        opts, args = getopt.getopt(
            sys.argv[1:], "ht:d:s:p:", ["title", "help", "publish="])
    except getopt.GetoptError:
        usage()
        sys.exit(2)
    for opt, arg in opts:
        if opt in ('-h', '--help'):
            usage()
            sys.exit()
        elif opt in ('-p', '--publish'):
            p = Post(arg)
            p.write()
            print('Post/page published, you might want to update now.')

        elif opt in ('-t', '--title'):
            # one-time modification of the template
            f = codecs.open(templatedir+'base.html', 'r', encoding)
            soup = BeautifulSoup(f.read(), 'html.parser')
            f.close()

            tag = soup.find('title')
            tag.contents[0].replaceWith(arg + '${self.title()}')

            tag = soup.find('a', 'title')
            tag.contents[0].replaceWith(arg)

            f = codecs.open(templatedir+'base.html', 'w', encoding)
            f.write(str(soup).decode(encoding))
            f.close()

            print('Title was set to:' + arg)
            sys.exit()
        else:
            assert False, "unhandled option"

    blog = Blog()

    for a in args:
        if a == 'index':
            blog.index()
        elif a == 'archive':
            blog.archive()
    if args == []:
        if site_type == 'blog':
            print("--> Updating your blog")
            blog.update_blog()
        else:
            print("--> Updating your site")
            blog.update_site()
Ejemplo n.º 23
0
def list_posts():
    request_data = get_json(request)

    if 'thread' in request_data:
        code, response = Post.list_by_thread(request_data['thread'], request_data)
    elif 'forum' in request_data:
        code, response = Post.list_by_forum(request_data['forum'], request_data)
    else:
        code, response = Codes.UNKNOWN_ERROR, 'Please enter thread or forum'

    return json.dumps(
        {'code': code,
         'response': response}
    )
Ejemplo n.º 24
0
	def post(self):
		if not self.user:
			self.redirect('/blog')

		subject = self.request.get('subject')
		content = self.request.get('content')
		created_by = self.user.name

		if subject and content:
			p = Post(parent = blog_key(), subject = subject, content = content, created_by = created_by)
			p.put()
			self.redirect('/blog/%s' % str(p.key().id()))
		else:
			error = "subject and content, please!"
			self.render("newpost.html", subject=subject, content=content, error=error)
Ejemplo n.º 25
0
    def post(self, post_subject):
        # If any user does not logged in redirect to homepage
        if not self.user:
            self.redirect("/login")

        post_to_delete = Post.find_by_subject(post_subject)
        # If post couldn't find redirect 404 page
        if not post_to_delete:
            self.error(404)
            return self.render('404.html')
        if not self.user.owner_of(post_to_delete):
            self.redirect("/")
        else:
            # delete post likes
            for like in post_to_delete.postlike_set:
                like.delete()
            # delete comment and comment likes
            for comment in post_to_delete.comment_set:
                for like in comment.commentlike_set:
                    like.delete()
                comment.delete()
            # finally delete the post's itself
            post_to_delete.delete()

            self.redirect('/')
Ejemplo n.º 26
0
 def get(self):
     posts = Post.all().order('-created')
 	
     if self.user:
        self.render('front.html', posts = posts,username = self.user.name)
     else:
         self.render('front.html', posts = posts)
Ejemplo n.º 27
0
    def post(self, post_subject):
        # If any user does not logged in redirect to homepage
        if not self.user:
            self.redirect('/')

        # Post page contains a form to post comments,
        # so a post request comes, lets put that comment into database
        post_to_comment = Post.find_by_subject(post_subject)
        # If post couldn't find redirect 404 page
        if not post_to_comment:
            self.error(404)
            return self.render('404.html')

        content = self.request.get('content').strip()

        if content:
            comment = Comment(
                content=content,
                post=post_to_comment,
                user=self.user)
            comment.put()
            self.redirect(post_to_comment.link_to('show'))
        else:
            errors = {'content': "can't be blank"}
            self.render(
                "/posts/post.html", post=post_to_comment,
                errors=errors)
Ejemplo n.º 28
0
 def get(self):
     db_sessions = db.Query(Session).filter('active =',True).order('ordering').fetch(100)
     sessions = []
     for s in db_sessions:
         cur = {
             'name'          : s.name,
             'day_of_week'   : s.day_of_week,
             'start_time'    : s.start_time,
             'end_time'      : s.end_time,
             'location'      : s.location,
             'quoted_loc'    : quote(s.location),
             'description'   : s.description,
             'member_price'  : s.member_price,
             'casual_price'  : s.casual_price,
             'courts'        : s.courts,
             'leader'        : s.leader,
             'coords'        : s.coordinates,
         }
         if s.leader:
             leader_name = s.leader.strip().split(' ')
             cur['email'] = get_email(*leader_name[0:2])
         else:
             cur['email'] = 'holy moly'
         sessions.append(cur)
             
     data = {
         'pages'         : Post.get_pages(),
         'session'       : util_sess.Session(),
         'sessions'      : sessions,
     }
     return self.response.out.write(template.render('session/sessions.html',data))
Ejemplo n.º 29
0
    def post(self, post_subject):
        # If any user does not logged in redirect to homepage
        if not self.user:
            self.redirect('/')
        post_to_update = Post.find_by_subject(post_subject)
        # If post couldn't find redirect 404 page
        if not post_to_update:
            self.error(404)
            return self.render('404.html')
        # If user is not owner of the post, redirect with an error
        if not self.user.owner_of(post_to_update):
            self.redirect("/")
        else:
            values = {
                'subject': self.request.get('subject'),
                'content': self.request.get('content')}

            if values['subject'] and values['content']:
                values = {
                    'subject': self.request.get('subject').strip(),
                    'content': self.request.get('content').strip()}

                post_to_update.subject = values['subject']
                post_to_update.content = values['content']
                post_to_update.put()
                self.redirect(post_to_update.link_to('show'))
            else:
                errors = {}
                if not values['subject']:
                    errors['subject'] = "can't be blank"
                if not values['content']:
                    errors['content'] = "can't be blank"
                self.render("/posts/edit.html", values=values, errors=errors)
Ejemplo n.º 30
0
 def get(self):
     db_posts = db.GqlQuery(
         """
         SELECT * FROM Post
         WHERE type IN ('announcement', 'news')
         AND active = TRUE
         ORDER BY date
         DESC LIMIT 5
         """
     )
     posts = []
     au_tz = pytz.timezone("Australia/Sydney")
     utc_tz = pytz.utc
     for db_post in db_posts:
         post = SimplePost(
             db_post.key,
             db_post.title,
             db_post.author,
             utc_tz.localize(db_post.date).astimezone(au_tz),
             db_post.content,
         )
         posts.append(post)
     data = {
         "upcoming": next_session_widget(8),
         "picofday": pic_of_day_widget(),
         "posts": posts,
         "session": sessions.Session(),
         "pages": Post.get_pages(),
     }
     return self.response.out.write(template.render("index.html", data))
Ejemplo n.º 31
0
 def create_post(self, title, content):
     self.posts.append(Post(title, content))
Ejemplo n.º 32
0
@app.route("/post/<int:blog_id>")
def get_post(blog_id):
    id_exists = False
    current_post = None
    for post in all_posts:
        if post.id == blog_id:
            current_post = post
            id_exists = True
            # no need to check the rest
            break
    # just show the main page for non-existing blog_id's, rather than a semi-broken post.html
    if id_exists:
        return render_template("post.html", post=current_post, year=get_current_year())
    else:
        return render_template("index.html", posts=all_posts, year=get_current_year())


# get the test blog posts
response = requests.get(JSON_URL)
response.raise_for_status()
blog_posts = response.json()
# store posts as objects in a list
all_posts = []
for blog_post in blog_posts:
    all_posts.append(Post(blog_post["id"], blog_post["author"], blog_post["date"], blog_post["title"],
                          blog_post["subtitle"], blog_post["image_url"], blog_post["body"]))

if __name__ == "__main__":
    app.run(debug=True)
Ejemplo n.º 33
0
 def test_json(self):
     p = Post('test', 'test content')
     expected = {'title': 'test', 'content': 'test content'}
     self.assertDictEqual(p.json(), expected)
Ejemplo n.º 34
0
from flask import Flask, render_template
import requests
from post import Post

app = Flask(__name__)

all_posts = requests.get(
    url=" https://api.npoint.io/5abcca6f4e39b4955965").json()
post_list = []
for post in all_posts:
    post_features = Post(post['id'], post['title'], post['subtitle'],
                         post['body'])
    post_list.append(post_features)


@app.route('/')
def home():
    return render_template("index.html", blogs=post_list)


@app.route("/post/<int:index>")
def show_post(index):
    requested_post = None
    for blog_post in post_list:
        if blog_post.id == index:
            requested_post = blog_post
    return render_template("post.html", post=requested_post)


if __name__ == "__main__":
    app.run(debug=True)
Ejemplo n.º 35
0
def view_post():
    return render_template("view.html", posts=Post.all())
Ejemplo n.º 36
0
def posts():
    posts = Post.objects()
    return render_template('posts.html', posts=posts)
Ejemplo n.º 37
0
def delete(post_id):
    post = Post.objects().with_id(post_id)
    post.delete()
    return redirect(url_for('posts'))
Ejemplo n.º 38
0
def post(post_id):
    post = Post.objects().with_id(post_id)
    return render_template('post.html', post=post)
Ejemplo n.º 39
0
from flask import Flask, render_template
from post import Post

app = Flask(__name__)
data = Post()
num_len = len(data.title)


@app.route("/")
def home():
    return render_template(
        "index.html",
        title=data.title,
        subtitle=data.subtitle,
        body=data.body,
        num_len=num_len,
    )


@app.route("/post/<num>")
def get_blog(num):
    i = int(num)
    return render_template("post.html",
                           title=data.title[i],
                           subtitle=data.subtitle[i],
                           body=data.body[i])


if __name__ == "__main__":
    app.run(debug=True)
Ejemplo n.º 40
0
    def test_create_post(self):
        p = Post("Titulek", "Obsah")

        self.assertEqual("Titulek", p.title)
        self.assertEqual("Obsah", p.content)
Ejemplo n.º 41
0
 def get(self):
     posts = Post.query().order(-Post.created)
     count = posts.count()
     self.render("front.html", count=count, posts=posts)
Ejemplo n.º 42
0
    def test_json(self):
        p = Post('Test', 'Test Content')

        expected = {'title': 'Test', 'content': 'Test Content'}
        self.assertDictEqual(expected, p.json())
Ejemplo n.º 43
0
def post_entries():
    return render_template("post_entries.html", posts=Post.all(request.args.get('available_from'), request.args.get('available_to')))
Ejemplo n.º 44
0
from flask import Flask
from flask import render_template, request, redirect, url_for
from post import Post

app = Flask(__name__)

db = {1: Post(1, 'Post 1', 'Gosho', 'Content 1')}

@app.route('/')
def hello_world():
    return 'Hello, World!!!'

@app.route('/posts')
def list_posts():
    return render_template('posts.html', posts=db.values())

@app.route('/posts/<int:id>')
def show_post(id):
    post = db[id]
    return render_template('post.html', post=post)

@app.route('/posts/new', methods=['GET', 'POST'])
def new_post():
    if request.method == 'GET':
        return render_template('new_post.html')
    elif request.method == 'POST':
        next_id = max(db.keys()) + 1
        post = Post(next_id, request.form['name'], request.form['author'], request.form['content'])
        db[next_id] = post
        return redirect(url_for('list_posts'))
 def setUp(self):
     self.p = Post('Title Post','Content Post')
Ejemplo n.º 46
0
    def test_create_post(self):
        p = Post('Test', 'Test Content')

        self.assertEqual('Test', p.title)
        self.assertEqual('Test Content', p.content)
Ejemplo n.º 47
0
	def get(self):
		self.response.headers['Content-Type'] = 'text/html'
		
		url = ''
		url_string = ''
		
		
		user = users.get_current_user()
		myuser = None
		timeline_posts = []
		following_users = []
		
		if user:
			url = users.create_logout_url(self.request.uri)
			url_string = 'Log Out'
			myuser =''
			myuser_key = ndb.Key('User',  user.user_id())
			myuser = myuser_key.get()
			
			if  myuser == None:
				
				myuser = User(id = user.user_id(), email_address = user.email())
				myuser.username = user.email()
				myuser.put()

			else:
				for i in myuser.following:
					following_users.append(i)
				following_users.append(myuser.key)
				timeline_posts = Post.query(Post.owner_user.IN(following_users)).order(-Post.date).fetch()
		



		

			

			

		else:

			url = users.create_login_url(self.request.uri)
			url_string = 'Log In'



        #passing to html page
		template_values = {
		    'url'  : url,
		    'url_string' : url_string,
		    'user': user,
		    'myuser' : myuser,
		    'upload_url':  blobstore.create_upload_url('/upload'),
		    'timeline_posts': timeline_posts
		   
		    
		}

		template = JINJA_ENVIRONMENT.get_template('main.html')
		self.response.write(template.render(template_values))
Ejemplo n.º 48
0
    def test_json(self):
        p = Post("Titulek", "Obsah")
        expected = {"title": "Titulek", "content": "Obsah"}

        self.assertDictEqual(expected, p.json())
Ejemplo n.º 49
0
 def create_new_post(self, title, content):
     new_post = Post(title, content)
     self.posts.append(new_post)
Ejemplo n.º 50
0
from flask import Flask, render_template
from post import Post
from datetime import date

# PROPS
app = Flask(__name__)
posts = Post().get_posts()
current_year = date.today().year


# METHODS
@app.route("/")
def get_home():
    return render_template("index.html", all_posts=posts, year=current_year)


@app.route("/post/<int:index>")
def get_post(index):
    return render_template("post.html", post=posts[index - 1], year=current_year)


# MAIN
if __name__ == "__main__":
    app.run(debug=True)
Ejemplo n.º 51
0
    def new_post(self,title,content,date=datetime.datetime.utcnow()):


        post = Post(blog_id=self._id,title=title,content=content,author=self.author,date=date)

        post.save_to_mongo()
Ejemplo n.º 52
0
def test_is_thread_false():
    a = Post(1, "foo", 2, "comment")
    b = a.is_thread()
    assert (b == False)
Ejemplo n.º 53
0
*    Day: 57- Jinja Donamic Html Pages - Project Blog                   *
*    Date: 2021-01-20                                                   *
*************************************************************************
"""

from flask import Flask, render_template
from datetime import date
import requests
from post import Post

actual_year = date.today().year
url = 'https://api.npoint.io/5abcca6f4e39b4955965'
posts = requests.get(url).json()
post_objects = []
for post in posts:
    post_obj = Post(post['id'], post['title'], post['subtitle'], post['body'])
    post_objects.append(post_obj)

app = Flask(__name__)


@app.route('/')
def home():
    return render_template("index.html",
                           year=actual_year,
                           all_posts=post_objects)


@app.route('/post/<int:index>')
def show_post(index):
    requested_post = None
Ejemplo n.º 54
0
 def get(self):
     deleted_post_id = self.request.get('deleted_post_id')
     posts = greetings = Post.all().order('-created')
     self.render('front.html', posts=posts, deleted_post_id=deleted_post_id)
Ejemplo n.º 55
0
    def dados_posts_banco(self):
        """
        Armazena o conteúdo da chave "items" de um json recebido via requisição GET em um banco MongoDB
        colecao (MongoDB Collection)
        url (REST API url)
        paginas (int)
        """
        for x in range(1, self.paginas):

            print("iniciando requisição na linha ", x)
            # requere usando o URL e o número de páginas, guarda o conteúdo da requisição em json_data
            json_data = requisicao(url, pagina=x)
            # se a requisição não vier vazia
            if json_data is not None:
                # checa se o campo "items" tem elementos a serem colhidos
                tamanho_resposta = len(json_data["items"])
                if tamanho_resposta > 0:
                    # se for maior que zero, continua e insere no banco
                    # começa o processo de filtragem
                    items = json_data["items"]
                    
                    for item in items:
                        try:
                            json_post = {}
                            post_id = item["id"]
                            post_titulo = item["content"]["title"]
                            #post_titulo.replace("'","''")
                            
                            
                            post_data_publicacao = item["publication"]
                            post_resumo = item["content"]["summary"]
                            post_url = item["content"]["url"]
                            if post_id is None and post_titulo is not None:
                                print("ID do post inválido")
                                pass
                            elif post_titulo is None:
                                print("Título do post inválido")
                                continue
                            elif post_data_publicacao is None:
                                print("Data da publicação inválida")
                                continue
                            elif post_resumo is None:
                                print("Resumo do post inválido")
                                continue
                            elif post_url is None:
                                print("URL do post inválido")
                                continue
                            json_id = {"_id": post_id}
                            json_titulo = {"titulo": post_titulo}
                            json_data_publicacao = {"data_publicacao": post_data_publicacao}
                            json_resumo = {"resumo": post_resumo}
                            json_post_url = {"post_url": post_url}
                            json_post.update(json_id)
                            json_post.update(json_titulo)
                            json_post.update(json_data_publicacao)
                            json_post.update(json_resumo)
                            json_post.update(json_post_url)
                            # cria um objeto post com o conteúdo coletado em json
                            post = Post(json_post)
                            
                            if self.sgbd == 'sqlite':
                                # inicializa a variavel caso ela não seja ocupada por causa de exceção
                                id_inserido = None
                                try:
                                    id_inserido = banco_sqlite.inserir(post)
                                except TypeError:
                                    print("inserção falhou com id do post: ", post_id)
                                if id_inserido == None:
                                    print("inserção falhou com id do post: ", post_id)
                                # se retornou um id não vazio, inserção ocorreu sem problemas
                                else:
                                    print("Post inserido com id: ", id_inserido)
                            """
                            Comentar o trecho que trata do mongo, pois não vamos usar por enquanto
                            elif self.sgbd == 'mongodb':
                                pass
                            else:
                                print("SGBD inválido, não consigo salvar os dados")
                                break
                            
                            if id_inserido is not None:
                                print("Post inserido com id: ", id_inserido)
                            else:
                                print("inserção falhou com id do post: ", post_id)
                            """
                            del post
                        except KeyError as e:
                            print("Chave não encontrada", e)
                            

                else:
                    # página não tem elemento "items", exibe erro e interrompe o programa
                    print("Resposta do servidor sem conteúdo na página ", x)
                    break
            else:
                # requisição não recebeu nenhum dado, interrompe o programa
                print("requisição vazia recebida na linha ", x)
                break
Ejemplo n.º 56
0
from urllib.parse import unquote


def youdao(file_path):
    with open(file_path, 'r', encoding='utf-8') as f:
        txt = f.read()
    pic_iter = re.finditer(r'\!\[.*?\]\((.*?)\)', txt)
    for tag in pic_iter:
        pic_path = unquote(
            tag.group(1))  #图片名称含有汉字时,有道云笔记采用url编码的方式来记录,所以解码找到对应的图片位置
        if re.search(r'^file:///(.+?)', pic_path):
            pic_path = re.search(r'^file:///(.+)', pic_path).group(1)
        print(pic_path)
        pic_name = str(time.time()).replace('.', '') + '.png'
        pic_url = post.upload_pic(pic_path, pic_name)
        txt = txt.replace(tag.group(1), pic_url)
    return txt


if __name__ == '__main__':
    post = Post()
    post.login()
    category_name = 'WEB'
    category_slug = 'web'
    title = 'windows下使用phpstudy配置sqlilabs'
    category_mid = post.category(category_name, category_slug)
    file_path = r'D:\桌面\44.md'
    text = youdao(file_path)
    if category_mid:
        post.send_text(title, text, category_mid)
        print('发送成功')
Ejemplo n.º 57
0
 def get_posts(self):
     return Post.from_blog(self._id)
Ejemplo n.º 58
0
from flask import Flask
from flask import render_template
import datetime
from person import Person
import requests
from post import Post

app = Flask(__name__)
all_posts = all_posts = requests.get(
    "https://api.npoint.io/5abcca6f4e39b4955965").json()
post_objects = []

for post in all_posts:
    post_obj = Post(post["id"], post["title"], post["subtitle"], post["body"])
    post_objects.append(post_obj)


@app.route('/')
def home_page():
    year = datetime.datetime.today().year
    return render_template("index.html", current_year=year)


@app.route('/guess/<name>')
def guesser(name):
    person = Person(name=name)
    return render_template(
        "guess.html",
        name=person.name,
        gender=person.gender,
        age=person.age,
Ejemplo n.º 59
0
def update_one_post(post_id, new_title):
    post = Post.objects().with_id(post_id)
    # post[key] = new
    # update
    # slug
    post.update(set__title=new_title)
Ejemplo n.º 60
0
import time
from selenium import webdriver
from selenium.common import exceptions
from bs4 import BeautifulSoup
import pandas as pd
from page import Page
from post import Post
from scrap import Scrap

session = webdriver.Firefox(executable_path=r'C:\geckodriver.exe')

main_page = Page()
post = Post()
scrap = Scrap()

main_page.load_page(session)
main_page.show_all_posts(session)

bs = BeautifulSoup(session.page_source, 'html.parser')

list_posts = post.get_all_posts(session)

post.title, post.date, post.excerpt, post.url = [], [], [], []

for p in list_posts:
    post.title.append(scrap.get_titles(p))
    post.date.append(scrap.get_dates(p))
    post.excerpt.append(scrap.get_excerpts(p))
    post.url.append(scrap.get_url_image(bs))

df = pd.DataFrame({