Ejemplo n.º 1
0
    def test_losing_bet(self):
        bet = mommy.make(Bet, better=Better.objects.all()[0], has_won='Pending',
                         bet_type='3', stake=10.0, week=Week.objects.get(id=1))
        mommy.make(BetItem, bet=bet, song=Song.objects.get(id=1), choice='1', odd=2.0)

        check_if_won.check_if_won(Week.objects.get(id=1), Week.objects.get(id=2))

        self.assertEqual(Better.objects.all()[0].points, 100)
Ejemplo n.º 2
0
    def __init__(self, url, checked, check_won=False):
        self.url = url
        self.checked = checked

        sock = urllib.urlopen(url)
        htmlSource = sock.read()
        sock.close()
        soup = BeautifulSoup(htmlSource)
        song_name = []

        week_time = time.strptime(soup.time.text, "%B %d, %Y")
        dt = datetime.fromtimestamp((time.mktime(week_time)))
        this_week = Week.objects.get_or_create(date=dt)[0]

        for i in range(1, 101):
            article = soup.find(class_="chart-row--{}".format(i))
            article_secondary = article.find(id="chart-row-{}-secondary".format(i))
            artist_name = article.select(".chart-row__title > h3")[0].getText().strip()
            song_name = article.select(".chart-row__title > h2")[0].getText().strip()

            artist = Artist.objects.get_or_create(name=artist_name)[0]
            song = Song.objects.get_or_create(name=song_name, artist=artist,
                                              artist_name=artist_name)[0]
            position = Position.objects.get_or_create(week=this_week, song=song,
                                                      position=i)[0]

            awards = article_secondary.find(class_="chart-row__awards")
            if awards:
                for award in awards.findAll('li'):
                    performance_gain = award.find(class_="fa-dot-circle-o")
                    if performance_gain:
                        position.performance_gain = True
                        position.save()

                    airplay_gain = award.find(class_="fa-microphone")
                    if airplay_gain:
                        this_week.airplay_gain = i
                    stream_gain = award.find(class_="fa-signal")
                    if stream_gain:
                        this_week.stream_gain = i
                    digital_gain = award.find(class_="fa-usd")
                    if digital_gain:
                        this_week.digital_gain = i
                    highest_ranking_debut = award.find(class_="fa-angle-double-up")
                    if highest_ranking_debut:
                        this_week.highest_ranking_debut = i

        this_week.save()
        if check_won:
            last_week = Week.objects.all().order_by('-date')[1]

        if check_won and this_week != last_week and checked is False:
            check_if_won.check_if_won(last_week, this_week)