예제 #1
0
파일: manage.py 프로젝트: pmrowla/p101stat
def update_dailies():
    """Update daily rank information."""
    # Do this once to get consistent results in the event that the day changes
    # while we are running this function
    today = datetime.now().date()
    for i, idol in enumerate(Idol.query.order_by(desc(Idol.vote_percentage)).all()):
        daily = DailyHistory.query.filter(and_(DailyHistory.idol == idol, DailyHistory.date == today)).first()
        if daily:
            daily.update(vote_percentage=idol.vote_percentage, rank=i + 1)
        else:
            daily = DailyHistory.create(idol=idol, date=today, vote_percentage=idol.vote_percentage, rank=i + 1)
        idol.update(prev_rank=daily.rank, prev_vote_percentage=daily.vote_percentage)
    print('Successfully updated dailies')
예제 #2
0
 def test_dailies(self):
     """Add a daily to a user."""
     idol = IdolFactory()
     daily = DailyHistory(idol=idol, date=dt.datetime.utcnow().date())
     daily.save()
     assert daily in idol.dailies
예제 #3
0
 def test_dailies(self):
     """Add a daily to a user."""
     idol = IdolFactory()
     daily = DailyHistory(idol=idol, date=dt.datetime.utcnow().date())
     daily.save()
     assert daily in idol.dailies