many not really separable changes for IMAP import and associated cleaning
- deactivated use of TourneySummary (short: TS) from HHC and subclasses - menu entry for IMAP import - converted ImapSummaries (short: IS) to use the config file - IS now optionally supports non-SSL and can run on folders other than INBOX - removed gametypes and getGameTypeAsString from TS method as identical one is in Hand - some other stuff
This commit is contained in:
parent
aeaac92fb9
commit
c6b6f8a788
|
@ -434,6 +434,19 @@ class Import:
|
||||||
return " interval = %s\n callFpdbHud = %s\n hhArchiveBase = %s\n saveActions = %s\n fastStoreHudCache = %s\n" \
|
return " interval = %s\n callFpdbHud = %s\n hhArchiveBase = %s\n saveActions = %s\n fastStoreHudCache = %s\n" \
|
||||||
% (self.interval, self.callFpdbHud, self.hhArchiveBase, self.saveActions, self.fastStoreHudCache)
|
% (self.interval, self.callFpdbHud, self.hhArchiveBase, self.saveActions, self.fastStoreHudCache)
|
||||||
|
|
||||||
|
class Email:
|
||||||
|
def __init__(self, node):
|
||||||
|
self.node = node
|
||||||
|
self.host= node.getAttribute("host")
|
||||||
|
self.username = node.getAttribute("username")
|
||||||
|
self.password = node.getAttribute("password")
|
||||||
|
self.useSsl = node.getAttribute("useSsl")
|
||||||
|
self.folder = node.getAttribute("folder")
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return " host = %s\n username = %s\n password = %s\n useSsl = %s\n folder = %s\n" \
|
||||||
|
% (self.host, self.username, self.password, self.useSsl, self.folder)
|
||||||
|
|
||||||
class HudUI:
|
class HudUI:
|
||||||
def __init__(self, node):
|
def __init__(self, node):
|
||||||
self.node = node
|
self.node = node
|
||||||
|
@ -593,6 +606,10 @@ class Config:
|
||||||
imp = Import(node = imp_node)
|
imp = Import(node = imp_node)
|
||||||
self.imp = imp
|
self.imp = imp
|
||||||
|
|
||||||
|
for email_node in doc.getElementsByTagName("email"):
|
||||||
|
email = Email(node = email_node)
|
||||||
|
self.email = email
|
||||||
|
|
||||||
for hui_node in doc.getElementsByTagName('hud_ui'):
|
for hui_node in doc.getElementsByTagName('hud_ui'):
|
||||||
hui = HudUI(node = hui_node)
|
hui = HudUI(node = hui_node)
|
||||||
self.ui = hui
|
self.ui = hui
|
||||||
|
|
|
@ -802,17 +802,17 @@ class Database:
|
||||||
#print "session stat_dict =", stat_dict
|
#print "session stat_dict =", stat_dict
|
||||||
#return stat_dict
|
#return stat_dict
|
||||||
|
|
||||||
def get_player_id(self, config, site, player_name):
|
def get_player_id(self, config, siteName, playerName):
|
||||||
c = self.connection.cursor()
|
c = self.connection.cursor()
|
||||||
#print "get_player_id: player_name =", player_name, type(player_name)
|
playerNameUtf = Charset.to_utf8(playerName)
|
||||||
p_name = Charset.to_utf8(player_name)
|
print "db.get_player_id siteName",siteName,"playerName",playerName
|
||||||
c.execute(self.sql.query['get_player_id'], (p_name, site))
|
c.execute(self.sql.query['get_player_id'], (playerNameUtf, siteName))
|
||||||
row = c.fetchone()
|
row = c.fetchone()
|
||||||
if row:
|
if row:
|
||||||
return row[0]
|
return row[0]
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_player_names(self, config, site_id=None, like_player_name="%"):
|
def get_player_names(self, config, site_id=None, like_player_name="%"):
|
||||||
"""Fetch player names from players. Use site_id and like_player_name if provided"""
|
"""Fetch player names from players. Use site_id and like_player_name if provided"""
|
||||||
|
|
||||||
|
@ -1995,10 +1995,14 @@ class Database:
|
||||||
return tourneyId
|
return tourneyId
|
||||||
#end def createOrUpdateTourney
|
#end def createOrUpdateTourney
|
||||||
|
|
||||||
def createOrUpdateTourneysPlayers(self, hand):
|
def createOrUpdateTourneysPlayers(self, hand, source=None):
|
||||||
tourneysPlayersIds=[]
|
tourneysPlayersIds=[]
|
||||||
for player in hand.players:
|
for player in hand.players:
|
||||||
playerId = hand.dbid_pids[player[1]]
|
print "beginning of for in createOrUpdateTourneysPlayers, player",player,"dbid_pids",hand.dbid_pids
|
||||||
|
if source=="TourneySummary": #TODO remove this horrible hack
|
||||||
|
playerId = hand.dbid_pids[player]
|
||||||
|
else:
|
||||||
|
playerId = hand.dbid_pids[player[1]]
|
||||||
|
|
||||||
cursor = self.get_cursor()
|
cursor = self.get_cursor()
|
||||||
cursor.execute (self.sql.query['getTourneysPlayersId'].replace('%s', self.sql.query['placeholder']),
|
cursor.execute (self.sql.query['getTourneysPlayersId'].replace('%s', self.sql.query['placeholder']),
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from HandHistoryConverter import *
|
from HandHistoryConverter import *
|
||||||
import TourneySummary
|
#import TourneySummary
|
||||||
|
|
||||||
# Fulltilt HH Format converter
|
# Fulltilt HH Format converter
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,6 @@ import Configuration
|
||||||
from Exceptions import *
|
from Exceptions import *
|
||||||
import DerivedStats
|
import DerivedStats
|
||||||
import Card
|
import Card
|
||||||
import Tourney
|
|
||||||
|
|
||||||
class Hand(object):
|
class Hand(object):
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,6 @@ log = logging.getLogger("parser")
|
||||||
|
|
||||||
|
|
||||||
import Hand
|
import Hand
|
||||||
import Tourney
|
|
||||||
from Exceptions import FpdbParseError
|
from Exceptions import FpdbParseError
|
||||||
import Configuration
|
import Configuration
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,7 @@
|
||||||
#see http://docs.python.org/library/imaplib.html for the python interface
|
#see http://docs.python.org/library/imaplib.html for the python interface
|
||||||
#see http://tools.ietf.org/html/rfc2060#section-6.4.4 for IMAP4 search criteria
|
#see http://tools.ietf.org/html/rfc2060#section-6.4.4 for IMAP4 search criteria
|
||||||
|
|
||||||
import sys
|
from imaplib import IMAP4, IMAP4_SSL
|
||||||
from imaplib import IMAP4_SSL
|
|
||||||
import PokerStarsSummary
|
import PokerStarsSummary
|
||||||
|
|
||||||
def splitPokerStarsSummaries(emailText):
|
def splitPokerStarsSummaries(emailText):
|
||||||
|
@ -30,20 +29,20 @@ def splitPokerStarsSummaries(emailText):
|
||||||
return splitSummaries
|
return splitSummaries
|
||||||
#end def emailText
|
#end def emailText
|
||||||
|
|
||||||
if __name__ == '__main__':
|
def run(config, db):
|
||||||
#TODO: move all these into the config file. until then usage is: ./ImapSummaries.py YourImapHost YourImapUser YourImapPw
|
print "start of IS.run"
|
||||||
configHost=sys.argv[1]
|
server=None
|
||||||
configUser=sys.argv[2]
|
#try:
|
||||||
configPw=sys.argv[3]
|
print "in try of IS.run"
|
||||||
#TODO: specify folder, whether to use SSL
|
if config.email.useSsl:
|
||||||
|
server = IMAP4_SSL(config.email.host)
|
||||||
try:
|
else:
|
||||||
server = IMAP4_SSL(configHost) #TODO: optionally non-SSL
|
server = IMAP4(config.email.host)
|
||||||
response = server.login(configUser, configPw) #TODO catch authentication error
|
response = server.login(config.email.username, config.email.password) #TODO catch authentication error
|
||||||
#print "response to logging in:",response
|
print "response to logging in:",response
|
||||||
#print "server.list():",server.list() #prints list of folders
|
#print "server.list():",server.list() #prints list of folders
|
||||||
|
|
||||||
response = server.select("INBOX")
|
response = server.select(config.email.folder)
|
||||||
#print "response to selecting INBOX:",response
|
#print "response to selecting INBOX:",response
|
||||||
if response[0]!="OK":
|
if response[0]!="OK":
|
||||||
raise error #TODO: show error message
|
raise error #TODO: show error message
|
||||||
|
@ -68,15 +67,15 @@ if __name__ == '__main__':
|
||||||
if messageData[0]=="PS":
|
if messageData[0]=="PS":
|
||||||
summaryTexts=(splitPokerStarsSummaries(bodyData))
|
summaryTexts=(splitPokerStarsSummaries(bodyData))
|
||||||
for summaryText in summaryTexts:
|
for summaryText in summaryTexts:
|
||||||
result=PokerStarsSummary.PokerStarsSummary(db=db, sitename="PokerStars", summaryText=summaryText, builtFrom = "IMAP")
|
result=PokerStarsSummary.PokerStarsSummary(db=db, config=config, siteName=u"PokerStars", summaryText=summaryText, builtFrom = "IMAP")
|
||||||
#print "result:",result
|
#print "finished importing a PS summary with result:",result
|
||||||
#TODO: count results and output to shell like hand importer does
|
#TODO: count results and output to shell like hand importer does
|
||||||
|
|
||||||
print "completed running Imap import, closing server connection"
|
print "completed running Imap import, closing server connection"
|
||||||
finally:
|
#finally:
|
||||||
try:
|
# try:
|
||||||
server.close()
|
# server.close()
|
||||||
finally:
|
# finally:
|
||||||
pass
|
# pass
|
||||||
server.logout()
|
#server.logout()
|
||||||
|
|
|
@ -23,16 +23,11 @@ from PokerStarsToFpdb import PokerStars
|
||||||
from TourneySummary import *
|
from TourneySummary import *
|
||||||
|
|
||||||
class PokerStarsSummary(TourneySummary):
|
class PokerStarsSummary(TourneySummary):
|
||||||
sitename = "PokerStars"
|
|
||||||
siteId = 2
|
|
||||||
#limits = PokerStars.limits
|
|
||||||
#games = PokerStars.games
|
|
||||||
# = PokerStars.
|
|
||||||
|
|
||||||
re_TourNo = re.compile("\#[0-9]+,")
|
re_TourNo = re.compile("\#[0-9]+,")
|
||||||
re_Entries = re.compile("[0-9]+")
|
re_Entries = re.compile("[0-9]+")
|
||||||
re_Prizepool = re.compile("\$[0-9]+\.[0-9]+")
|
re_Prizepool = re.compile("\$[0-9]+\.[0-9]+")
|
||||||
re_Player = re.compile("""(?P<RANK>[0-9]+):\s(?P<NAME>.*)\s\(.*\),(\s\$(?P<WINNINGS>[0-9]+\.[0-9]+)\s\()?""")
|
re_Player = re.compile(u"""(?P<RANK>[0-9]+):\s(?P<NAME>.*)\s\(.*\),(\s\$(?P<WINNINGS>[0-9]+\.[0-9]+)\s\()?""")
|
||||||
|
re_BuyInFee = re.compile("(?P<BUYIN>[0-9]+\.[0-9]+).*(?P<FEE>[0-9]+\.[0-9]+)")
|
||||||
# = re.compile("")
|
# = re.compile("")
|
||||||
|
|
||||||
def parseSummary(self):
|
def parseSummary(self):
|
||||||
|
@ -40,7 +35,17 @@ class PokerStarsSummary(TourneySummary):
|
||||||
|
|
||||||
self.tourNo = self.re_TourNo.findall(lines[0])[0][1:-1] #ignore game and limit type as thats not recorded
|
self.tourNo = self.re_TourNo.findall(lines[0])[0][1:-1] #ignore game and limit type as thats not recorded
|
||||||
|
|
||||||
#ignore lines[1] as buyin/fee are already recorded by HHC
|
if lines[1].find("$")!=-1:
|
||||||
|
self.currency="USD"
|
||||||
|
elif lines[1].find(u"€")!=-1:
|
||||||
|
self.currency="EUR"
|
||||||
|
else:
|
||||||
|
raise fpdbParseError("didn't recognise buyin currency")
|
||||||
|
|
||||||
|
result=self.re_BuyInFee.search(lines[1])
|
||||||
|
result=result.groupdict()
|
||||||
|
self.buyin=int(100*Decimal(result['BUYIN']))
|
||||||
|
self.fee=int(100*Decimal(result['FEE']))
|
||||||
|
|
||||||
self.entries = self.re_Entries.findall(lines[2])[0]
|
self.entries = self.re_Entries.findall(lines[2])[0]
|
||||||
|
|
||||||
|
|
|
@ -1944,7 +1944,6 @@ class Sql:
|
||||||
|
|
||||||
self.query['getPlayerIdBySite'] = """SELECT id from Players where name = %s AND siteId = %s"""
|
self.query['getPlayerIdBySite'] = """SELECT id from Players where name = %s AND siteId = %s"""
|
||||||
|
|
||||||
|
|
||||||
# used in Filters:
|
# used in Filters:
|
||||||
self.query['getSiteId'] = """SELECT id from Sites where name = %s"""
|
self.query['getSiteId'] = """SELECT id from Sites where name = %s"""
|
||||||
self.query['getGames'] = """SELECT DISTINCT category from Gametypes"""
|
self.query['getGames'] = """SELECT DISTINCT category from Gametypes"""
|
||||||
|
|
|
@ -102,6 +102,7 @@ import GuiPrefs
|
||||||
import GuiLogView
|
import GuiLogView
|
||||||
import GuiDatabase
|
import GuiDatabase
|
||||||
import GuiBulkImport
|
import GuiBulkImport
|
||||||
|
import ImapSummaries
|
||||||
import GuiPlayerStats
|
import GuiPlayerStats
|
||||||
import GuiPositionalStats
|
import GuiPositionalStats
|
||||||
import GuiTableViewer
|
import GuiTableViewer
|
||||||
|
@ -655,6 +656,7 @@ class fpdb:
|
||||||
<menu action="import">
|
<menu action="import">
|
||||||
<menuitem action="sethharchive"/>
|
<menuitem action="sethharchive"/>
|
||||||
<menuitem action="bulkimp"/>
|
<menuitem action="bulkimp"/>
|
||||||
|
<menuitem action="imapsummaries"/>
|
||||||
<menuitem action="autoimp"/>
|
<menuitem action="autoimp"/>
|
||||||
<menuitem action="autorate"/>
|
<menuitem action="autorate"/>
|
||||||
</menu>
|
</menu>
|
||||||
|
@ -701,6 +703,7 @@ class fpdb:
|
||||||
('import', None, '_Import'),
|
('import', None, '_Import'),
|
||||||
('sethharchive', None, '_Set HandHistory Archive Directory', None, 'Set HandHistory Archive Directory', self.select_hhArchiveBase),
|
('sethharchive', None, '_Set HandHistory Archive Directory', None, 'Set HandHistory Archive Directory', self.select_hhArchiveBase),
|
||||||
('bulkimp', None, '_Bulk Import', '<control>B', 'Bulk Import', self.tab_bulk_import),
|
('bulkimp', None, '_Bulk Import', '<control>B', 'Bulk Import', self.tab_bulk_import),
|
||||||
|
('imapsummaries', None, '_Import Tourney Summaries through eMail/IMAP', '<control>I', 'Auto Import and HUD', self.import_imap_summaries),
|
||||||
('autorate', None, 'Auto _Rating (todo)', '<control>R', 'Auto Rating (todo)', self.not_implemented),
|
('autorate', None, 'Auto _Rating (todo)', '<control>R', 'Auto Rating (todo)', self.not_implemented),
|
||||||
('viewers', None, '_Viewers'),
|
('viewers', None, '_Viewers'),
|
||||||
('autoimp', None, '_Auto Import and HUD', '<control>A', 'Auto Import and HUD', self.tab_auto_import),
|
('autoimp', None, '_Auto Import and HUD', '<control>A', 'Auto Import and HUD', self.tab_auto_import),
|
||||||
|
@ -734,6 +737,12 @@ class fpdb:
|
||||||
menubar = uimanager.get_widget('/MenuBar')
|
menubar = uimanager.get_widget('/MenuBar')
|
||||||
window.add_accel_group(accel_group)
|
window.add_accel_group(accel_group)
|
||||||
return menubar
|
return menubar
|
||||||
|
#end def get_menu
|
||||||
|
|
||||||
|
def import_imap_summaries(self, widget, data=None):
|
||||||
|
result=ImapSummaries.run(self.config, self.db)
|
||||||
|
print "import imap summaries result:", result
|
||||||
|
#end def import_imap_summaries
|
||||||
|
|
||||||
def load_profile(self, create_db = False):
|
def load_profile(self, create_db = False):
|
||||||
"""Loads profile from the provided path name."""
|
"""Loads profile from the provided path name."""
|
||||||
|
@ -879,7 +888,6 @@ class fpdb:
|
||||||
|
|
||||||
def tab_bulk_import(self, widget, data=None):
|
def tab_bulk_import(self, widget, data=None):
|
||||||
"""opens a tab for bulk importing"""
|
"""opens a tab for bulk importing"""
|
||||||
#print "start of tab_bulk_import"
|
|
||||||
new_import_thread = GuiBulkImport.GuiBulkImport(self.settings, self.config, self.sql)
|
new_import_thread = GuiBulkImport.GuiBulkImport(self.settings, self.config, self.sql)
|
||||||
self.threads.append(new_import_thread)
|
self.threads.append(new_import_thread)
|
||||||
bulk_tab=new_import_thread.get_vbox()
|
bulk_tab=new_import_thread.get_vbox()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user