Ejemplo n.º 1
0
    def put(self, user):
        """Update a single user."""

        sex_am = request.form.get('sex_am')
        if sex_am in ('guy', 'gal'):
            previous = redis.get('users:%s:sex_am' % user)
            if previous and previous != sex_am:
                redis.srem('sex_am:%s' % previous, user)

            redis.set('users:%s:sex_am' % user, sex_am)
            redis.sadd('sex_am:%s' % sex_am, user)

        sex_want = request.form.get('sex_want')
        if sex_want in ('guy', 'gal'):
            previous = redis.get('users:%s:sex_want' % user)
            if previous and previous != sex_want:
                redis.srem('sex_want:%s' % previous, user)

            redis.set('users:%s:sex_want' % user, sex_want)
            redis.sadd('sex_want:%s' % sex_want, user)

        zipcode = request.form.get('zip', '')
        zipshort = zipcode[:2]

        previous = redis.get('users:%s:zip' % user)
        if previous and previous != zipcode:
            redis.srem('zip:%s' % previous, user)
        redis.set('users:%s:zip' % user, zipcode)

        previous = redis.get('users:%s:zipshort' % user)
        if previous and previous != zipshort:
            redis.srem('zipshort:%s' % previous, user)
        redis.set('users:%s:zipshort' % user, zipshort)

        redis.sadd('zip:%s' % zipcode, user)
        redis.sadd('zipshort:%s' % zipshort, user)

        birthday = request.form.get('birthday', '')
        birthyear = birthday.split('-')[0]

        previous = redis.get('users:%s:birthyear' % user)
        if previous and previous != birthyear:
            redis.srem('birthyears:%s' % previous, user)

        redis.set('users:%s:birthday' % user, birthday)
        redis.set('users:%s:birthyear' % user, birthyear)

        redis.sadd('users:%s:birthday' % birthday, user)
        redis.sadd('users:%s:birthyear' % birthyear, user)

        # Birthyear is the score.
        redis.zadd('birthyears', user, birthyear)

        return Response()
Ejemplo n.º 2
0
Archivo: tweets.py Proyecto: cvan/mula
def run():
    # When the run started.
    timestamp = datetime.datetime.today().strftime('%Y-%m-%d %H:%M:%S')
    redis_timestamp = datetime.datetime.today().strftime('%Y%m%d%H%M%S')
    print timestamp

    # Sorted Set.
    # key: runs
    # score: redis_timestamp
    # value: timestamp
    redis.zadd('runs', timestamp, redis_timestamp)

    if settings.MOCK:
        counts = {}
        counts['exact'] = {'composed': 1, 'elated': 8, 'energetic': 2, 'tired': 1, 'depressed': 6, 'anxious': 4, 'confident': 1, 'agreeable': 5}
        counts['fuzzy'] = {'composed': 10, 'elated': 80, 'energetic': 20, 'tired': 10, 'depressed': 60, 'anxious': 40, 'confident': 10, 'agreeable': 50}
        #
        # TODO: Add total analyzed, etc.
        #
    else:
        counts = process_tweets(search_terms)
    print counts

    for mood in moods:
        for precision, sub_counts in counts.iteritems():
            # Set.
            # key: runs:<redis_timestamp>:<precision [exact or fuzzy]>:<mood>
            # value: <count>
            redis.set('runs:%s:moods:%s:%s' % (redis_timestamp, precision, mood),
                      sub_counts.get(mood, 0))

    for total in totals:
        for precision, sub_counts in counts.iteritems():
            # Set.
            # key: runs:<redis_timestamp>:<precision [exact or fuzzy]>:<total>
            # value: <count>
            redis.set('runs:%s:totals:%s:%s' % (redis_timestamp, precision, total),
                      sub_counts.get(total, 0))