Esempio n. 1
0
def setData():
    db = firebase.database()
    storage = firebase.storage()


    with open(SCORE_PATH, 'r') as f:
        score_data = json.load(f)

    # store data on firebase
    for name in score_data:
        db.child("players").child(name).child("name").set(name)
        db.child("players").child(name).child("name").set(name)
        db.child("players").child(name).child("score").set(score_data[name]["score"])
        db.child("players").child(name).child("avatarFilePath").set(score_data[name]["avatarFilePath"])


    # upload image and delete all local avatar image
    for file in os.listdir(IMAGE_DIR):
        storage.child("images")
        storage.child(file).put(IMAGE_DIR+file)
        os.remove(IMAGE_DIR+file)

    # empty local json file
    with open(SCORE_PATH, 'w') as f:
       f.write("{}")
Esempio n. 2
0
cache = SimpleCache()
app = Flask(__name__, template_folder='Templates')
app.secret_key = 'super secret key'
now = datetime.datetime.now()
#GR_KEY = 'hCgnomVsyFTNe73zLW7Q'
GR_KEY = 'HeN7az3JVPSRALsq6Jxpfg'
#GR_SECRET = 'SR9wYYUa5tzHx0vQrVZEDghDoMBjtkItshkYwVkCcQ'
GR_SECRET = 'J2qXu5Q1XSvSYusFWxEEAXeqNr72fEScyzhDk2Gx8'
GR_ACCESS_TOKEN = app.secret_key
GR_ACCESS_TOKEN_SECRET = app.secret_key

gc = client.GoodreadsClient(GR_KEY, GR_SECRET)

auth = firebase.auth()
db = firebase.database()
db_storage = firebase.storage()


@app.route('/')
def index():
    return render_template('home.html')


@app.route('/about')
def about():
    return render_template('about.html')


def is_logged_in(f):
    @wraps(f)
Esempio n. 3
0
def leader_board():
    # set the data, before displaying
    setData()
    pygame.init()
    pygame.mixer.init()
    font = pygame.font.SysFont("arial", 24)
    font_height = font.get_linesize()
    board_screen = pygame.display.set_mode(Display_Size, pygame.DOUBLEBUF, 32)
    pygame.display.set_caption("Welcome To Snake")
    background = 'data/bg.jpg'
    bg = pygame.image.load(background).convert_alpha()

    # load firebase
    db = firebase.database()
    storage = firebase.storage()
    # display the top 20 players with highest scores
    users_by_score = db.child("players").get()

    with open(SCORE_PATH, 'r') as f:
        score_data = json.load(f)

    while True:
        board_screen.fill((0, 0, 0))
        board_screen.blit(bg, (0, 0))
        show_message(board_screen, 'Welcome to leaderBoard, press F to return',
                     blackColour, 30, 250, 200)

        # the position of the first displaying data
        x = 250
        y = 520

        # display avatar, name and score for each player

        top_users = []
        for user in users_by_score.each():
            player_name = user.val()['name']
            player_score = user.val()['score']
            image_url = storage.child(
                user.val()["avatarFilePath"]).get_url(None)
            top_users.append((player_name, player_score, image_url))
        top_users.sort(key=lambda x: x[1], reverse=False)

        top_users = top_users[:5]

        for user in top_users:
            player_name, player_score, image_url = user[0], user[1], user[2]
            response = requests.get(image_url)
            image_file = io.BytesIO(response.content)
            avatar_img = pygame.image.load(image_file)
            board_screen.blit(avatar_img, (x, y))
            show_message(board_screen,
                         player_name + ":   " + str(player_score), blackColour,
                         25, x + 60, y + 20)
            y -= 70
            if (y < 240):
                y = 520
                x -= 220

        # check input
        pygame.display.update()

        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_f:
                    menu_loop()
                if event.key == pygame.K_ESCAPE:
                    pygame.event.post(pygame.event.Event(pygame.QUIT))

            if event.type == pygame.QUIT:
                quitHelper()
Esempio n. 4
0
def leader_board():
    # set the data, before displaying
    setData()
    pygame.init()
    pygame.mixer.init()
    font = pygame.font.SysFont("arial", 24)
    font_height = font.get_linesize()
    board_screen = pygame.display.set_mode(Display_Size, pygame.DOUBLEBUF, 32)
    pygame.display.set_caption("Welcome To Snake")
    background = 'data/bg.jpg'
    bg = pygame.image.load(background).convert_alpha()

    # load firebase
    db = firebase.database()
    storage = firebase.storage()
    # display the top 20 players with highest scores
    users_by_score = db.child("players").order_by_child("score").limit_to_last(
        20).get().val()
    print(users_by_score)
    # with open(SCORE_PATH, 'r') as f:
    #     score_data = json.load(f)

    back_button = Button()

    while True:
        board_screen.fill((0, 0, 0))
        board_screen.blit(bg, (0, 0))

        back_button.create_button(screen, whiteColour, 30, 100, 100, 50, 60,
                                  "Back", steelBlue)

        # the position of the first displaying data (800,520) bottom-left to top-right
        x = 720
        y = 520

        # display avatar, name and score for each player

        for playerName in users_by_score:
            player = users_by_score[playerName]

            # avatar_img = pygame.image.load(player["avatarFilePath"])

            image_url = storage.child(player["avatarFilePath"]).get_url(None)
            response = requests.get(image_url)
            image_file = io.BytesIO(response.content)
            avatar_img = pygame.image.load(image_file)
            board_screen.blit(avatar_img, (x, y))
            show_message(board_screen,
                         playerName + ":   " + str(player["score"]),
                         blackColour, 25, x + 60, y + 20)
            y -= 70
            if (y < 240):
                y = 520
                x -= 220

        # check input
        pygame.display.update()

        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_f:
                    menu_loop()
                if event.key == pygame.K_ESCAPE:
                    pygame.event.post(pygame.event.Event(pygame.QUIT))
            if event.type == pygame.QUIT:
                quitHelper()
            elif event.type == pygame.MOUSEBUTTONUP:
                if back_button.pressed(pygame.mouse.get_pos()):
                    menu_loop()