Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improves cleanup #126

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions trapp/check_games.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ def checkGames(self):
[self.reviewCompetition(record['CompetitionID'], startYear)
for record
in competitions]

c.disconnectDB()
del c
13 changes: 12 additions & 1 deletion trapp/compile_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ def assemblePlusMinus(self, record):
# Transfer impact information to record
record = dict(record, **impact[0])

ge.disconnectDB()
del ge

return record

def assembleStatLine(self, record):
Expand Down Expand Up @@ -82,12 +85,18 @@ def doCompile(self):
# Trying a delay to prevent buffer space problems
time.sleep(0.01)

gs.disconnectDB()
del gs

return True

def getAppearanceList(self):
gm = GameMinute()
gm.connectDB()
return gm.lookupIDlistByYear()
result = gm.lookupIDlistByYear()
gm.disconnectDB()
del gm
return result

def getEventSummary(self, item):
ge = GameEvent()
Expand All @@ -96,4 +105,6 @@ def getEventSummary(self, item):
if(len(temp) == 0):
temp = [{'Goals': 0, 'Ast': 0}]
item = dict(list(item.items()) + list(temp[0].items()))
ge.disconnectDB()
del ge
return item
1 change: 1 addition & 0 deletions trapp/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def connect(self):
def disconnect(self):
self.cursor.close()
self.cnx.close()
del self.cnx

def convertDate(self, date):
# This converts a python date object into a MySQL-format date string
Expand Down
3 changes: 3 additions & 0 deletions trapp/import_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ def importRecord(self, record):
# Something(s) found, so we skip
self.processMissingRecord(found, len(found))

g.disconnectDB()
del g

return True
9 changes: 9 additions & 0 deletions trapp/import_goal.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ def correctValues(self):
# Log the corrected record for later inspection
self.log.message(' Outcome:\n ' + str(record))

g.disconnectDB()
del g

return True

def disambiguatePlayers(self, record, result):
Expand Down Expand Up @@ -126,6 +129,9 @@ def importRecord(self, record):
e.saveDict(item, self.log)
self.imported += 1

e.disconnectDB()
del e

return True

def lookupPlayerID(self, event):
Expand All @@ -139,6 +145,9 @@ def lookupPlayerID(self, event):

PlayerID = p.lookupIDbyGoal(event, self.log)

p.disconnectDB()
del p

# Swap team and opponent IDs back for own goals
event = self.swapTeamIDs(event)

Expand Down
12 changes: 12 additions & 0 deletions trapp/import_lineup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from trapp.gameminute import GameMinute
from trapp.player import Player
from datetime import datetime
from time import sleep


class ImporterLineups(Importer):
Expand Down Expand Up @@ -62,6 +63,9 @@ def importPlayer(self, player):
gm.saveDict(player, self.log)
self.imported += 1
return True
sleep(0.25)
gm.disconnectDB()
del gm

def importRecord(self, record):
self.log.message('\nImporting lineup ' + str(record))
Expand Down Expand Up @@ -110,6 +114,12 @@ def importRecord(self, record):
# At this point we have self.players - but need to store them
[self.importPlayer(player) for player in self.players]

# Sleep
sleep(0.25)

g.disconnectDB()
del g

return True

def parseLineup(self, lineup, game, teamID, duration):
Expand Down Expand Up @@ -184,6 +194,8 @@ def parsePlayer(self, starter, gameID, teamID, duration):
'PlayerName': player,
}
playerID = p.lookupIDbyName(needle, self.log)
p.disconnectDB()
del p

if (len(playerID) == 1):
playerID = playerID[0]
Expand Down
3 changes: 3 additions & 0 deletions trapp/import_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ def importRecord(self, record):

self.log.message('')

p.disconnectDB()
del p

return True
3 changes: 3 additions & 0 deletions trapp/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ def lookupTeamID(self, teamname):
# At this point we know teamID is a list of length 1, so we return
# the first value only
return teamID[0]
# Clean up
team.disconnectDB()
del team

def parseMinute(self, minute):
# This reads in a string representing a minute denotation, and
Expand Down