Пример #1
0
class API(webapp.RequestHandler):
    def get(self, profile_name, request_object, response_format):
        context = {}

        # Create a Twitter OAuth object.
        try:
            twitter = getTwitterObject()
        except AttributeError, e:
            # Something went wrong, perhaps the OAuth tokens expired or have been removed
            # from the datastore.
            error = {
                'title':
                "Something's Broken",
                'message':
                "We're so sorry, but it seems that Foller.me is down. We'll deal with this issue as soon as possible"
            }
            logging.critical(
                "API: Cannot create a Twitter OAuth object. Lacking tokens?")

            rendertext(self, encoder.encode({'error': error}))
            return

        # Fire a /statuses/user_timeline request, record parse the first entry for the user
        # details.
        try:
            timeline = twitter.GetUserTimeline({
                'screen_name': profile_name,
                'count': 100
            })
        except urllib2.HTTPError, e:
            # An HTTP error can occur during requests to the Twitter API.
            # We handle such errors here and log them for later investigation.
            error = {
                'title':
                'Unknown Error',
                'message':
                "We're sorry, but an unknown error has occoured. We'll very be glad if you <a href='http://twitter.com/kovshenin'>report this</a>."
            }
            if e.code == 401:
                error['title'] = 'Profile Protected'
                error[
                    'message'] = "It seems that @%s's tweets are protected." % profile_name
            elif e.code == 404:
                error['title'] = 'Profile Not Found'
                error[
                    'message'] = 'It seems that @%s is not tweeting at all.' % profile_name

            # Log the error, render the template and return
            logging.warning("API: Code %s: %s - " % (e.code, e.msg) +
                            "Request was: %s" % profile_name)
            rendertext(self, encoder.encode({'error': error}))
            return
Пример #2
0
	def get(self, profile_name, request_object, response_format):
		context = {}
		
		# Create a Twitter OAuth object.
		try:
			twitter = getTwitterObject()
		except AttributeError, e:
			# Something went wrong, perhaps the OAuth tokens expired or have been removed
			# from the datastore.
			error = {'title': "Something's Broken", 'message': "We're so sorry, but it seems that Foller.me is down. We'll deal with this issue as soon as possible"}			
			logging.critical("API: Cannot create a Twitter OAuth object. Lacking tokens?")
			
			rendertext(self, encoder.encode({'error': error}))
			return
Пример #3
0
    def get(self, profile_name, request_object, response_format):
        context = {}

        # Create a Twitter OAuth object.
        try:
            twitter = getTwitterObject()
        except AttributeError, e:
            # Something went wrong, perhaps the OAuth tokens expired or have been removed
            # from the datastore.
            error = {
                'title':
                "Something's Broken",
                'message':
                "We're so sorry, but it seems that Foller.me is down. We'll deal with this issue as soon as possible"
            }
            logging.critical(
                "API: Cannot create a Twitter OAuth object. Lacking tokens?")

            rendertext(self, encoder.encode({'error': error}))
            return
Пример #4
0
def save_profile_cache(screen_name, cache_data):
    clear_profile_cache(screen_name)
    cache = Cache(name='profile:' + screen_name.lower(),
                  value=encoder.encode(cache_data))
    cache.put()
Пример #5
0
            logging.warning("API: Code %s: %s - " % (e.code, e.msg) +
                            "Request was: %s" % profile_name)
            rendertext(self, encoder.encode({'error': error}))
            return

        try:
            profile = timeline[0]['user']
        except IndexError, e:
            # If timeline[0] is inaccessible then there were no tweets at all
            error = {
                'title': 'Profile Empty',
                'message': "There were no tweets by @%s at all." % profile_name
            }
            logging.warning("API: Accessed an empty profile: %s" %
                            profile_name)
            rendertext(self, encoder.encode({'error': error}))
            return

        # We make some manipulations for the profile, since we don't want to output some fields
        # (such as the created at field) the way Twitter passes them over to us. We convert that
        # into a valid datetime object.
        profile['created_at'] = datetime.strptime(
            profile['created_at'], "%a %b %d %H:%M:%S +0000 %Y")
        context['profile'] = profile

        # Let's submit this as a recent query into the datastore (via the task queue api)
        taskqueue.add(url='/admin/tasks/',
                      params={
                          'task':
                          'recent-create',
                          'recent':
Пример #6
0
def save_profile_cache(screen_name, cache_data):
	clear_profile_cache(screen_name)
	cache = Cache(name='profile:' + screen_name.lower(), value=encoder.encode(cache_data))
	cache.put()
Пример #7
0
			elif e.code == 404:
				error['title'] = 'Profile Not Found'
				error['message'] = 'It seems that @%s is not tweeting at all.' % profile_name
			
			# Log the error, render the template and return
			logging.warning("API: Code %s: %s - " % (e.code, e.msg) + "Request was: %s" % profile_name)
			rendertext(self, encoder.encode({'error': error}))
			return
		
		try:	
			profile = timeline[0]['user']
		except IndexError, e:
			# If timeline[0] is inaccessible then there were no tweets at all
			error = {'title': 'Profile Empty', 'message': "There were no tweets by @%s at all." % profile_name}
			logging.warning("API: Accessed an empty profile: %s" % profile_name)
			rendertext(self, encoder.encode({'error': error}))
			return
		
		# We make some manipulations for the profile, since we don't want to output some fields
		# (such as the created at field) the way Twitter passes them over to us. We convert that
		# into a valid datetime object.
		profile['created_at'] = datetime.strptime(profile['created_at'], "%a %b %d %H:%M:%S +0000 %Y")
		context['profile'] = profile
		
		# Let's submit this as a recent query into the datastore (via the task queue api)
		taskqueue.add(url='/admin/tasks/', params={'task': 'recent-create', 'recent': encoder.encode({'screen_name': profile['screen_name'], 'profile_image_url': profile['profile_image_url']})}, method='POST')
	
		# The data string will hold all our text concatenated. Perhaps this is not the fastest way
		# as strings are unchangable. Might convert this to a list in the future and then join if needed.
		data = ""
		for entry in timeline: