Esempio n. 1
0
def PersonTweetsBackground(request,screen_name,account=None):
    try:
        output = {}
        person = Person.by_screen_name(screen_name)
        count = 0
            
        while person.statusCount() is 0 and person.isUpdating() is True:
            time.sleep(2**count)
            count = count + 1
            
        complete = not person.isUpdating()
          
        output['num_statuses'] = person.statusCount()
        output['complete'] = complete
        
        if person.oldestStatus():
            output['oldest_date'] = person.oldestStatus().status_date()
        if person.latestStatus():
            output['latest_date'] = person.latestStatus().status_date()
        
        if account:
            output['api_calls'] = account.rate_remaining
        response = HttpResponse()
        response.write(simplejson.dumps(output))
    except:
        exc_type, exc_value, exc_traceback = sys.exc_info()
        print "*** print_tb:"
        traceback.print_tb(exc_traceback, limit=1, file=sys.stdout)
        print "*** print_exception:"
        traceback.print_exception(exc_type, exc_value, exc_traceback,
                                  limit=2, file=sys.stdout)
        print "*** print_exc:"
        traceback.print_exc()
        print "*** format_exc, first and last line:"
    return response
Esempio n. 2
0
def GroupAddPage(request,account=None):
    name = request.REQUEST.get('name','')
    short_name = name.replace(' ','_').lower()
    member_names = request.REQUEST.get('member_names','')
    auto_gen = request.REQUEST.get('auto_gen',None)
    
    errors = []
    
    if 'POST' == request.method:
        if auto_gen:
            return render_to_response('group-add.html', {
                                                        "user": account,
                                                        "member_names":member_names,
                                                        }, context_instance=RequestContext(request))
        group = Group.by_short_name_and_user(short_name, account)
        if group:
            return render_to_response('group-add.html', {
                                                        "errors":['A group by the short_name \'' + short_name + '\' already exists for you. Please try another.'], 
                                                        "user": account, 
                                                        "short_name":short_name, 
                                                        "name":name,
                                                        "member_names":member_names,
                                                        }, context_instance=RequestContext(request))
        people = []
        if len(short_name) < 1:
            errors.append("Please ensure the group name is atleast 1 character long.")
        for member in member_names.strip().split(','):
            person = Person.by_screen_name(member)
            if not person:
                person = collector.person(member,account)
            if person:
                people.append(person)
                tasks.updatePersonTweets(person,account)
            else:
                errors.append("Could not find a user named: " + member)
        if len(errors) > 0:
            return render_to_response('group-add.html', {
                                                        "errors":errors, 
                                                        "user": account, 
                                                        "short_name":short_name, 
                                                        "name":name,
                                                        "member_names":member_names,
                                                        }, context_instance=RequestContext(request))
        else:
            group = Group.objects.create(short_name=short_name, user=account, name=name)
            for person in people:
                group.members.add(person)
            group.save()
            return HttpResponseRedirect('/group')
    return render_to_response('group-add.html', {
                                            'user': account, 
                                            },context_instance=RequestContext(request))
Esempio n. 3
0
def PersonTweets(request,screen_name,account=None):
    person = Person.by_screen_name(screen_name)
    filters = {}
    terms=None
    if request.REQUEST.get('start'):
        filters['created_at__gte'] = datetime.strptime(request.REQUEST.get('start'),"%Y-%m-%d")
    if request.REQUEST.get('end'):
        filters['created_at__lt'] = datetime.strptime(request.REQUEST.get('end'),"%Y-%m-%d")
    if request.REQUEST.get('q'):
        terms = request.REQUEST.get('q').split()
    statuses = person.statuses(20,0,query=terms,**filters)
    encodeURLs(statuses, account)
    return render_to_response('person-tweets.html', {'screen_name':screen_name, 'statuses':statuses})
Esempio n. 4
0
def PersonPage(request,screen_name,account=None):
    if account:
        person = collector.person(screen_name,account)
    else:
        person = Person.by_screen_name(screen_name)
    if person:
        tasks.updatePersonTweets(person,account)
        num_friends = person.following_count
    else:
        num_friends = None
    return render_to_response('person.html',{'person':person,
                                      'num_friends':num_friends,
                                      'user':account})
Esempio n. 5
0
def PersonPage(request, screen_name, account=None):
    if account:
        person = collector.person(screen_name, account)
    else:
        person = Person.by_screen_name(screen_name)
    if person:
        tasks.updatePersonTweets(person, account)
        num_friends = person.following_count
    else:
        num_friends = None
    return render_to_response('person.html', {
        'person': person,
        'num_friends': num_friends,
        'user': account
    })
Esempio n. 6
0
def PersonTweets(request, screen_name, account=None):
    person = Person.by_screen_name(screen_name)
    filters = {}
    terms = None
    if request.REQUEST.get('start'):
        filters['created_at__gte'] = datetime.strptime(
            request.REQUEST.get('start'), "%Y-%m-%d")
    if request.REQUEST.get('end'):
        filters['created_at__lt'] = datetime.strptime(
            request.REQUEST.get('end'), "%Y-%m-%d")
    if request.REQUEST.get('q'):
        terms = request.REQUEST.get('q').split()
    statuses = person.statuses(20, 0, query=terms, **filters)
    encodeURLs(statuses, account)
    return render_to_response('person-tweets.html', {
        'screen_name': screen_name,
        'statuses': statuses
    })
Esempio n. 7
0
def PersonTweetsBackground(request, screen_name, account=None):
    try:
        output = {}
        person = Person.by_screen_name(screen_name)
        count = 0

        while person.statusCount() is 0 and person.isUpdating() is True:
            time.sleep(2**count)
            count = count + 1

        complete = not person.isUpdating()

        output['num_statuses'] = person.statusCount()
        output['complete'] = complete

        if person.oldestStatus():
            output['oldest_date'] = person.oldestStatus().status_date()
        if person.latestStatus():
            output['latest_date'] = person.latestStatus().status_date()

        if account:
            output['api_calls'] = account.rate_remaining
        response = HttpResponse()
        response.write(simplejson.dumps(output))
    except:
        exc_type, exc_value, exc_traceback = sys.exc_info()
        print "*** print_tb:"
        traceback.print_tb(exc_traceback, limit=1, file=sys.stdout)
        print "*** print_exception:"
        traceback.print_exception(exc_type,
                                  exc_value,
                                  exc_traceback,
                                  limit=2,
                                  file=sys.stdout)
        print "*** print_exc:"
        traceback.print_exc()
        print "*** format_exc, first and last line:"
    return response
Esempio n. 8
0
 def execute(self):
     person = Person.by_id(self.id)
     if not person:
         person = collector.person_by_id(self.id, self.account)
     updatePersonTweets(person,self.account)
Esempio n. 9
0
 def execute(self):
     person = Person.by_id(self.id)
     if not person:
         person = collector.person_by_id(self.id, self.account)
     updatePersonTweets(person, self.account)
Esempio n. 10
0
def GroupAddPage(request, account=None):
    name = request.REQUEST.get('name', '')
    short_name = name.replace(' ', '_').lower()
    member_names = request.REQUEST.get('member_names', '')
    auto_gen = request.REQUEST.get('auto_gen', None)

    errors = []

    if 'POST' == request.method:
        if auto_gen:
            return render_to_response('group-add.html', {
                "user": account,
                "member_names": member_names,
            },
                                      context_instance=RequestContext(request))
        group = Group.by_short_name_and_user(short_name, account)
        if group:
            return render_to_response('group-add.html', {
                "errors": [
                    'A group by the short_name \'' + short_name +
                    '\' already exists for you. Please try another.'
                ],
                "user":
                account,
                "short_name":
                short_name,
                "name":
                name,
                "member_names":
                member_names,
            },
                                      context_instance=RequestContext(request))
        people = []
        if len(short_name) < 1:
            errors.append(
                "Please ensure the group name is atleast 1 character long.")
        for member in member_names.strip().split(','):
            person = Person.by_screen_name(member)
            if not person:
                person = collector.person(member, account)
            if person:
                people.append(person)
                tasks.updatePersonTweets(person, account)
            else:
                errors.append("Could not find a user named: " + member)
        if len(errors) > 0:
            return render_to_response('group-add.html', {
                "errors": errors,
                "user": account,
                "short_name": short_name,
                "name": name,
                "member_names": member_names,
            },
                                      context_instance=RequestContext(request))
        else:
            group = Group.objects.create(short_name=short_name,
                                         user=account,
                                         name=name)
            for person in people:
                group.members.add(person)
            group.save()
            return HttpResponseRedirect('/group')
    return render_to_response('group-add.html', {
        'user': account,
    },
                              context_instance=RequestContext(request))