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 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 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 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)
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 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 setUp(self): self.client = Redis(decode_responses=True) self.client.flushdb() self.lottery = Lottery(self.client, "test-lottery")
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 :-)")