Esempio n. 1
0
def timeline(request):
    form = TweetForm(request.POST or None)
    if request.user['is_authenticated'] and form.is_valid():
        tweet_id = str(uuid.uuid1())
        cass.save_tweet(
            tweet_id, request.session['username'], {
                'username': request.session['username'],
                'body': form.cleaned_data['body'],
            })
        return HttpResponseRedirect(reverse('timeline'))
    start = request.GET.get('start')
    if request.user['is_authenticated']:
        tweets, next = cass.get_timeline(request.session['username'],
                                         start=start,
                                         limit=NUM_PER_PAGE)
    else:
        tweets, next = cass.get_userline(cass.PUBLIC_USERLINE_KEY,
                                         start=start,
                                         limit=NUM_PER_PAGE)
    context = {
        'form': form,
        'tweets': tweets,
        'next': next,
    }
    return render_to_response('tweets/timeline.html',
                              context,
                              context_instance=RequestContext(request))
Esempio n. 2
0
    def handle(self, *args, **options):
        # Oldest account is 10 years
        origin = int(time.time() +
                     datetime.timedelta(days=365.25 * 10).total_seconds() *
                     1e6)
        now = int(time.time() * 1e6)

        num_users = int(args[0])
        max_tweets = int(args[1])

        # Generate number of tweets based on a Zipfian distribution
        sample = [random.paretovariate(15) - 1 for x in range(max_tweets)]
        normalizer = 1 / float(max(sample)) * max_tweets
        num_tweets = [int(x * normalizer) for x in sample]

        for i in range(num_users):
            username = self.get_random_string()
            cass.save_user(username, {'password': self.get_random_string()})
            creation_date = random.randint(origin, now)

            for _ in range(num_tweets[i % max_tweets]):
                cass.save_tweet(str(uuid.uuid1()),
                                username, {
                                    'username': username,
                                    'body': self.get_tweet(),
                                },
                                timestamp=random.randint(creation_date, now))
Esempio n. 3
0
def timeline(request):
    form = TweetForm(request.POST or None)
    if request.user['is_authenticated'] and form.is_valid():
        tweet_id = str(uuid.uuid1())
        cass.save_tweet(tweet_id, request.user['id'], {
            'id': tweet_id,
            'user_id': request.user['id'],
            'body': form.cleaned_data['body'],
        })
        return HttpResponseRedirect(reverse('timeline'))
    start = request.GET.get('start')
    if request.user['is_authenticated']:
        tweets = cass.get_timeline(request.user['id'], start=start,
            limit=NUM_PER_PAGE + 1)
    else:
        tweets = cass.get_userline(cass.PUBLIC_USERLINE_KEY, start=start,
            limit=NUM_PER_PAGE + 1)
    next = None
    if tweets and len(tweets) == NUM_PER_PAGE + 1:
        next = tweets[-1]['_ts']
    tweets = tweets[:NUM_PER_PAGE]
    context = {
        'form': form,
        'tweets': tweets,
        'next': next,
    }
    return render_to_response('tweets/timeline.html', context,
        context_instance=RequestContext(request))
Esempio n. 4
0
def timeline(request):
   # pdb.set_trace()
#print request.GET['status'] # for GET form method
#print request.POST['status'] # for POST form method
#debug
    try:
        if request.user['is_authenticated'] :
            status_opcode=101
            print request.POST['status'] # for POST form method
            print request.POST['user_id'] # for POST form method
            print request.POST['activibe'] # for POST form method
            user_status  = request.POST['status'] # for POST form method
            user_id      = request.POST['user_id'] # for POST form method
            user_domain  = request.POST['activibe'] # for POST form method
	    if user_domain == 101:
	        cass.save_user_status(user_status,user_id,user_domain)
                #start = request.GET.get('start')
                start=1
                status,next = cass.get_user_status(user_id)
                context = {
                   'status': status,
                   'next': next,
                }
                return render_to_response('tweets/timeline.html', context,
                    context_instance=RequestContext(request))
         #       return HttpResponseRedirect(reverse('timeline'))
	else:
 	    print "Invalid Request"
    except:
        print "Unexpected error:"
#debug

    form = TweetForm(request.POST or None)
    if request.user['is_authenticated'] and form.is_valid():
        tweet_id = str(uuid.uuid1())
        cass.save_tweet(tweet_id, request.session['username'], {
            'username': request.session['username'],
            'body': form.cleaned_data['body'],
        })
        return HttpResponseRedirect(reverse('timeline'))
    start = request.GET.get('start')
    if request.user['is_authenticated']:
        tweets,next = cass.get_timeline(request.session['username'],
            start=start, limit=NUM_PER_PAGE)
        #tweets,next = cass.get_friends(request.session['username'],
         #    limit=NUM_PER_PAGE)
    else:
        tweets,next = cass.get_userline(cass.PUBLIC_USERLINE_KEY, start=start,
            limit=NUM_PER_PAGE)
    context = {
        'form': form,
        'tweets': tweets,
        'next': next,
    }
    return render_to_response('tweets/timeline.html', context,
        context_instance=RequestContext(request))
Esempio n. 5
0
def timeline(request):
    form = TweetForm(request.POST or None)
    if request.user['is_authenticated'] and form.is_valid():
        cass.save_tweet(request.session['username'], form.cleaned_data['body'])
        return HttpResponseRedirect(reverse('timeline'))
    start = request.GET.get('start')
    if request.user['is_authenticated']:
        tweets,next = cass.get_timeline(request.session['username'],
            start=start, limit=NUM_PER_PAGE)
    else:
        tweets,next = cass.get_timeline(cass.PUBLIC_TIMELINE_KEY, start=start,
            limit=NUM_PER_PAGE)
    context = {
        'form': form,
        'tweets': tweets,
        'next': next,
    }
    return render_to_response('tweets/timeline.html', context,
        context_instance=RequestContext(request))
Esempio n. 6
0
    def handle(self, *args, **options):
        # Oldest account is 10 years
        origin = int(
            time.time() +
            datetime.timedelta(days=365.25 * 10).total_seconds() * 1e6)
        now = int(time.time() * 1e6)

        num_users = int(args[0])
        max_tweets = int(args[1])

        # Generate number of tweets based on a Zipfian distribution
        sample = [random.paretovariate(15) - 1 for x in range(max_tweets)]
        normalizer = 1 / float(max(sample)) * max_tweets
        num_tweets = [int(x * normalizer) for x in sample]

        for i in range(num_users):
            username = self.get_random_string()
            cass.save_user(username, self.get_random_string())
            creation_date = random.randint(origin, now)

            for _ in range(num_tweets[i % max_tweets]):
                cass.save_tweet(uuid.uuid1(), username, self.get_tweet(), timestamp=random.randint(creation_date, now))

            print "created user"
Esempio n. 7
0
def timeline(request):
    # pdb.set_trace()
    #print request.GET['status'] # for GET form method
    #print request.POST['status'] # for POST form method
    #debug
    try:
        if request.user['is_authenticated']:
            status_opcode = 101
            print request.POST['status']  # for POST form method
            print request.POST['user_id']  # for POST form method
            print request.POST['activibe']  # for POST form method
            user_status = request.POST['status']  # for POST form method
            user_id = request.POST['user_id']  # for POST form method
            user_domain = request.POST['activibe']  # for POST form method
            if user_domain == 101:
                cass.save_user_status(user_status, user_id, user_domain)
                #start = request.GET.get('start')
                start = 1
                status, next = cass.get_user_status(user_id)
                context = {
                    'status': status,
                    'next': next,
                }
                return render_to_response(
                    'tweets/timeline.html',
                    context,
                    context_instance=RequestContext(request))
        #       return HttpResponseRedirect(reverse('timeline'))
        else:
            print "Invalid Request"
    except:
        print "Unexpected error:"


#debug

    form = TweetForm(request.POST or None)
    if request.user['is_authenticated'] and form.is_valid():
        tweet_id = str(uuid.uuid1())
        cass.save_tweet(
            tweet_id, request.session['username'], {
                'username': request.session['username'],
                'body': form.cleaned_data['body'],
            })
        return HttpResponseRedirect(reverse('timeline'))
    start = request.GET.get('start')
    if request.user['is_authenticated']:
        tweets, next = cass.get_timeline(request.session['username'],
                                         start=start,
                                         limit=NUM_PER_PAGE)
        #tweets,next = cass.get_friends(request.session['username'],
        #    limit=NUM_PER_PAGE)
    else:
        tweets, next = cass.get_userline(cass.PUBLIC_USERLINE_KEY,
                                         start=start,
                                         limit=NUM_PER_PAGE)
    context = {
        'form': form,
        'tweets': tweets,
        'next': next,
    }
    return render_to_response('tweets/timeline.html',
                              context,
                              context_instance=RequestContext(request))
def create_tweets():
    for i in range(1, 10000):
        body = "%s %s %s" % (choice(WORDS[0]), choice(WORDS[1]), choice(WORDS[2]))
        save_tweet(choice(USERS), body)