ImapFetcher: Make it run from command line with -i

This commit is contained in:
Worros 2010-09-04 16:33:16 +08:00
parent 04849775d7
commit 1dda0848d3

View File

@ -20,8 +20,17 @@
#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
from imaplib import IMAP4, IMAP4_SSL from imaplib import IMAP4, IMAP4_SSL
import sys
import codecs
import re
import Configuration
import Database
import SQL
import Options
import PokerStarsSummary import PokerStarsSummary
import locale import locale
lang=locale.getdefaultlocale()[0][0:2] lang=locale.getdefaultlocale()[0][0:2]
if lang=="en": if lang=="en":
@ -90,3 +99,54 @@ def run(config, db):
# pass # pass
server.logout() server.logout()
def readFile(filename):
kodec = "utf8"
in_fh = codecs.open(filename, 'r', kodec)
whole_file = in_fh.read()
in_fh.close()
return whole_file
def runFake(db, config, infile):
summaryText = readFile(infile)
# This regex should be part of PokerStarsSummary
re_SplitGames = re.compile("PokerStars Tournament #")
summaryList = re.split(re_SplitGames, summaryText)
if len(summaryList) <= 1:
print "DEBUG: re_SplitGames isn't matching"
for summary in summaryList[1:]:
result = PokerStarsSummary.PokerStarsSummary(db=db, config=config, siteName=u"PokerStars", summaryText=summary, builtFrom = "file")
def splitPokerStarsSummaries(emailText):
splitSummaries=emailText.split("\nPokerStars Tournament #")[1:]
def main(argv=None):
if argv is None:
argv = sys.argv[1:]
(options, argv) = Options.fpdb_options()
if options.usage == True:
#Print usage examples and exit
print _("USAGE:")
sys.exit(0)
# These options should really come from the OptionsParser
config = Configuration.Config(file = "HUD_config.test.xml")
db = Database.Database(config)
sql = SQL.Sql(db_server = 'sqlite')
settings = {}
settings.update(config.get_db_parameters())
settings.update(config.get_import_parameters())
settings.update(config.get_default_paths())
db.recreate_tables()
runFake(db, config, options.infile)
if __name__ == '__main__':
sys.exit(main())