def test_select_winners_without_weights(mock_separate_prizes, given_number_of_winners, expected_number_of_winners): participants = mock_participant(test_list_of_participants_no_weights) lottery = Lottery(mock_separate_prizes, participants) winners = lottery.select_winners(given_number_of_winners) assert len(winners) == expected_number_of_winners
def find_winning_number(self, number): w = Lottery() x = w.get_extracted_page(2013, 12) try: return (drawing for drawing in x if drawing["number"] == number).next() except: return False
def main(): lottery = Lottery() if not lottery.read_config(): print("Can't init script, exiting now") return print('Init done, starting lottery') scheduler = sched.scheduler(time.time, time.sleep) def check_for_new_issues(): print('Checking for new pull requests at', time.ctime()) all_issues = list(issues.fetch_opened_pull_requests()) issues_by_teams = {} for team_name in config.teams: try: team_issues = list( issues.filter_issues_for_team(all_issues, team_name)) issues_by_teams[team_name] = team_issues all_issues = list( filter(lambda i: i not in team_issues, all_issues)) except requests.exceptions.RequestException: pass for team_name in issues_by_teams: team_issues = issues_by_teams[team_name] print('Team', team_name, 'has:', list(map(lambda i: (i.repository, i.number), team_issues))) for issue in issues.filter_issues_to_be_assigned(team_issues): try: if issue.assignee is None: lottery.select_assignee(issue, team_name) else: lottery.increase_reviewer_score(issue.assignee) issue.add_in_review_label() update_result = issue.update_on_server() print('Added for review:', issue.repository, issue.number, issue.assignee, update_result) except requests.exceptions.RequestException: pass for issue in issues.filter_issues_to_be_checked_for_completed_review( team_issues): if comments.issue_contains_review_done_comment(issue): issue.add_reviewed_label() try: update_result = issue.update_on_server() print('Review completed:', issue.repository, issue.number, issue.assignee, update_result) except requests.exceptions.RequestException: pass if not config.single_shot: scheduler.enter(config.interval_between_checks_in_seconds, 1, check_for_new_issues) check_for_new_issues() if not config.single_shot: scheduler.run()
def __init__(self, data_file, sub_table=0): """ """ self.num_dozens = 25 self.doz_by_raffle = 15 self.dozen_dozens = 2 self.pickle_file = "facil.pickle" Lottery.__init__(self, data_file, sub_table=0)
def __init__(self, data_file, sub_table = 0): """ """ self.num_dozens = 80 self.dozen_dozens = 8 self.doz_by_raffle = 5 self.pickle_file = 'quina.pickle' Lottery.__init__(self, data_file, sub_table = 0)
def main(): lottery = Lottery() if not lottery.read_config(): print("Can't init script, exiting now") return print('Init done, starting lottery') scheduler = sched.scheduler(time.time, time.sleep) def check_for_new_issues(): print('Checking for new pull requests at', time.ctime()) all_issues = list(issues.fetch_opened_pull_requests()) issues_by_teams = {} for team_name in config.teams: try: team_issues = list(issues.filter_issues_for_team(all_issues, team_name)) issues_by_teams[team_name] = team_issues all_issues = list(filter(lambda i: i not in team_issues, all_issues)) except requests.exceptions.RequestException: pass for team_name in issues_by_teams: team_issues = issues_by_teams[team_name] print ('Team', team_name, 'has:', list(map(lambda i: (i.repository, i.number) , team_issues))) for issue in issues.filter_issues_to_be_assigned(team_issues): try: if issue.assignee is None: lottery.select_assignee(issue, team_name) else: lottery.increase_reviewer_score(issue.assignee) issue.add_in_review_label() update_result = issue.update_on_server() print('Added for review:', issue.repository, issue.number, issue.assignee, update_result) except requests.exceptions.RequestException: pass for issue in issues.filter_issues_to_be_checked_for_completed_review(team_issues): if comments.issue_contains_review_done_comment(issue): issue.add_reviewed_label() try: update_result = issue.update_on_server() print('Review completed:', issue.repository, issue.number, issue.assignee, update_result) except requests.exceptions.RequestException: pass if not config.single_shot: scheduler.enter(config.interval_between_checks_in_seconds, 1, check_for_new_issues) check_for_new_issues() if not config.single_shot: scheduler.run()
def __init__(self, data_file, sub_table = 0): """ """ self.num_dozens = 80 self.doz_by_raffle = 5 self.updated = ctime(os.path.getmtime(data_file)) Lottery.__init__(self) if os.path.exists('data/quina.pickle'): self.updated = os.path.getmtime(data_file) if os.path.getmtime('data/quina.pickle') > os.path.getmtime(data_file): try: data_bin = open('../data/quina.pickle', 'rb') self.all_content = pickle.load(data_bin) if sub_table > 0: self.all_content = self.all_content[:sub_table] except IOError, err: print ("File error: " + str(err)) else: data_bin.close()
def main(file_name, file_format, lottery_template, output_file): participants = Participants() participants.read_data_from_file(file_name, file_format) prizes = Prizes(specify_lottery_template(lottery_template)) prizes.load_prize_data() lottery = Lottery(prizes, participants) lottery.award_prizes() lottery.save_awarded_prizes_data_to_json_file(output_file)
def test_select_winners_with_weights(mock_separate_prizes): participants = mock_participant(test_list_of_participants_weights) lottery = Lottery(mock_separate_prizes, participants) winners = lottery.select_winners(2) assert len(winners) == 2 assert { "id": "1", "first_name": "Tanny", "last_name": "Bransgrove", "weight": "1" } in winners assert { "id": "2", "first_name": "Delila", "last_name": "Spriggs", "weight": "1" } in winners assert { "id": "3", "first_name": "Sigmund", "last_name": "Saw", "weight": "0" } not in winners
def run(): # Parse the options. options = parser.parse_args() # Print a list of games & exist (if applicable) if options.list: print("\nYou may use the following with the -g or --game flag:") for game, title in Lottery.game_data.items(): print("* {0} -- {1}.".format(game, title)) sys.exit() # The full list of games. games = Lottery.games() if options.game and options.game not in games: sys.stderr.write("\n{0} is not a valid game.\n".format(options.game)) sys.exit(1) elif options.game: games = [options.game] # Just play a single game # Prints randomly generated numbers for the selected TN Lottery game print("\n" + "+" * 50) game_name = options.game if options.game else "TN Lottery" print("{0} Numbers!".format(game_name)) print("-" * 50) for n in range(options.number): lottery = Lottery() if "powerball" in games: print(lottery.print_powerball()) if "megamillions" in games: print(lottery.print_mega_millions()) if "hotlotto" in games: print(lottery.print_hot_lotto_sizzler()) if "tncash" in games: print(lottery.print_tn_cash()) if "cash4" in games: print(lottery.print_cash_four()) if "cash3" in games: print(lottery.print_cash_three()) if options.number > 1 and len(games) > 1: print("-" * 50) print("\nGood Luck! (you'll need it)\n\n")
def run(): locale.setlocale(locale.LC_ALL, '') # Assume US because that's where TN is. lotto = Lottery() spent = 0 # how much we've spent trials = 0 # Number of time's we've bought a ticket won = False while not won: # Generate a ticket & a drawing won, cost = play(lotto) spent += cost trials += 1 # Print some info every year if trials % YEARS == 0: report(trials, spent, won) report(trials, spent, won)
import sys from PyQt5.QtWidgets import QApplication from lottery import Lottery if __name__ == '__main__': app = QApplication(sys.argv) lo = Lottery() lo.show() sys.exit(app.exec_())
def menu(): user = register() game = Lottery() game.gather_choices()
from lottery import Lottery # variable from Lottery class and define winning numbers lotto = Lottery() lotto.winning_numbers = lotto.draw_numbers() # define my ticket variable and count, to track how many tickets bought my_ticket = lotto.draw_numbers() count = 1 # Introduce rules for lotto jackpot print(f"To win the jackpot you need to match {lotto.numbers_to_match} numbers ranging from {lotto.numbers_range[0]} to {lotto.numbers_range[-1]}") if lotto.bonus_to_match: print(f"You also need to match {lotto.bonus_to_match} bonus number(s) ranging from {lotto.bonus_range[0]} to {lotto.bonus_range[-1]}\n") # Define maximum number of tickets to buy max_tickets = input("How many tickets would you like to buy?\n") while max_tickets.isdigit() == False: max_tickets = input("Sorry, that is not a number!\nHow many tickets would you like to buy?\n") # Keep buying more tickets and incrementing count until we get the winning numbers while my_ticket != lotto.winning_numbers and count < int(max_tickets): my_ticket = lotto.draw_numbers() count += 1 print(f"{count} {my_ticket}") # Exit statement when we failed to get a winning ticket if count == int(max_tickets): print(f"\nSorry! You bought {count} tickets, but still didn't win the jackpot!!") print("Better luck next time :-)")
class TestLottery(unittest.TestCase): def setUp(self): self.client = Redis(decode_responses=True) self.client.flushdb() self.lottery = Lottery(self.client, "test-lottery") def test_add_player(self): self.assertEqual(self.lottery.get_all_players(), set()) self.lottery.add_player("peter") self.assertNotEqual(self.lottery.get_all_players(), set()) def test_get_all_players(self): self.assertEqual(self.lottery.get_all_players(), set()) self.lottery.add_player("peter") self.assertEqual(self.lottery.get_all_players(), {"peter"}) def test_player_count(self): self.assertEqual(self.lottery.player_count(), 0) self.lottery.add_player("peter") self.assertEqual(self.lottery.player_count(), 1) def test_draw(self): player_list = {"peter", "jack", "tom"} for player in player_list: self.lottery.add_player(player) # 确保获奖者的数量跟我们要求的一致 self.assertEqual(len(self.lottery.draw(1)), 1) self.assertEqual(len(self.lottery.draw(2)), 2) # 确保获奖者来源于参与抽奖的玩家 winner = self.lottery.draw(1)[0] self.assertTrue(winner in player_list)
def setUp(self): self.client = Redis(decode_responses=True) self.client.flushdb() self.lottery = Lottery(self.client, "test-lottery")
def test_get_single_page(self): w = Lottery() assert 'WINNING NUMBERS' in w.get_page(2013, 12)