Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 48 lines (44 sloc) 1.385 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
import sqlite3
import os.path

def make_db():
    if not os.path.exists('leaderboard.db'):
     conn = sqlite3.connect('leaderboard.db')
        cur = conn.cursor()
        cur.execute('''CREATE TABLE leaders
(Name Text, Score Integer, GameDate Date)
''')
        conn.commit()
        conn.close()
    else: pass

def insert_db(player, score, game_date):
    conn = sqlite3.connect('leaderboard.db')
    cur = conn.cursor()
    cur.execute('''
INSERT INTO leaders VALUES (?,?,?);
''', (player, score, game_date))
    conn.commit()
    conn.close()

def results_db():
    conn = sqlite3.connect('leaderboard.db')
    cur = conn.cursor()
    cur.execute('''
SELECT SUBSTR(name,1,20) AS name, score, strftime('%m/%d/%Y', gamedate)
FROM leaders
ORDER BY score ASC
LIMIT 20;
''')
    rows = cur.fetchall()
    print '''\n\n
_ _
| | | |
| | ___ __ _ __| | ___ _ __ ___
| | / _ \/ _` |/ _` |/ _ \ '__/ __|
| |___| __/ (_| | (_| | __/ | \__ \\
\_____/\___|\__,_|\__,_|\___|_| |___/
'''
    print '\n\nNAME MOVES DATE'
    print '____________________________________________________\n'
    for row in rows:
        print '%-20s %-10s %-30s' % (row[0], str(row[1]), row[2])
    print '\n\n\n'

    conn.close()
Something went wrong with that request. Please try again.