Esempio n. 1
0
def social_winner(request):
    """
        Finds the winner for the day

        :url: /a/winner/social/

        :param POST['code']: the pass code to select winner
        :param POST['winners']: list of people
        :param POST['test']: '1' if testing
    """
    r = {}

    test = False
    if request.POST.get('test','0') == '1':
        test = True 

    if request.POST.get('code','000') == 'ch00seW199Er':
        # check the number of people who transacted today
        d = date.today()
        
        fb_ids = request.POST.getlist('winners')
        winner_str = ""

        if not test:
            for f in fb_ids:
                winner = OTNUser.objects.get(facebook_profile__facebook_id=f)
                # save to DB
                win_prize = Winner(user=winner, prize="$50 TechCASH")
                win_prize.save()
                
                # if called the day after
                win_prize.timestamp = d 
                win_prize.save()
                winner_str += "%s, %s\n"%(winner.name, winner.mit_id) 

                # email winner
                msg = "You are MealTime Social winner!\n\nYou will receive $50 credit in your TechCASH account.\n\n-kwan"
                send_mail('OTN Social Prize Winner', msg, '*****@*****.**', [winner.my_email, '*****@*****.**'], fail_silently=False) 

            # email mitcard to credit from DIGRECPT1 to MIT ID
            msg = "%s\nare OTN Social Winners!\n\nPlease transfer $50 from DIGRECPT1 to their TechCASH accounts respectively.\n\n-kwan"%winner_str
            send_mail('OTN Social Prize Winner', msg, '*****@*****.**', ['*****@*****.**', '*****@*****.**'], fail_silently=False) 

        r['result'] = {'winners': winner_str}
    else:
        r['result'] = '-1'

    return JSONHttpResponse(r)
Esempio n. 2
0
def final_winners():

    u = OTNUser.objects.get(name="Victoria Hammett")
    w = Winner(user=u, prize="$550 Apple gift certificate")
    w.save()
    u = OTNUser.objects.get(name="Bob Chen")
    w = Winner(user=u, prize="$50 Amazon gift certificate")
    w.save()
    u = OTNUser.objects.get(name="Michael Snively")
    w = Winner(user=u, prize="$50 Amazon gift certificate")
    w.save()
    u = OTNUser.objects.get(name="Pooja Shah")
    w = Winner(user=u, prize="$50 Amazon gift certificate")
    w.save()
    u = OTNUser.objects.get(name="Carin King")
    w = Winner(user=u, prize="$50 Amazon gift certificate")
    w.save()
Esempio n. 3
0
def winner_add(request):
    """
        Adds winner to Winner table

        :url: /a/winner/add/
    """
    r = {}

    if request.POST.get('code','000') == 'ch00seW199Er':
        u = OTNUser.objects.get(facebook_profile__facebook_id=517379465)
        w = Winner(user=u, prize="$100 Legal's Gift Certificate")
        w.save()
        # update to old time
        w.timestamp=datetime(year=2010, month=3, day=21, hour=0, minute=0, second=0)
        w.save()
        r['result'] = {'name':w.user.name, 'id': "%d"%w.user.id}
    else:
        r['result'] = '-1'
    return JSONHttpResponse(r)
Esempio n. 4
0
def find_winner(request):
    """
        Finds the winner for the day

        :url: /a/winner/

        :param POST['code']: the pass code to select winner
        :param POST['test']: '1' if testing
    """
    r = {}

    test = False
    if request.POST.get('test','0') == '1':
        test = True 

    if request.POST.get('code','000') == 'ch00seW199Er':
        # check the number of people who transacted today
        d = date.today() #-timedelta(30)
        win_begin = datetime(year=d.year, month=d.month, day=d.day,
                hour=0, minute=0, second=0)
        win_end = datetime(year=d.year, month=d.month, day=d.day,
                hour=23, minute=59, second=59)

        # check the number of people who logged in today
        logged_in = Event.objects.filter(action=Event.LOGIN,timestamp__gt=win_begin, timestamp__lt=win_end).values('user').distinct()
        logger.debug("People that used: %s"%str(logged_in))
        
        # check the number of people who saw the feed today
        feed_viewed = FeedEvent.objects.filter(action=FeedEvent.FEED,timestamp__gt=win_begin, timestamp__lt=win_end).values('user').distinct()
        logger.debug("People that used the feed: %s"%str(feed_viewed))

        # check the number of people who have reviewed
        reviewed = Receipt.objects.filter(last_update__lt=win_end, last_update__gt=win_begin).values_list("txn__user", flat=True).distinct()
        logger.debug("People that reviewed: %s"%str(reviewed))

        # exclude previous winners
        prev_winners = Winner.objects.all().values('user__id')
        #.exclude(id__in=prev_winners)

        r_start = Q(techcashtransaction__receipt__last_update__gt=win_begin)
        r_end = Q(techcashtransaction__receipt__last_update__lt=win_end)
        t_start = Q(techcashtransaction__timestamp__gt=win_begin)
        t_end = Q(techcashtransaction__timestamp__lt=win_end)
        f_viewed = Q(id__in=feed_viewed)

        users_today = OTNUser.objects.filter(f_viewed | (r_start & r_end) | (t_start & t_end)).order_by('id').distinct()
        logger.debug("People that made txns (%d): %s"%(users_today.count(), str(users_today)))

        # randomly select
        winner_id=-1
        if users_today.count() == 0:
            return JSONHttpResponse({'result':'0'})
        elif users_today.count() == 1:
            winner_id = users_today[0].id
            winner = users_today[0]
        else:
            # exclude Kwan, John McDonald, Dawei Shen, Alter Yod
            exclude_list=[-1, 2, 3, 5]
            while winner_id in exclude_list:
                draw = randint(0,users_today.count()-1)
                winner = users_today[draw] 
                winner_id = winner.id
        
        if not test:
            # save to DB
            win_prize = Winner(user=winner, prize="$5 TechCASH")
            win_prize.save()
            
            # if called the day after
            win_prize.timestamp = d 
            win_prize.save()

            # email mitcard to credit from DIGRECPT1 to MIT ID
            msg = "%s is today's OTN/MealTime winner!\n\nPlease transfer $5 from DIGRECPT1 to %s.\n\n-kwan"%(winner.name, winner.mit_id)
            send_mail('OTN Winner', msg, '*****@*****.**', ['*****@*****.**'], fail_silently=False) 

            # email winner
            msg = "You are today's MealTime winner!\n\nYou will receive $5 credit in your TechCASH account.\n\n-kwan"
            send_mail('OTN Winner', msg, '*****@*****.**', [winner.my_email, '*****@*****.**'], fail_silently=False) 

        r['result'] = {'name':winner.name, 'id':"%d"%winner.id}
    else:
        r['result'] = '-1'

    return JSONHttpResponse(r)
Esempio n. 5
0
            """
            if not Winner.objects.filter(user=u).exists():
                w = Winner(user=u, prize="$50 Legal's Gift Certificate")
                w.save()
                send_mail("Referral Award $50 Legal's gift certificate", msg%u.name.split(" ")[0], 'Digital Menu <*****@*****.**>', [u.my_email], fail_silently=False) 
                print "Sent email to: %s"%u.my_email
            """
            refs.append((u.name,u.id, referrals.count()))

print refs

#winners = [27, 40, 29, 25, 43, 81, 133]
#winners = [79, 91, 166]
#winners = [92]
#winners = [257]
#winners = [168, 109]
#winners = [148] + Sang Kim + Yod
#winners = [137] Tracey
#winners = [306] Tamiko
#winners = [305] Matt (Need to send out)
winners = []
for wid in winners:
    u = OTNUser.objects.get(id=wid)
    w = Winner(user=u, prize="$50 Legal's Gift Certificate")
    w.save()
    send_mail("Referral Award $50 Legal's gift certificate", msg%u.name.split(" ")[0], 'Digital Menu <*****@*****.**>', [u.my_email], fail_silently=False) 
    print "Sent email to: %s"%u.my_email