def post(self): if not self.user: return self.redirect('/blog') subject = self.request.get('subject') content = self.request.get('content') if subject and content: p = Post(parent=blog_key(), subject=subject, content=content) p.user_id = str(self.user.key().id()) p.put() postComm = Comment.all().filter('post_id =', p.key().id()) self.render("permalink.html", post=p, comments=postComm) else: error = "subject and content, please!" self.render("newpost.html", subject=subject, content=content, error=error)
def postEntry(requestentity=None,check=0): newPost = Post() #college = CollegeDb(name = 'NITK',student_sup='Anirudh',collegeId='NITK-123') #college_key = college.put() query = CollegeDb.query() club_name = Club.query() if check==0: print "The request entity key is " + requestentity.club_id key1 = ndb.Key('Club',int(requestentity.club_id)) key2 = ndb.Key('Profile',int(requestentity.from_pid)) else: key1 = requestentity.club_id key2 = requestentity.from_pid persons = Profile.query() #print club_name[0] #print "The key is " + club_name[0].key club_key = key1 profile_key = key2 flag = 0 print "Profile Key " + str(profile_key) for x in persons: print x.key if(x.key == profile_key): print "Same" flag=1 else: print "NOPE" #setattr(clubRequest, field, profile_key) if(flag==1): if requestentity: for field in ('title','description','club_id','from_pid','likes','views'): if hasattr(requestentity, field): print(field,"is there") val = getattr(requestentity, field) if(field=="club_id"): print "Club_Id stage" setattr(newPost, field, club_key) elif field == "from_pid": print "Entered here" person = profile_key.get() print "Person's email-id ", person.email person_collegeId = person.collegeId print "His college Id ", person.collegeId college_details = person_collegeId.get() print "The sup is ", college_details.student_sup setattr(newPost, field, profile_key) print "Put PID" setattr(newPost,'collegeId',person_collegeId) print "Put college id" elif val: print("Value is",val) setattr(newPost, field, str(val)) else: setattr(newPost, "likes", 0) setattr(newPost, "views", 0) print("About to create Post") print(newPost) newPost.put() else: print "Invalid Person" return
def parseFeed(feed, user): index = open(feed.url) # gets html index index = index.read() # continues soupd = soup(index) # parse the hml with BeautifulSoup rsslink = soupd.findAll("link", type="application/rss+xml") # this little mess will get the # rss link if rsslink == "[]": rsslink = soupd.findAll("link", type="application/rdf+xml") # or rdf elif rsslink == "[]": rsslink = soupd.findAll("link", type="application/atom+xml") # or atom rsslink = str(rsslink) # and put to a string # no need to understand this as none will ever comprehend RegExp # a hint, it strips the link out of the html tag link = re.search('href=".*?"', rsslink) if link == 0: link = link.group() link = re.search('HREF=".*?"', rsslink) link = link.strip("HREF=") link = str(link) link = link.strip('""') elif link == 0: print "erro, linha 94 engine.py, link para rss n encontrado!" else: link = link.group() link = str(link) link = link.strip("href=") link = link.strip('""') feed.rsslink = link # we will need to store this, for updates # now some more fun, getting the real thing, xml content # from the link we have xml = open(link) xml = xml.read() # time to parse it with FeedParser k = feedparse(xml) feed.title = k.feed.title feed.put() # now let's parse the posts one-by-one for x in range(len(k.entries)): p = str(x) post = Post(url=k.entries[x].link, owner=user) # now that the post model is set, let us play! # ugly but necessary: if k.entries[x].has_key("author") is True: post.author = k.entries[x].author + " sings " else: post.author = "Anonymous" if k.entries[x].has_key("category") is True: post.category = " on " + k.entries[x].category else: post.category = "" if k.entries[x].has_key("date_parsed") is True: date = parseDate(k.entries[x].date_parsed) post.date = date if k.entries[x].has_key("summary") is True: post.summary = k.entries[x].summary else: post.summary = "No private dancing, cowboy..." if k.entries[x].has_key("title") is True: post.title = k.entries[x].title if len(post.title) == 0: post.title = "Untitled" post.feed = feed.key() post.put() return feed
def postEntry(requestentity=None,check=0): newPost = Post() #college = CollegeDb(name = 'NITK',student_sup='Anirudh',collegeId='NITK-123') #college_key = college.put() query = CollegeDb.query() club_name = Club.query() if check==0: print "The request entity key is " + requestentity.club_id key1 = ndb.Key('Club',int(requestentity.club_id)) key2 = ndb.Key('Profile',int(requestentity.from_pid)) else: key1 = requestentity.club_id key2 = requestentity.from_pid persons = Profile.query() #print club_name[0] #print "The key is " + club_name[0].key club_key = key1 profile_key = key2 flag = 0 flag1 = 0 clubs = Club.query() print "Profile Key " + str(profile_key) for x in persons: print x.key if(x.key == profile_key): print "Same" flag=1 else: print "NOPE" for x in clubs: print x.key if(x.key == club_key): print "Same" flag1=1 else: print "NOPE" #setattr(clubRequest, field, profile_key) if(flag==1 and flag1==1): if requestentity: for field in ('title','description','club_id','from_pid','likes','views','timestamp','photo','photoUrl'): if hasattr(requestentity, field): print(field,"is there") val = getattr(requestentity, field) if(field=="club_id"): print "Club_Id stage" setattr(newPost, field, club_key) elif field == "from_pid": print "Entered here" person = profile_key.get() print "Person's email-id ", person.email person_collegeId = person.collegeId print "His college Id ", person.collegeId college_details = person_collegeId.get() print "The sup is ", college_details.student_sup setattr(newPost, field, profile_key) print "Put PID" setattr(newPost,'collegeId',person_collegeId) print "Put college id" elif field=="timestamp": setattr(newPost, field, val) elif val: print("Value is",val) setattr(newPost, field, str(val)) else: if field == "timestamp": temp = datetime.strptime(getattr(requestentity,"date"),"%Y-%m-%d").date() temp1 = datetime.strptime(getattr(requestentity,"time"),"%H:%M:%S").time() setattr(newPost,field,datetime.combine(temp,temp1)) setattr(newPost, "likes", 0) setattr(newPost, "views", 0) print("About to create Post") print(newPost) newPost.put() else: print "Invalid Entry" return newPost