Add 'Currencies' filter to the ring player stats viewer.
[fpdb-dooglus.git] / pyfpdb / Summaries.py
blob13f89efc3aa2bcd52813f5c49052c1b241afb502
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 #Copyright 2008-2011 Steffen Schaumburg
5 #This program is free software: you can redistribute it and/or modify
6 #it under the terms of the GNU Affero General Public License as published by
7 #the Free Software Foundation, version 3 of the License.
9 #This program is distributed in the hope that it will be useful,
10 #but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 #GNU General Public License for more details.
14 #You should have received a copy of the GNU Affero General Public License
15 #along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #In the "official" distribution you can find the license in agpl-3.0.txt.
18 """This file is to fetch summaries through IMAP and pass them on to the appropriate parser"""
19 #see http://docs.python.org/library/imaplib.html for the python interface
20 #see http://tools.ietf.org/html/rfc2060#section-6.4.4 for IMAP4 search criteria
22 import sys
23 from imaplib import IMAP4_SSL
24 from Summaries import Summaries
25 from PokerStarsSummaries import PokerStarsSummaries
27 #TODO: move all these into the config file. until then usage is: ./ImapSummaries.py YourImapHost YourImapUser YourImapPw
28 configHost=sys.argv[1]
29 configUser=sys.argv[2]
30 configPw=sys.argv[3]
32 server = IMAP4_SSL(configHost) #TODO: optionally non-SSL
33 response = server.login(configUser, configPw) #TODO catch authentication error
34 #print "response to logging in:",response
35 #print "server.list():",server.list() #prints list of folders
37 response = server.select("INBOX")
38 #print "response to selecting INBOX:",response
39 if response[0]!="OK":
40 raise error #TODO: show error message
42 neededMessages=[]
43 response, searchData = server.search(None, "SUBJECT", "PokerStars Tournament History Request")
44 for messageNumber in searchData[0].split(" "):
45 response, headerData = server.fetch(messageNumber, "(BODY[HEADER.FIELDS (SUBJECT)])")
46 #print "response to fetch subject:",response
47 if response!="OK":
48 raise error #TODO: show error message
49 if headerData[1].find("Subject: PokerStars Tournament History Request - Last x")!=1:
50 neededMessages.append(messageNumber, "PS")
52 tourneys=[]
53 if len(neededMessages)==0:
54 raise error #TODO: show error message
55 for messageData in neededMessages:
56 response, bodyData = server.fetch(messageData[0], "(UID BODY[TEXT])")
57 if response!="OK":
58 raise error #TODO: show error message
59 if messageData[0]=="PS":
60 tourneys.append(PokerStarsSummaries.PokerStarsSummaries(bodyData))
62 for tourney in tourneys:
63 print "tourney:",tourney
65 server.close()
66 server.logout()