Coverage for Summaries.py: 0%
35 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-27 18:50 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-27 18:50 +0000
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.
8#
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.
13#
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"""
19from __future__ import print_function
20#see http://docs.python.org/library/imaplib.html for the python interface
21#see http://tools.ietf.org/html/rfc2060#section-6.4.4 for IMAP4 search criteria
23import sys
24from imaplib import IMAP4_SSL
25from Summaries import Summaries
26import PokerStarsSummary
27import Exceptions
29#TODO: move all these into the config file. until then usage is: ./ImapSummaries.py YourImapHost YourImapUser YourImapPw
30configHost=sys.argv[1]
31configUser=sys.argv[2]
32configPw=sys.argv[3]
34server = IMAP4_SSL(configHost) #TODO: optionally non-SSL
35response = server.login(configUser, configPw) #TODO catch authentication error
36#print "response to logging in:",response
37#print "server.list():",server.list() #prints list of folders
39response = server.select("INBOX")
40#print "response to selecting INBOX:",response
41if response[0]!="OK":
42 raise error #TODO: show error message
44neededMessages=[]
45response, searchData = server.search(None, "SUBJECT", "PokerStars Tournament History Request")
46for messageNumber in searchData[0].split(" "):
47 response, headerData = server.fetch(messageNumber, "(BODY[HEADER.FIELDS (SUBJECT)])")
48 #print "response to fetch subject:",response
49 if response!="OK":
50 raise error #TODO: show error message
51 if headerData[1].find("Subject: PokerStars Tournament History Request - Last x")!=1:
52 neededMessages.append(messageNumber, "PS")
54tourneys=[]
55if len(neededMessages)==0:
56 raise error #TODO: show error message
57for messageData in neededMessages:
58 response, bodyData = server.fetch(messageData[0], "(UID BODY[TEXT])")
59 if response!="OK":
60 raise error #TODO: show error message
61 if messageData[0]=="PS":
62 tourneys.append(PokerStarsSummary.PokerStarsSummary(bodyData))
64for tourney in tourneys:
65 print("tourney:",tourney)
67server.close()
68server.logout()