コード例 #1
0
def scrape_game(single_game_books, web_driver, index):
	"""Function that scrapes a single beautifulsoup "game" object.
	Arguments: beautifulsoup object, selenium webdriver, and index for which game 
	in the given league on the given day (as provided by the original URL).
	Returns: Game object cointaining teams and dataframe of moneylines and associated sportsbooks.
	"""

	home = away = ''
	teams = single_game_books.findAll('span',{'class':'_3O1Gx'})
	home = teams[0].text
	away = teams[1].text


	right_button = web_driver.find_element_by_class_name('sbr-icon-chevron-right')
	end_of_books = False
	frame = 0 # Track which SBR frame the selenium driver is currently on.

	# Instantiate pandas dataframe that will house all lines for all books for this specific game.
	game_df = pd.DataFrame(columns = ["BookID", "Home_ML", "Away_ML"])

	while(end_of_books == False):
		# Step deeper into HTML.
		unique_books = single_game_books.findAll('section', {'class':'_2NFWr'})

		# Store each book's lines for this game.
		game_df = game_df.append(books_to_dataframe(unique_books, frame), ignore_index = True)
		try:
			right_button.click()

			# NEED to include sleep to allow the time for the page to load before scraping it.
			time.sleep(2)
			frame += 1

			# Scrape new frame.
			page_soup2 = soup(web_driver.execute_script("return document.body.innerHTML"), "html.parser")
			odds_container2 = page_soup2.find('div',{'id':'bettingOddsGridContainer'})
			games = odds_container2.findAll('div',{'class':'_3A-gC'})
			single_game_books = games[index]
		except Exception as e:
			# Reached end of sports books.
			end_of_books = True


	# Now click back as far left as possible for the next game.
	left_button = web_driver.find_element_by_class_name('sbr-icon-chevron-left')
	while(end_of_books == True):
		try:
			left_button.click()
		except Exception as e:
			# Reached end of sports books.
			end_of_books = False

	# "Game" object idenitfying home team, away team, and a dataframe with every book and every line
	newGame = game.Game(home, away, game_df)
	return newGame
コード例 #2
0
def main():
    try:
        game_file = open("counting_game.txt", 'x')
        header = ["Player", "Levels", "Time", "Score"]
        for info in header:
            game_file.write("{0:-^10}".format(info) + ' ')
        game_file.write("\n")
        game_file.close()
    except FileExistsError:
        pass
    game_file = open("counting_game.txt", 'a')
    try:
        game = game_class.Game(sys.argv[1], sys.argv[2])
    except IndexError:
        game = game_class.Game()
    game.start_game()
    for info in game.player_information:
        try:
            game_file.write("{0:^10}".format(int(info)) + ' ')
        except ValueError:
            game_file.write("{0:^10}".format(info) + ' ')
    game_file.write("\n")
    game_file.close()
コード例 #3
0
ファイル: Main.py プロジェクト: Rooster202/Rorben_INC
import pygame
import game_class

pygame.init()

res = (1080, 720)
screen = pygame.display.set_mode(res)
game = game_class.Game(screen)

done = False
while not done:
    done = game.events()
    game.draw_screen()
    pygame.display.flip()

pygame.quit()
コード例 #4
0
ファイル: main.py プロジェクト: collinkennedy/BattleShip
from typing import Iterable, Set, Tuple, Dict, List
import sys
from board_class import Board
from ship_class import Ship
import game_class

if __name__ == '__main__':
    a = 5
    b = 6
    if len(sys.argv) > 1:
        with open(sys.argv[1]) as file:
            lines = file.readlines()
            for i, line in enumerate(lines):
                if i == 0:
                    dimStr = line
                    a, b = dimStr.split(" ")
    game = game_class.Game(int(a), int(b), '*')
    game.play()
コード例 #5
0
import time as t
import game_class

# Menu Driven Arithmetic Game. Play as you like!

while True:
    os.system('clear')
    print("                     --------MENU--------  \n")
    print("                  1. Level 1")
    print("                  2. Level 2")
    print("                  3. Level 3")
    print("                  4. Exit this Hell!\n")
    choice = input("                  Enter your choice : ")

    if choice == '1':
        new_game = game_class.Game(3, 1)
        os.system('clear')
        new_game.lets_play()
        new_game.declare_results()
        print("                    Returning back to menu", end='')
        for j in range(3):
            print('.', end='', flush=True)
            t.sleep(1.0)

    elif choice == '2':
        new_game = game_class.Game(4, 2)
        os.system('clear')
        new_game.lets_play()
        new_game.declare_results()
        print("                    Returning back to menu", end='')
        for j in range(3):
コード例 #6
0
if __name__ == "__main__":
    # game window settings
    window = tkinter.Tk()
    window.title("Yatzy")
    window.geometry("500x600")
    window.resizable(0,0)
    window.lift()
    window.attributes("-topmost", True)
    
    # asks how many player will be playing
    nro_players = tkinter.simpledialog.askinteger("Players", "How many players?", parent=window)
    
    # asks player names and makes list of players (Player class)
    players = []
    i = 0
    while i<nro_players:
        nro = i+1
        text = "Player "+ str(nro) +" name?"
        name = tkinter.simpledialog.askstring("Player name", text, parent=window)
        player = player_class.Player(name)
        players.append(player)
        i += 1

    # initializes gui and game-logic with given players
    gui = gui_class.GUI(window, players)
    game = game_class.Game(gui, players)
    gui.add_game_logic(game)
    
    game.start()
    
    window.mainloop()