def handle_feed(feed, source): """Handles a Superfeedr JSON feed. Creates :class:`models.BlogPost` entities and adds propagate-blogpost tasks for new items. http://documentation.superfeedr.com/schema.html#json http://documentation.superfeedr.com/subscribers.html#pubsubhubbubnotifications Args: feed: unicode string, Superfeedr JSON feed source: Blogger, Tumblr, or WordPress """ logging.info('Source: %s %s', source.label(), source.key.string_id()) logging.info('Raw feed: %s', feed) if source.status != 'enabled': logging.info('Dropping because source is %s', source.status) return elif 'webmention' not in source.features: logging.info("Dropping because source doesn't have webmention feature") return for item in json.loads(feed).get('items', []): url = item.get('permalinkUrl') or item.get('id') if not url: logging.error('Dropping feed item without permalinkUrl or id!') continue # extract links from content, discarding self links. # # i don't use get_webmention_target[s]() here because they follows redirects # and fetch link contents, and this handler should be small and fast and try # to return a response to superfeedr successfully. # # TODO: extract_links currently has a bug that makes it drop trailing # slashes. ugh. fix that. content = item.get('content') or item.get('summary', '') links = [ util.clean_url(util.unwrap_t_umblr_com(l)) for l in util.extract_links(content) if util.domain_from_link(l) not in source.domains ] logging.info('Found links: %s', links) if len(url) > _MAX_KEYPART_BYTES: logging.warning( 'Blog post URL is too long (over 500 chars)! Giving up.') bp = models.BlogPost(id=url[:_MAX_KEYPART_BYTES], source=source.key, feed_item=item, failed=links) else: bp = models.BlogPost(id=url, source=source.key, feed_item=item, unsent=links) bp.get_or_save()
def postrender(site, build_args): unpublished = site.g.get("unpublished_posts", []) num_published = 0 for post in unpublished: response = "" while not response: response = input( "Unpublished post '{0}' found. Publish this post? (y/n) ". format(post["url"])) response = { "y": "yes", "yes": "yes", "n": "no", "no": "no" }.get(response.lower(), "") if response == "yes": record = models.BlogPost(url=post["url"], date_published=datetime.datetime.now()) site.db.add(record) site.db.commit() num_published += 1 if num_published: # rerender the site so published posts will include dates site.build(**build_args)
def post(self, post): form = PostForm(formdata=self.request.POST, obj=post, data={'draft': post and post.published is None}) if form.validate(): if post is None: post = models.BlogPost(title=form.title.data, body=form.body.data, body_markup=form.body_markup.data, tags=form.tags.data) else: form.populate_obj(post) if form.data['draft']: # Draft post post.published = datetime.datetime.max post.put() else: if not post.path: # Publish post post.updated = post.published = datetime.datetime.now() else: # Edit post post.updated = datetime.datetime.now() post.publish() self.render_to_response("published.html", { 'post': post, 'draft': form.data['draft'] }) else: self.render_form(form)
def get(self, pageid): user, site = self.us() page = ndb.Key('Page', long(pageid), parent=site.key).get() if not user or not page: return spec = page.spec() bpid = models.BlogPost.allocate_ids(size=1, parent=page.key)[0] bpkey = ndb.Key('BlogPost', bpid, parent=page.key) imkey = ndb.Key('Image', '0', parent=bpkey) im = models.Image(key=imkey, width=spec['postimagesz'][0], height=spec['postimagesz'][1]) bp = models.BlogPost(key=bpkey, title='Post Title', author=user.first_name, image=imkey) im.put_async() bp.put_async() self.redirect( webapp2.uri_for('edit-v1', sitename=site.name, pagename=page.name, v1=bpid))
def db_start(): create_engine('sqlite:///tmp/test.db', convert_unicode=True) db.create_all() db.session.commit() post_1 = models.BlogPost() post_1.sub = "Temat 1" post_1.content = "lalsdlajdwkjdna" db.session.add(post_1) db.session.commit()
def migrate_one(self, article): post = models.BlogPost(path=article.key().name(), title=article.title, body=article.html, tags=set(article.tags), published=article.published, updated=article.updated, deps={}) post.put() deferred.defer(self.migrate_all_comments, article.key(), article.title)
def migrate_one(self, wp_post): post = models.BlogPost( path=wp_post['path'], title=wp_post['title'], body=wp_post['body'], body_markup='html', tags=wp_post['tags'], published=wp_post['published'], updated=wp_post['published'], deps={}, ) post.put() if wp_post['comments']: deferred.defer(self.migrate_all_comments, wp_post['comments'], post.path, wp_post['title'])
def post_new(subject, content, image_url, tag): """Helper function that creates a new Entity for a new blog post. """ blog_entry = models.BlogPost(subject=subject, content=content, image_url=image_url, tag=tag) blog_entry.put() post_id = str(blog_entry.key().id()) blog_entry.post_id = post_id blog_entry.put() #rerun query and update the cache. main_page_posts(True) tag_cache(tag, True) archive_year = blog_entry.created.strftime('%Y') archive_cache(archive_year, True) visits_cache(True) return '/{post_id}'.format(post_id=post_id)
def post(self): cookie_id = self.read_secure_cookie('id') if cookie_id: subject = self.request.get("subject") content = self.request.get("content") author_id = str(self.read_secure_cookie("id")) if subject and content and author_id: p = models.BlogPost(subject=subject, content=content, author_id=author_id) p.put() post_id = str(p.key().id()) self.redirect("/post/" + post_id) else: error = "we need both a title and some content!" self.render_form(subject, content, error) else: self.render_404()
def get(self): labels = [ "Manage DJs", "Manage Programs", "Manage Permissions", "Manage Albums", "Manage Genres", "Manage Blog", "Manage Events" ] for l in labels: if not models.getPermission(l): permission = models.Permission(title=l, dj_list=[]) permission.put() seth = models.getDjByEmail("*****@*****.**") if not seth: seth = models.Dj(fullname='Seth Glickman', lowername='seth glickman', email='*****@*****.**', username='******', password_hash=hash_password('testme')) seth.put() program = models.Program( title='Seth\'s Show', slug='seth', desc='This is the show where Seth plays his favorite music.', dj_list=[seth.key()], page_html='a <b>BOLD</b> show!') program.put() for l in labels: permission = models.getPermission(l) if seth.key() not in permission.dj_list: permission.dj_list.append(seth.key()) permission.put() if not models.getLastPosts(3): post1 = models.BlogPost( title="Blog's first post!", text="This is really just filler text on the first post.", slug="first-post", post_date=datetime.datetime.now()) post1.put() time.sleep(2) post2 = models.BlogPost(title="Blog's second post!", text="More filler text, alas.", slug="second-post", post_date=datetime.datetime.now()) post2.put() artists = [ "Bear In Heaven", "Beck", "Arcade Fire", "Andrew Bird", "The Antlers", "Arcade Fire", "The Beach Boys", "Brian Wilson", "The Beatles", "Beethoven", "Beirut", "Belle & Sebastian", "Benji Hughes", "Club 8", "Crayon Fields", ] for a in artists: if not models.ArtistName.all().filter("artist_name =", a).fetch(1): ar = models.ArtistName( artist_name=a, lowercase_name=a.lower(), search_names=models.artistSearchName(a).split()) ar.put() self.session.add_flash( "Permissions set up, ArtistNames set up, Blog posts set up, DJ Seth entered." ) self.redirect('/')
def handle_feed(feed, source): """Handles a Superfeedr JSON feed. Creates :class:`models.BlogPost` entities and adds propagate-blogpost tasks for new items. http://documentation.superfeedr.com/schema.html#json http://documentation.superfeedr.com/subscribers.html#pubsubhubbubnotifications Args: feed: unicode string, Superfeedr JSON feed source: Blogger, Tumblr, or WordPress """ logger.info(f'Source: {source.label()} {source.key_id()}') logger.info(f'Raw feed: {feed}') if not feed: return if source.status != 'enabled': logger.info(f'Dropping because source is {source.status}') return elif 'webmention' not in source.features: logger.info("Dropping because source doesn't have webmention feature") return for item in feed.get('items', []): url = item.get('permalinkUrl') or item.get('id') if not url: logger.error('Dropping feed item without permalinkUrl or id!') continue # extract links from content, discarding self links. # # i don't use get_webmention_target[s]() here because they follows redirects # and fetch link contents, and this handler should be small and fast and try # to return a response to superfeedr successfully. # # TODO: extract_links currently has a bug that makes it drop trailing # slashes. ugh. fix that. content = item.get('content') or item.get('summary', '') links = [ util.clean_url(util.unwrap_t_umblr_com(url)) for url in util.extract_links(content) if util.domain_from_link(url) not in source.domains ] unique = [] for link in util.dedupe_urls(links): if len(link) <= _MAX_STRING_LENGTH: unique.append(link) else: logger.info( f'Giving up on link over {_MAX_STRING_LENGTH} chars! {link}' ) if len(unique) >= MAX_BLOGPOST_LINKS: logger.info('Stopping at 10 links! Skipping the rest.') break logger.info(f'Found links: {unique}') if len(url) > _MAX_KEYPART_BYTES: logger.warning( 'Blog post URL is too long (over 500 chars)! Giving up.') bp = models.BlogPost(id=url[:_MAX_KEYPART_BYTES], source=source.key, feed_item=item, failed=unique) else: bp = models.BlogPost(id=url, source=source.key, feed_item=item, unsent=unique) bp.get_or_save()