· 6 years ago · Jul 30, 2019, 12:11 PM
1# Created By: Ryan Watson
2# Date Created: 30/7/19
3# Version: 1.1
4# Program is to take input from the user and put it into a database.
5
6import sqlite3
7import time
8import datetime
9
10# Opening the connection to the db.
11conn = sqlite3.connect('test_r6s_stats.db')
12c = conn.cursor()
13
14def create_table_casual():
15 '''Creating the table for the casual matches'''
16 c.execute("CREATE TABLE IF NOT EXISTS casualGameStats(Date TEXT, Time TEXT, Map TEXT, Gamemode TEXT, Kills INTEGER, Assists INTEGER, Deaths INTEGER, Final_Score TEXT, Win_Or_Loss TEXT, Num_Of_Friends INTEGER)")
17
18def create_table_ranked():
19 '''Creating the table for the ranked matches'''
20 c.execute("CREATE TABLE IF NOT EXISTS rankedGameStats(Date TEXT, Time TEXT, Map TEXT, Gamemode TEXT, Kills INTEGER, Assists INTEGER, Deaths INTEGER, Final_Score TEXT, Win_Or_Loss TEXT, Num_Of_Friends INTEGER)")
21
22def insert_data():
23 '''it asks the user to input all their data from the causal games so the program can insert it into the db.'''
24 quit_out = "n"
25 enter_again = "999"
26 while enter_again != quit_out:
27 game_type = input("Did you play ranked or casual? ").capitalize()
28 if game_type != "Ranked" and game_type != "Casual":
29 print("Please enter either Ranked or Casual!")
30 else:
31 game_map = input("What map did you play on? ").capitalize()
32 gamemode = input("What gamemode was it? ").capitalize()
33 kill_amount = int(input("How many kills did you get? "))
34 assist_amount = int(input("How many assists did you get? "))
35 death_amount = int(input("How many times did you die? "))
36 final_score = input("What was the final score? ")
37 win_or_loss = input("Did you win or lose? ").capitalize()
38 num_of_friends = int(input("How much friends were you playing with? "))
39
40 local_time = time.localtime()
41 time_string = time.strftime("%H:%M:%S")
42 date_string = time.strftime("%d/%m/%y")
43
44 if game_type == "Ranked":
45 c.execute("INSERT INTO rankedGameStats (Date, Time, Map, Gamemode, Kills, Assists, Deaths, Final_Score, Win_Or_loss, Num_Of_Friends) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (date_string, time_string, game_map, gamemode, kill_amount, assist_amount, death_amount, final_score, win_or_loss, num_of_friends))
46 print("Your data has been saved in the ranked table!")
47 conn.commit()
48
49 elif game_type == "Casual":
50 c.execute("INSERT INTO casualGameStats (Date, Time, Map, Gamemode, Kills, Assists, Deaths, Final_Score, Win_Or_loss, Num_Of_Friends) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (date_string, time_string, game_map, gamemode, kill_amount, assist_amount, death_amount, final_score, win_or_loss, num_of_friends))
51 print("Your data has been saved in the casual table!")
52 conn.commit()
53
54 enter_again = "999"
55 while enter_again != "n" and enter_again != "y":
56 enter_again = input("Do you want to enter another games stats? (y/n) ").lower()
57
58 if enter_again == "n":
59 enter_again = quit_out
60
61 elif enter_again == "y":
62 enter_again = enter_again
63
64 else:
65 print('Please enter "y" or "n"!')
66
67# Calling the functions
68#create_table_casual()
69#create_table_ranked()
70insert_data()
71
72# Closing the connection to the database.
73c.close
74conn.close()
75
76# To do later: Create a table that will store the data and give me my kd and and win/loss for the specified amount of time.