Exemple #1
0
    def get(self):
        path = os.path.join(os.path.dirname(__file__),'puzzle.html')

        #client setup
        gd_client = service.PhotosService()
        appengine.run_on_appengine(gd_client)
        #Get picasa album
        albums = gd_client.GetUserFeed(user='******')
        for album in albums.entry:
            if album.title.text == 'BHTrHunt_sirihikareue0214':
                break
        #Get photos
        photos = gd_client.GetFeed('/data/feed/api/user/%s/albumid/%s?kind=photo' % (
            'sirihikareue0214',album.gphoto_id.text))
        #Get photo
        i = 0
        randint = random.randrange(len(photos.entry))
        for photo in photos.entry:
            if i == randint:
		        break
            i+=1

        template_values = {'album': album,'photos': photos,'photo': photo}
        
        self.response.out.write(template.render(path,template_values))
Exemple #2
0
def StoreCalendarSessionToken(relative_url):
  """Extract calendar auth tokens from url and store them in the datastore.

  Args:
    relative_url: The url that was called by the calendar token system with
        token information in it.
  """
  # Get auth token from url.
  auth_token = auth.extract_auth_sub_token_from_url(relative_url)
  assert auth_token

  # Upgrade to session token.
  calendar_client = calendar_service.CalendarService()
  gdata_appengine.run_on_appengine(calendar_client, store_tokens=False,
                                   single_user_mode=True, deadline=10)
  session_token = calendar_client.upgrade_to_session_token(auth_token)
  assert session_token

  # Write session token to datastore.
  session_token_str = session_token.get_token_string()
  config = models.Configuration(key_name=_CALENDAR_TOKEN_KEY_NAME,
                                config_value=session_token_str,
                                config_key=_CALENDAR_TOKEN_KEY_NAME)
  config.put()

  # Refresh memcache session token and make sure a usable calendar client can be
  # created.
  calendar_client = _GetCalendarService(refresh_memcache=True)
  assert calendar_client is not None
 def _doTweet(self, masterData, botData):
   import oauth
   client = oauth.TwitterClient(masterData.cKey,
                                masterData.cSecret, None)
   run_on_appengine(client, store_tokens=False, single_user_mode=True)
   param = {'status': botData.status}
   client.make_request('https://api.twitter.com/1.1/statuses/update.json',
                       token=masterData.aToken,
                       secret=masterData.aTokenSecret,
                       additional_params=param,
                       protected=True,
                       method='POST')
   logging.info(botData.status)
 def do_login(self, username, password, isAppEngine=False, ssl=None):
     """Login to the Calendar Service"""
     self._ca_client = gdata.calendar.service.CalendarService()
     if ssl != None:
         self._ca_client.ssl = True
     if isAppEngine:
         from gdata.alt.appengine import run_on_appengine
         run_on_appengine(self._ca_client)
     self._ca_client.email = username
     self._ca_client.password = password
     self._ca_client.source = 'sgtdev-pythonCalendarHelper-0.1'
     self._ca_client.ProgrammaticLogin()
     return self._ca_client
Exemple #5
0
def search(q, restrict=None):
    yt_service = YouTubeService()
    run_on_appengine(yt_service)

    yt_service.ssl = True
    yt_service.developer_key = settings.YOUTUBE_API_KEY

    query = YouTubeVideoQuery()
    query.vq = q
    if restrict:
        query.restriction = restrict

    query.max_results = 1
    feed = yt_service.YouTubeQuery(query)
    return get_embed_code(feed.entry[0])
def create_youtube_service(oauth_token=None):
  """Create a YouTubeService object.

  If provided, use the OAuth 2 token. Otherwise, requests are unauthenticated.

  """
  yt_service = gdata.youtube.service.YouTubeService()
  yt_service.ssl = True
  yt_service.client_id = app_identity.get_application_id()
  appengine.run_on_appengine(yt_service, store_tokens=False,
                             single_user_mode=True,
                             deadline=webutils.HTTP_TIMEOUT)
  if oauth_token is not None:
    yt_service.SetAuthSubToken(oauth_token)
  yt_service.developer_key = DEVELOPER_KEY
  return yt_service
 def get(self):
     self.response.headers['Content-Type'] = 'text/xml'
     self.response.out.write('<?xml version="1.0" encoding="UTF-8"?>')
     
     video_id = self.request.get('id', default_value='')
     video = None
     try:
         yt = run_on_appengine(YouTubeService())
         video = yt.GetYouTubeVideoEntry(video_id=video_id)
     except Exception, e:
         pass #will return empty result :)
Exemple #8
0
def setOAuthInputParamaters(service, data):
  """Sets OAuth input parameters for given service.
   """

  request = data.request
  site = data.site
  if system.isSecondaryHostname(request):
    consumer_key = site.secondary_gdata_consumer_key
    consumer_secret = site.secondary_gdata_consumer_secret
  else:
    consumer_key = site.gdata_consumer_key
    consumer_secret = site.gdata_consumer_secret

  if not consumer_key or not consumer_secret:
    return

  service.SetOAuthInputParameters(
      auth.OAuthSignatureMethod.HMAC_SHA1, consumer_key.encode('utf-8'),
      consumer_secret.encode('utf-8'), settings.GDATA_SCOPES)
  appengine.run_on_appengine(service)
Exemple #9
0
    def get(self):
        path = os.path.join(os.path.dirname(__file__),'photo.html')

        #client_id = str(uuid.uuid4())
        #token = channel.create_channel(client_id)

        #client setup
        gd_client = service.PhotosService()
        appengine.run_on_appengine(gd_client)
        #Get picasa album
        albums = gd_client.GetUserFeed(user='******')
        for album in albums.entry:
            if album.title.text == 'BHTrHunt_sirihikareue0214':
                break
        #Get photo
        photos = gd_client.GetFeed('/data/feed/api/user/%s/albumid/%s?kind=photo' % (
            'sirihikareue0214',album.gphoto_id.text))
        #template_values = {'album': album,'photos': photos,'token' : token,'client_id' : client_id}
        template_values = {'album': album,'photos': photos}
        #template_values = {}
        
        self.response.out.write(template.render(path,template_values))
Exemple #10
0
def _GetCalendarService(refresh_memcache=False):
  """Create gdata calendar service with a valid session id.

  Creates a gdata calendar service. Uses session key from memcache when
  available. On a memcache miss, loads the session key from datastore. Tries to
  return a usable calendar service and None if it fails to create one.

  Args:
    refresh_memcache: Force a memcache session key refresh from datastore.

  Returns:
    A gdata.calendar.service.CalendarService
  """
  # Initialize calendar service for AppEngine.
  headers = {'X-Redirect-Calendar-Shard': 'true'}
  calendar_client = calendar_service.CalendarService(additional_headers=headers)
  gdata_appengine.run_on_appengine(calendar_client, store_tokens=False,
                                   single_user_mode=True, deadline=10)

  session_token = None
  memcache_key = 'memcache_'+ _CALENDAR_TOKEN_KEY_NAME
  if not refresh_memcache:
    session_token = memcache.get(memcache_key)

  if session_token is None:  # Memcache miss, load from datastore.
    config_entity = models.Configuration.get_by_key_name(
        _CALENDAR_TOKEN_KEY_NAME
    )
    if not config_entity or not config_entity.config_value: return None
    session_token = config_entity.config_value
    memcache.set(memcache_key, session_token)  # Place in memcache.

  token = auth.AuthSubToken()
  token.set_token_string(session_token)
  calendar_client.current_token = token

  return calendar_client
Exemple #11
0
  def get(self):
    yt_service = gdata.youtube.service.YouTubeService()
    appengine.run_on_appengine(yt_service, store_tokens=False,
                               single_user_mode=True, deadline=10)
    yt_service.SetAuthSubToken(self.oauth2_decorator.credentials.access_token)

    video_feed = yt_service.GetYouTubeUserFeed(username="******")
    videos = []
    for video_entry in video_feed.entry:
      video = dict(
        id=(video_entry.id.text.split('/'))[-1],
        title=video_entry.title.text,
        description=video_entry.media.description.text,
        thumbnail_url=video_entry.media.thumbnail[1].url
      )
      videos.append(video)

    params = dict(
      logout_url=users.create_logout_url(self.request.uri),
      videos=videos
    )

    path = os.path.join(os.path.dirname(__file__), 'templates', 'index.html')
    self.response.out.write(template.render(path, params))
Exemple #12
0
def run_on_django(gdata_service, request=None, store_tokens=True, single_user_mode=False, deadline=10):
    try:
        import google.appengine
    except:
        pass
    else:
        from gdata.alt.appengine import run_on_appengine
        gdata_service = run_on_appengine(gdata_service, deadline=deadline)

    try:
        gdata_service._SetSessionId(None)
    except:
        pass

    gdata_service.token_store = DjangoTokenStore(request)
    gdata_service.auto_store_tokens = store_tokens
    gdata_service.auto_set_current_token = single_user_mode

    return gdata_service
Exemple #13
0
def run_on_django(gdata_service,
                  request=None,
                  store_tokens=True,
                  single_user_mode=False,
                  deadline=10):
    try:
        import google.appengine
    except:
        pass
    else:
        from gdata.alt.appengine import run_on_appengine
        gdata_service = run_on_appengine(gdata_service, deadline=deadline)

    try:
        gdata_service._SetSessionId(None)
    except:
        pass

    gdata_service.token_store = DjangoTokenStore(request)
    gdata_service.auto_store_tokens = store_tokens
    gdata_service.auto_set_current_token = single_user_mode

    return gdata_service
Exemple #14
0
def douban_service():
    service = DoubanService(api_key=CONSUMER_KEY, \
                            secret=CONSUMER_SECRET)
    return run_on_appengine(service)
def douban_service():
    service = DoubanService(api_key=settings.DOUBAN_API_KEY, \
                            secret=settings.DOUBAN_API_SECRET)
    return run_on_appengine(service)