· 9 years ago · Nov 29, 2016, 02:08 PM
1#! /usr/local/python
2
3import sqlite3 as s3
4
5class Scores:
6 def __init__(self, list):
7 self.year = int(list[0])
8 self.winner = list[3]
9 self.wscore = int(list[4])
10 self.loser = list[5]
11 try:
12 self.lscore = int(list[6])
13 self.ots = 0
14 except ValueError:
15 lscore_ot_list = str.split(list[6])
16 ot_num_ornot = lscore_ot_list[1][1]
17 self.lscore = int(lscore_ot_list[0])
18 self.ots = int(ot_num_ornot) if (str.isdigit(ot_num_ornot)) else 1
19 def loadMyScores(self):
20 cli = s3.connect('AK_BALL.db')
21 c = cli.cursor()
22 toEx1 = '''CREATE TABLE IF NOT EXISTS CHAMPIONSHIPS_AK (YEAR INT, WINNER TEXT, WSCORE INT, LOSER TEXT, LSCORE INT, OTS INT)'''
23 toEx2 = "INSERT INTO CHAMPIONSHIPS_AK VALUES (?,?,?,?,?,?)"
24 c.execute(toEx1)
25 c.execute(toEx2, self.makeMySeq())
26 cli.commit()
27 cli.close()
28 def makeMySeq(self):
29 return (self.year, self.winner, self.wscore, self.loser, self.lscore, self.ots)
30
31def breakUpList (inty, listy):
32 acc = 1
33 bigList = []
34 while (acc <= (len(listy) / inty)):
35 county = inty * (acc - 1)
36 max = inty * acc
37 addList = []
38 while (county < max):
39 try:
40 addList.append(listy[county])
41 county += 1
42 except IndexError:
43 break
44 bigList.append(addList)
45 acc += 1
46 return bigList
47
48def interpretScores():
49 inFile = open("BBallData.txt", "r")
50 inFile.seek(0)
51 fiStri = inFile.read()
52 fiStriLi = fiStri.splitlines()
53 lineez = breakUpList(7, fiStriLi)
54 mS = map((lambda l: Scores(l)), lineez)
55 inFile.close()
56 return mS
57
58def eO(listy, i, into):
59 acc = 1
60 ssll = []
61 while (acc * i <= len(listy)):
62 c = (acc - 1) * i
63 while (c < (acc * i)):
64 if ((c % i) == into):
65 ssll.append(listy[c])
66 c += 1
67 acc += 1
68 return ssll
69
70def addRecordsScores(listOfScores):
71 for x in listOfScores:
72 x.loadMyScores()
73
74if __name__ == "__main__":
75 addRecordsScores(interpretScores())