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:
steffen123 2010-07-08 19:46:25 +02:00
parent aeaac92fb9
commit c6b6f8a788
9 changed files with 72 additions and 42 deletions

View File

@ -434,6 +434,19 @@ class Import:
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)
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:
def __init__(self, node):
self.node = node
@ -593,6 +606,10 @@ class Config:
imp = Import(node = imp_node)
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'):
hui = HudUI(node = hui_node)
self.ui = hui

View File

@ -802,17 +802,17 @@ class Database:
#print "session stat_dict =", 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()
#print "get_player_id: player_name =", player_name, type(player_name)
p_name = Charset.to_utf8(player_name)
c.execute(self.sql.query['get_player_id'], (p_name, site))
playerNameUtf = Charset.to_utf8(playerName)
print "db.get_player_id siteName",siteName,"playerName",playerName
c.execute(self.sql.query['get_player_id'], (playerNameUtf, siteName))
row = c.fetchone()
if row:
return row[0]
else:
return None
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"""
@ -1995,10 +1995,14 @@ class Database:
return tourneyId
#end def createOrUpdateTourney
def createOrUpdateTourneysPlayers(self, hand):
def createOrUpdateTourneysPlayers(self, hand, source=None):
tourneysPlayersIds=[]
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.execute (self.sql.query['getTourneysPlayersId'].replace('%s', self.sql.query['placeholder']),

View File

@ -20,7 +20,7 @@
import logging
from HandHistoryConverter import *
import TourneySummary
#import TourneySummary
# Fulltilt HH Format converter

View File

@ -37,7 +37,6 @@ import Configuration
from Exceptions import *
import DerivedStats
import Card
import Tourney
class Hand(object):

View File

@ -35,7 +35,6 @@ log = logging.getLogger("parser")
import Hand
import Tourney
from Exceptions import FpdbParseError
import Configuration

View File

@ -19,8 +19,7 @@
#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
import sys
from imaplib import IMAP4_SSL
from imaplib import IMAP4, IMAP4_SSL
import PokerStarsSummary
def splitPokerStarsSummaries(emailText):
@ -30,20 +29,20 @@ def splitPokerStarsSummaries(emailText):
return splitSummaries
#end def emailText
if __name__ == '__main__':
#TODO: move all these into the config file. until then usage is: ./ImapSummaries.py YourImapHost YourImapUser YourImapPw
configHost=sys.argv[1]
configUser=sys.argv[2]
configPw=sys.argv[3]
#TODO: specify folder, whether to use SSL
try:
server = IMAP4_SSL(configHost) #TODO: optionally non-SSL
response = server.login(configUser, configPw) #TODO catch authentication error
#print "response to logging in:",response
def run(config, db):
print "start of IS.run"
server=None
#try:
print "in try of IS.run"
if config.email.useSsl:
server = IMAP4_SSL(config.email.host)
else:
server = IMAP4(config.email.host)
response = server.login(config.email.username, config.email.password) #TODO catch authentication error
print "response to logging in:",response
#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
if response[0]!="OK":
raise error #TODO: show error message
@ -68,15 +67,15 @@ if __name__ == '__main__':
if messageData[0]=="PS":
summaryTexts=(splitPokerStarsSummaries(bodyData))
for summaryText in summaryTexts:
result=PokerStarsSummary.PokerStarsSummary(db=db, sitename="PokerStars", summaryText=summaryText, builtFrom = "IMAP")
#print "result:",result
result=PokerStarsSummary.PokerStarsSummary(db=db, config=config, siteName=u"PokerStars", summaryText=summaryText, builtFrom = "IMAP")
#print "finished importing a PS summary with result:",result
#TODO: count results and output to shell like hand importer does
print "completed running Imap import, closing server connection"
finally:
try:
server.close()
finally:
pass
server.logout()
#finally:
# try:
# server.close()
# finally:
# pass
#server.logout()

View File

@ -23,16 +23,11 @@ from PokerStarsToFpdb import PokerStars
from TourneySummary import *
class PokerStarsSummary(TourneySummary):
sitename = "PokerStars"
siteId = 2
#limits = PokerStars.limits
#games = PokerStars.games
# = PokerStars.
re_TourNo = re.compile("\#[0-9]+,")
re_Entries = re.compile("[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("")
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
#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]

View File

@ -1944,7 +1944,6 @@ class Sql:
self.query['getPlayerIdBySite'] = """SELECT id from Players where name = %s AND siteId = %s"""
# used in Filters:
self.query['getSiteId'] = """SELECT id from Sites where name = %s"""
self.query['getGames'] = """SELECT DISTINCT category from Gametypes"""

View File

@ -102,6 +102,7 @@ import GuiPrefs
import GuiLogView
import GuiDatabase
import GuiBulkImport
import ImapSummaries
import GuiPlayerStats
import GuiPositionalStats
import GuiTableViewer
@ -655,6 +656,7 @@ class fpdb:
<menu action="import">
<menuitem action="sethharchive"/>
<menuitem action="bulkimp"/>
<menuitem action="imapsummaries"/>
<menuitem action="autoimp"/>
<menuitem action="autorate"/>
</menu>
@ -701,6 +703,7 @@ class fpdb:
('import', None, '_Import'),
('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),
('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),
('viewers', None, '_Viewers'),
('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')
window.add_accel_group(accel_group)
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):
"""Loads profile from the provided path name."""
@ -879,7 +888,6 @@ class fpdb:
def tab_bulk_import(self, widget, data=None):
"""opens a tab for bulk importing"""
#print "start of tab_bulk_import"
new_import_thread = GuiBulkImport.GuiBulkImport(self.settings, self.config, self.sql)
self.threads.append(new_import_thread)
bulk_tab=new_import_thread.get_vbox()