Esempio n. 1
0
def tweet(sender, instance, **kwargs):
	TOTAL_CHARS = 140
	
	api = utils.auth()
	
	if api:
		ctype = ContentType.objects.get_for_model(instance)
		
		template_list = [
			"django_twitter/snippets/%s.html",
			"django_twitter/snippets/item.html"
		]
		
		context = { 'obj': instance }
		
		tweet = render_to_string(template_list, context)
		
		if instance.get_absolute_url():
			site = Site.objects.get_current()
			url = "http://%s%s" % (site.domain, instance.get_absolute_url())
			url_length = len(url) + len(': ')
			TOTAL_CHARS = TOTAL_CHARS - url_length
		
		if len(tweet) >= TOTAL_CHARS:
			TOTAL_CHARS = TOTAL_CHARS - len('...')
			tweet = ' '.join(tweet[:TOTAL_CHARS].split(' ')[:-1]) + '...'
		
		if url:
			tweet += ': ' + url
		
		if not settings.DEBUG:
			return api.update_status(tweet)
		else:
			return log.debug(tweet)
	def handle(self, *args, **options):
		api = utils.auth()
		
		if api:
			tweets = api.retweets_of_me()
			
			for tweet in tweets:
				print "%s:\t%s" % (tweet.id, tweet.text)
	def handle(self, *args, **options):
		api = utils.auth()
		
		if api:
			query = raw_input('Query: ').split()
			
			results = api.search(query)
			
			for result in results:
				print "\n%s" % result.text
				print "\t@%s - %s" % (result.from_user, result.created_at)
				print "\thttp://twitter.com/%s/status/%s" % (result.from_user, result.id)
Esempio n. 4
0
def timeline(request):
    """
	Twitter timeline page.
	"""
    api = utils.auth()

    if api:
        tweets = api.friends_timeline()
    else:
        tweets = None

    context = {"tweets": tweets, "title": "Twitter Timeline"}

    return render_to_response("django_twitter/timeline.html", context, context_instance=RequestContext(request))
	def handle(self, *args, **options):
		level = { '0': logging.WARN, '1': logging.INFO, '2': logging.DEBUG }[options.get('verbosity', '0')]
		logging.basicConfig(level=level, format="%(name)s: %(levelname)s: %(message)s")
		
		api = utils.auth()
		
		if api:
			status = raw_input("What's happening?: ").strip()
			
			if len(status) > 140:
				return log.warn("This tweet is to long. It has %s charaters.", len(status))
			
			if not settings.DEBUG:
				status = api.update_status(status)
				log.info("http://twitter.com/%s/status/%s" % (status.author.screen_name, status.id))
			else:
				return log.debug(status)
	def handle(self, *args, **options):
		api = utils.auth()
		
		if api:
			return api.test()