Last active
December 2, 2016 18:53
-
-
Save JarrettR/29566fd90a70897578aa35b065ac97f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def parseSQL(filename): | |
fd = open(filename, 'r') | |
sqlFile = fd.read() | |
fd.close() | |
memberCount = [] | |
keyholderCount = [] | |
friendCount = [] | |
cardCount = [] | |
otherCount = [] | |
sqlCommands = sqlFile.split(';') | |
for command in sqlCommands: | |
if command.find('ipnrequest') != -1: | |
entries = command.split('),(') | |
for entry in entries: | |
if entry.find("CAD") != -1: | |
fields = entry.split(',') | |
if entry.find("25.00") != -1: | |
memberCount.append(fields[1][1:8]) | |
elif entry.find("30.00") != -1: | |
memberCount.append(fields[1][1:8]) | |
elif entry.find("50.00") != -1: | |
keyholderCount.append(fields[1][1:8]) | |
elif entry.find("60.00") != -1: | |
keyholderCount.append(fields[1][1:8]) | |
elif entry.find("10.00") != -1: | |
friendCount.append(fields[1][1:8]) | |
elif entry.find("5.00") != -1: | |
cardCount.append(fields[1][1:8]) | |
else: | |
otherCount.append(fields[1][1:8]) | |
print "Total IPNs in dataset:" | |
print " Members: {}, Keyholders: {}, Friends: {}, Cardholders: {}, Other: {}".format( \ | |
len(memberCount), len(keyholderCount), len(friendCount), len(cardCount), len(otherCount)) | |
print "By Month:" | |
monthStr = " Month: " | |
memberStr = " Members: " | |
keyholderStr = " Keyholders: " | |
friendStr = " Friends: " | |
cardStr = " Cardholders: " | |
otherStr = "" | |
for i in range(11): | |
monthStr += "2016-{:02} ".format(i + 1) | |
memberStr += "{:<10} ".format(memberCount.count("2016-{:02}".format(i + 1))) | |
keyholderStr += "{:<11}".format(keyholderCount.count("2016-{:02}".format(i + 1))) | |
friendStr += "{:<11}".format(friendCount.count("2016-{:02}".format(i + 1))) | |
cardStr += "{:<11}".format(cardCount.count("2016-{:02}".format(i + 1))) | |
print monthStr | |
print memberStr | |
print keyholderStr | |
print friendStr | |
print cardStr | |
parseSQL('backup.sql') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment