当前位置: 首页>>代码示例>>Python>>正文


Python Token.gql方法代码示例

本文整理汇总了Python中models.Token.gql方法的典型用法代码示例。如果您正苦于以下问题:Python Token.gql方法的具体用法?Python Token.gql怎么用?Python Token.gql使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Token的用法示例。


在下文中一共展示了Token.gql方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: fs_request_token_ready

# 需要导入模块: from models import Token [as 别名]
# 或者: from models.Token import gql [as 别名]
def fs_request_token_ready(request):
  """
  OAuth dance for Foursquare, callback URL
  """
  CONSUMER_KEY = FS_CONSUMER_KEY
  CONSUMER_SECRET = FS_CONSUMER_SECRET
  token = Token.gql( "WHERE user = :1", str(request.user) ).get()
  request_values = token.fs_request_token.split("&")
  env = os.environ['QUERY_STRING'].split("&")
  for e in env:
      request_values.append(e)
  values = {}
  for rv in request_values:
      (key, value) = rv.split("=")
      values[key] = value
  oauth_token = oauth.OAuthToken.from_string( token.fs_request_token )
  oauth_verifier = values['oauth_verifier']
  request_token_key = oauth_token
  request_token_secret = values['oauth_token_secret']
  credentials = foursquare.OAuthCredentials(CONSUMER_KEY, CONSUMER_SECRET)
  fs = foursquare.Foursquare(credentials)
  user_token = fs.access_token(token=request_token_key, oauth_verifier=oauth_verifier)
  credentials.set_access_token(user_token)
  fs_token = "oauth_token_secret=%s&oauth_token=%s" % (request_token_secret, str(user_token))
  token.fs_token = fs_token
  token.fs_user_token = str(user_token)
  token.put()
  return redirect( "/" )
开发者ID:johl,项目名称:FireCheckIn,代码行数:30,代码来源:views.py

示例2: fe_connect

# 需要导入模块: from models import Token [as 别名]
# 或者: from models.Token import gql [as 别名]
def fe_connect(request):
  """
  Do the OAuth dance for Fire Eagle!
  """
  CONSUMER_KEY = FE_CONSUMER_KEY
  CONSUMER_SECRET = FE_CONSUMER_SECRET
  CALLBACK_URL = FE_CALLBACK_URL
  fe = FireEagle( CONSUMER_KEY, CONSUMER_SECRET )
  request_token = fe.request_token( oauth_callback=CALLBACK_URL )
  if ( Token.gql( "WHERE user = :1", str(request.user) ).get() != None ):
      token = Token.gql( "WHERE user = :1", str(request.user) ).get()
  else:
    token = Token()
  token.user = str(request.user)
  token.fe_request_token = str(request_token)
  token.put()
  auth_url = fe.authorize( request_token, oauth_callback=CALLBACK_URL )
  return redirect( auth_url )
开发者ID:johl,项目名称:FireCheckIn,代码行数:20,代码来源:views.py

示例3: render_index

# 需要导入模块: from models import Token [as 别名]
# 或者: from models.Token import gql [as 别名]
def render_index(request, template):
    """
    Render the single landing page we have in FireCheckIn. Fill in information on the state
    of the connections to Fire Eagle and Foursquare and see if the user is logged in.
    """
    fireeagle_connected = False
    foursquare_connected = False
    if request.user.is_anonymous():
        return render_to_response(template,  { 'fireeagle_connected': fireeagle_connected,
                                                 'foursquare_connected': foursquare_connected})
    else:
        if ( Token.gql( "WHERE user = :1", str(request.user) ).get() != None ):
              token = Token.gql( "WHERE user = :1", str(request.user) ).get()
              if ( token.fe_token ):
                  fireeagle_connected = True
              if ( token.fs_token ):
                  foursquare_connected = True
        return render_to_response(template,  { 'fireeagle_connected': fireeagle_connected,
                                                 'foursquare_connected': foursquare_connected})
开发者ID:johl,项目名称:FireCheckIn,代码行数:21,代码来源:views.py

示例4: fs_connect

# 需要导入模块: from models import Token [as 别名]
# 或者: from models.Token import gql [as 别名]
def fs_connect(request):
  """
  OAUTh dance for Foursquare
  """
  CONSUMER_KEY = FS_CONSUMER_KEY
  CONSUMER_SECRET = FS_CONSUMER_SECRET
  CALLBACK_URL = FS_CALLBACK_URL
  credentials = foursquare.OAuthCredentials(CONSUMER_KEY, CONSUMER_SECRET)
  fs = foursquare.Foursquare(credentials)
  request_token = fs.request_token( oauth_callback=CALLBACK_URL )
  if ( Token.gql( "WHERE user = :1", str(request.user) ).get() != None ):
      token = Token.gql( "WHERE user = :1", str(request.user) ).get()
  else:
    token = Token()
  token.user = str(request.user)
  token.fs_request_token = str(request_token)
  token.put()
  auth_url = fs.authorize( request_token, oauth_callback=CALLBACK_URL )
  return redirect( auth_url )
开发者ID:johl,项目名称:FireCheckIn,代码行数:21,代码来源:views.py

示例5: deleteme

# 需要导入模块: from models import Token [as 别名]
# 或者: from models.Token import gql [as 别名]
def deleteme(request):
    """
    Remove the currently logged in user from our database and log them out. 
    Privacy, you know? Don't request this casually :)
    """
    if (not (request.user.is_anonymous())):
        logout = users.create_logout_url( "/" )
        db.delete(Token.gql( "WHERE user = :1", str(request.user) ).get())
        return redirect( logout )
    else:
        return redirect( "/" )
开发者ID:johl,项目名称:FireCheckIn,代码行数:13,代码来源:views.py

示例6: syncworker

# 需要导入模块: from models import Token [as 别名]
# 或者: from models.Token import gql [as 别名]
def syncworker(request):
    """
    Okay, this is the real stuff. It's the worker process for the task queue.
    Gets a user name as a parameter.
    Calls Foursquare, Fire Eagle. Compares times of last check-in. If the Foursquare check-in
    is more recent, updates Fire Eagle.
    We catch all kinds of exceptions, so users with messed up OAuth permissions won't stop
    the worker.
    """
    user = request.args.get('user')
    logging.warning('user is: %s' % str(user))
    t = Token.gql( "WHERE user = :1", str(user) ).get()
    lat = 0
    lon = 0
    try:
        token = oauth.OAuthToken.from_string( t.fe_token )
        fe = FireEagle( FE_CONSUMER_KEY, FE_CONSUMER_SECRET )
        user = fe.user( token )
        date_time = user[0]['location'][0]['located_at']
        """
        For some reasons that only Yahoo! knows, Fire Eagle logs its time and dates
        in local Californian time (including Daylight Saving Time), so we have to
        convert the thing to UTC. Crazy, huh? 
        Share my frustration at http://blog.johl.io/post/393494632/what-time-is-it
        """
        current_datetime = datetime.datetime.now(ustimezones.pacific()) # What time is it in Cali?
        fe_delta = str(current_datetime.replace(tzinfo=None) - date_time)
        credentials = foursquare.OAuthCredentials( FS_CONSUMER_KEY, FS_CONSUMER_SECRET )
        fs = foursquare.Foursquare( credentials )
        token = oauth.OAuthToken.from_string( t.fs_user_token )
        credentials.set_access_token(token)
        history = fs.history()
        date_time = history['checkins'][0]['created']
        lat = history['checkins'][0]['venue']['geolat']
        lon = history['checkins'][0]['venue']['geolong']
        current_datetime = datetime.datetime.now()
        date_time = datetime.datetime.fromtimestamp(time.mktime(rfc822.parsedate(date_time)))
        fs_delta = str(current_datetime.replace(tzinfo=None) - date_time)
    except:
        """
        So yeah, something went wrong. Let's assume we should update Fire Eagle.
        """
        logging.warning('Application error occurred with user %s', str(t.user))
        fs_delta = 0
        fe_delta = -1
    if (fs_delta < fe_delta):
      try:
        fe.update( lat=lat, lon=lon, token=oauth.OAuthToken.from_string( t.fe_token ) )
      except:
        """
        Can't update Fire Eagle. Whatever.
        """
        logging.warning('Application error occurred with user %s', str(t.user))
    return render_to_response('firecheckin/index.html')
开发者ID:johl,项目名称:FireCheckIn,代码行数:56,代码来源:views.py

示例7: sync

# 需要导入模块: from models import Token [as 别名]
# 或者: from models.Token import gql [as 别名]
def sync(request):
  """
  It's the cron job that gets run every 2 minutes (or on request). Iterates over users and
  queues tasks to sync. Will only 'iterate' over the current user
  if called by a logged in user.
  """
  tokens = []
  if (request.user.is_anonymous()):
      tokens = Token.all().fetch(1000)
  else:
      tokens.append(Token.gql( "WHERE user = :1", str(request.user) ).get())
  for t in tokens:
      taskqueue.add(url='/syncworker/?user=%s' % str(t.user), method='GET')
  """
  We cannot return a redirect when called anonymously as a cron job.
  Google App Engine will complain about 'Too many continues.'
  """
  if (request.user.is_anonymous()):
      return render_to_response('firecheckin/index.html')
  else:
      return redirect( "/" )
开发者ID:johl,项目名称:FireCheckIn,代码行数:23,代码来源:views.py

示例8: fe_request_token_ready

# 需要导入模块: from models import Token [as 别名]
# 或者: from models.Token import gql [as 别名]
def fe_request_token_ready(request):
  """
  OAuth dance for Fire Eagle, callback URL
  """
  query = request.environ['QUERY_STRING']
  query_values = query.split("&")
  values = {}
  for qv in query_values:
      (key, value) = qv.split("=")
      values[key] = value
  oauth_verifier = values['oauth_verifier']
  oauth_token = values['oauth_token']
  CONSUMER_KEY = FE_CONSUMER_KEY
  CONSUMER_SECRET = FE_CONSUMER_SECRET
  fe = FireEagle( CONSUMER_KEY, CONSUMER_SECRET )
  token = Token.gql( "WHERE user = :1", str(request.user) ).get()
  oauth_token = oauth.OAuthToken.from_string( token.fe_request_token )
  fe = FireEagle( CONSUMER_KEY, CONSUMER_SECRET )
  access_token = fe.access_token( oauth_verifier=oauth_verifier, token=oauth_token )
  token.fe_token = str(access_token)
  token.put()
  return redirect( "/" )
开发者ID:johl,项目名称:FireCheckIn,代码行数:24,代码来源:views.py


注:本文中的models.Token.gql方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。