Exemplo n.º 1
0
 def post(self):
     name = self.request.get('name')
     if name:
         topic = Topic()
         topic.name = name
         topic.put()
         self.get()
     else:
         self.response.out.write('no name :(')
Exemplo n.º 2
0
def find_news():
    items = []
    try:
        root = ET.fromstring(
            requests.get(config.get('main', 'rss_url')).content)
    except requests.exceptions.ConnectionError:
        return []
    for item in root.findall('.//channel/item'):
        link, title = item.find('link').text, item.find('title').text
        ext_id = link.split('.')[-1].split('/')[0]
        if not Topic.select().where(Topic.ext_id == ext_id):
            items.append({"title": title, "link": link})
            Topic.create(title=title, link=link, ext_id=ext_id)
        else:
            Topic.update(title=title, link=link).where(Topic.ext_id == ext_id)
    return items
Exemplo n.º 3
0
 def post(self, topicid):
     topic = Topic.get_by_id(int(topicid))
     text = self.request.get('text')
     if topic and text:
         Comment(text=text,topic=topic).put()
         self.get(topicid)
     else:
         self.response.out.write('no text or invalid topic id :(')
Exemplo n.º 4
0
 def get(self, topicid):
     template = jinja_environment.get_template('templates/topic.html')
     topic = Topic.get_by_id(int(topicid))
     if topic:
         comments = Comment.all().filter('topic',topic)
         self.response.out.write(template.render({"topic": topic,"comments":comments}))
     else:
         self.response.out.write("no topic")
Exemplo n.º 5
0
 def get(self):
     try:
         offset = int(self.request.get('o'))
     except:
         offset = 0
     template = jinja_environment.get_template('templates/index.html')
     topics = Topic.all().order('-created_at').fetch(5,offset)
     if len(topics) ==5:
         next_url = self.request.url.split('?')[0]+'?o='+str(offset+5)
     else:
         next_url = ''
     self.response.out.write(template.render({"topics": topics,"next_url":next_url}))