Ejemplo n.º 1
0
def timeline(request):

    count = request.GET.get('count')

    # Get home timeline
    if not count:
        timeline = get_home_timeline()  # Default grabs 10 tweets
    else:
        timeline = get_home_timeline(count=count)

    try:
        sources = json.loads(request.GET.get('sources'))
    except TypeError as e:
        return JsonResponse({'errors': 'missing parameter sources'}, status=400)

    # Keep only what want to return :-)
    trimmed_timeline = map(lambda t: {'created_at': t.get('created_at'),
                                      'screen_name': t.get('user').get('screen_name'),
                                      'id': t.get('id'),
                                      'url': 'https://twitter.com/{0}/status/{1}'.format(t.get('user').get('id'), t.get('id')),
                                      'text': t.get('text')}, timeline)

    # Find sources from home timeline
    if sources:
        tweet_sources = analyze_sources(timeline)

        # Return it as JSON
        return JsonResponse({'tweets': trimmed_timeline, 'sources': tweet_sources}, status=200)

    return JsonResponse({'tweets': trimmed_timeline}, status=200)
Ejemplo n.º 2
0
 def update_tweets(self):
     if not self.twitter_account:
         return
     fmt = '{text} | {user[screen_name]}'
     try:
         self['timeline'].data_source.items = [fmt.format(**tweet) for tweet
             in twitter.get_home_timeline(self.twitter_account)]
     except TypeError:  # too many Twitter API calls
         pass
Ejemplo n.º 3
0
def timeline(request):

    count = request.GET.get('count')

    # Get home timeline
    if not count:
        timeline = get_home_timeline()  # Default grabs 10 tweets
    else:
        timeline = get_home_timeline(count=count)

    try:
        sources = json.loads(request.GET.get('sources'))
    except TypeError as e:
        return JsonResponse({'errors': 'missing parameter sources'},
                            status=400)

    # Keep only what want to return :-)
    trimmed_timeline = map(
        lambda t: {
            'created_at':
            t.get('created_at'),
            'screen_name':
            t.get('user').get('screen_name'),
            'id':
            t.get('id'),
            'url':
            'https://twitter.com/{0}/status/{1}'.format(
                t.get('user').get('id'), t.get('id')),
            'text':
            t.get('text')
        }, timeline)

    # Find sources from home timeline
    if sources:
        tweet_sources = analyze_sources(timeline)

        # Return it as JSON
        return JsonResponse(
            {
                'tweets': trimmed_timeline,
                'sources': tweet_sources
            }, status=200)

    return JsonResponse({'tweets': trimmed_timeline}, status=200)
Ejemplo n.º 4
0
def get_tweets(sender):
	tlist = []
	tweets = twitter.get_home_timeline(account)
	console.show_activity('Refreshing')
	time.sleep(1)
	for t in tweets:
		tlist.append(t.get('text'))
	timeline.data_source = ui.ListDataSource(items=tlist)
	timeline.reload()
	console.hide_activity()
Ejemplo n.º 5
0
def main():
	accounts = twitter.get_all_accounts()
	if not accounts:
		print('No Twitter accounts were found. You can configure Twitter accounts in the settings app. If you have denied access to your accounts when prompted, you can also change your mind there.')
	account = accounts[0]
	username = account['username']
	print('Loading recent tweets in %s\'s timeline...' % (username,))
	tweets = twitter.get_home_timeline(account)
	for tweet in tweets:
		print('%s:\n\n%s' % (tweet['user']['screen_name'], tweet['text']))
		print('-' * 40)
Ejemplo n.º 6
0
def main():
	accounts = twitter.get_all_accounts()
	if not accounts:
		print 'No Twitter accounts were found. You can configure Twitter accounts in the settings app. If you have denied access to your accounts when prompted, you can also change your mind there.'
	account = accounts[0]
	username = account['username']
	print 'Loading recent tweets in %s\'s timeline...' % (username,)
	tweets = twitter.get_home_timeline(account)
	for tweet in tweets:
		print '%s:\n\n%s' % (tweet['user']['screen_name'], tweet['text'])
		print '-' * 40
Ejemplo n.º 7
0
import twitter

all_accounts = twitter.get_all_accounts()
if len(all_accounts) >= 1:
    account = all_accounts[0]
    tweets = twitter.get_home_timeline(account)
    for t in tweets:
        print(t.get('text'))
        print('=' * 0)
else:
    print(
        'You don\'t have any Twitter accounts (or haven\'t given permission to access them).'
    )
Ejemplo n.º 8
0
	else:
		form = UserForm()


	return render(request, 'index.html', {'form': form})

def content(request):
	return render(request, 'content.html', )

# @render_to('quokkapp:content.html')
# @login_required
def view_name(request):
		return {
			"interest": formFields.interest1,
			"jam": "Do you like jam?"
		}

# twitter stuff
APP_KEY = 'qeADlQBHiLENCx5Oqg4bqOjz8'
APP_SECRET ='zjzaBO7BSrB5MOC718rhQSdrY909vMOIEObbjHRrGju3T2BKFz'

twitter = Twython(APP_KEY, APP_SECRET)

auth = twitter.get_authentication_tokens(callback_url='http://127.0.0.1:8000/content/')

OAUTH_TOKEN = auth['oauth_token']
OAUTH_TOKEN_SECRET = auth['oauth_token_secret']

twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
twitter.get_home_timeline()