示例#1
0
    def __parse_single_attraction(li):
        """
        下記の形式のHTMLをParseする。

        <li>
          <a href='****' title='****'>
            <ul>
              <li class='photo'><img data-src='****' width='64' height='64' class='lozad' alt='***'></li>
              <li class='desc'>
                <h4>グリーティング名称</h4>
                <p><span class='runtime'>10:40 - 18:00</span> ただいま列に並んで利用できます</p>
              </li>
              <li class='time'>
                <p><span>待ち時間</span>20<span class='m'>分</span></p>
              </li>
            </ul>
          </a>
        </li>
        """

        greeting = Greeting()
        if elem_desc := li.find(class_='desc'):
            # グリーティング名称
            greeting.name = elem_desc.find('h4').text
            # スタンバイパスの状況
            if elem_fp := elem_desc.find(class_="fp"):
                greeting.standby_pass_status = elem_fp.text
示例#2
0
def post_greeting(request, db, src_user_id):
    provider = request.form.get('provider')
    uid = request.form.get('uid')

    if not provider or not uid:
        raise InvalidParam('provider or uid is not invalid')

    account = db.session.query(Account)\
              .filter(Account.uid==uid)\
              .filter(Account.provider==provider).first()

    # if the user you are greeting to is not registered in our app then we create
    # a mock user account for him
    if not account:
        user = User()
        user.accounts = [Account(provider=provider, uid=uid)]
        db.session.add(user)
        db.session.commit()
        account = user.accounts[0]

    greeting = db.session.query(Greeting)\
               .filter(Greeting.src_user_id==src_user_id)\
               .filter(Greeting.dst_user_id==account.user_id).first()

    if not greeting:
        greeting = Greeting(src_user_id=src_user_id, dst_user_id=account.user_id)
        db.session.add(greeting)
        db.session.commit()

    back_greeting = db.session.query(Greeting)\
                    .filter(Greeting.src_user_id==account.user_id)\
                    .filter(Greeting.dst_user_id==src_user_id).first()

    if back_greeting:
        back_greeting.is_friend = True
        back_greeting.is_friend_at = sqlnow()
        greeting.is_friend = True
        greeting.is_friend_at = sqlnow()
        db.session.add(greeting)
        db.session.add(back_greeting)
        db.session.commit()

        return jsonify({
            'status': 'success',
            'data': {
                'is_friend': True,
                'user_id': account.user_id
            }
        })
    else:
        return jsonify({
            'status': 'success',
            'data': {
                'is_friend': False,
                'user_id': account.user_id
            }
        })
示例#3
0
    def post(self):
        user = users.get_current_user()
        guestbook_name = self.request.get('guestbook_name')
        greeting = Greeting(parent = guestbook_key(guestbook_name))

        if user:
            self.response.out.write('<html><body>You wrote:<pre>')
            self.response.out.write(cgi.escape(self.request.get('content')))
            self.response.out.write('</pre></body></html>')

            greeting.author = user
            greeting.content = self.request.get('content')
            greeting.put()
            self.redirect('/?' + urllib.urlencode({'guestbook_name':guestbook_name}))
        else:
            self.redirect(users.create_login_url(self.request.uri))
示例#4
0
    def get(self):
        guestbook_name = self.request.get('guestbook_name')
        greetings_string = Greeting.all().ancestor(
            guestbook_key(guestbook_name)).order('-date')
        greetings = greetings_string.fetch(10)

        """
        greetings = db.GqlQuery(
            "SELECT * "
            "FROM Greeting "
            "WHERE ANCESTOR IS :1 "
            "ORDER BY date DESC LIMIT 10",
            guestbook_key(guestbook_name)
            )
            """
        '''
        for greeting in greetings:
            if greeting.author:
                self.response.out.write('<b>%s</b> wrote: ' % greeting.author.nickname())
            else:
                self.response.out.write('wrote:')

            self.response.out.write('<blockquote>%s</blockquote>' % cgi.escape(greeting.content))
            '''

        '''
        self.response.out.write("""
                <form action="/sign?%s" method="post">
                  <div></div>
                  <div><textarea name="content" row="3" conspan="6"></textarea></div>
                  <div><input type="submit" value="sign guestbook" /></div>
                </form>
                <hr />
                <hr />sfssd
                <form>
                  guestbook Name: <input type="text" value="%s" name="guestbook_name" />
                  <input type="submit" value="switch" />
                </form>
              </body>
            </html>
        """ % (urllib.urlencode({'guestbook_name':guestbook_name}), cgi.escape(guestbook_name)))
        '''

        user = users.get_current_user()
        if user:
            url = users.create_logout_url(self.request.uri)
            url_linktext = "Logout"
            # self.response.out.write('Hello' + user.nickname())
        else:
            url = users.create_login_url(self.request.uri)
            url_linktext = 'login'
            # self.redirect(users.create_login_url(self.request.uri))

        template_values = {
            'greetings' : greetings,
            'url' : url,
            'url_linktext' : url_linktext
        }
        template = jinja_enviroment.get_template('index.html')
        self.response.out.write(template.render(template_values))
示例#5
0
文件: rpc.py 项目: honten/diary
 def AddGreeting(self,request):
     refresh = simplejson.loads(request.get("refresh"))
     if refresh:
         greeting = Greeting()
         greeting.user = request.get("id")
         greeting.content = request.get("msg")
         currentUser = users.GetCurrentUser()
         if currentUser:
           greeting.author = currentUser
         greeting.put()
     query = datastore.Query('Greeting').Order(('date',datastore.Query.DESCENDING))  #the parameter must be list.
     greetings = []
     for greeting_ in query.Get(20):
         greeting_['key'] = str(greeting_.key())
         #greeting_['author'] = greeting_['user']
         if greeting_['author']:
           greeting_['email'] = greeting_['author'].email()
           greeting_['author'] = "\""+greeting_['email'].split('@')[0]+"\""
         else:
           greeting_['author'] = greeting_['user'].split('@')[0]   
         greeting_["date"] = greeting_["date"].strftime('%m/%d/%y')
         greetings+=[greeting_]
     return greetings