Don't allow the start date to be later than the end date. If it is, modify whichever...
[fpdb-dooglus.git] / pyfpdb / ScriptFetchWinamaxResults.py
blob13ca8a8c1d15452d71362e8748d5b58f5514ee24
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 #Copyright 2008-2011 Carl Gherardi
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 """A script for fetching Winamax tourney results"""
19 import L10n
20 _ = L10n.get_translation()
22 import Configuration
23 import Database
25 import logging, os, sys
26 import re, urllib2
29 def fetch_winamax_results_page(tourney_id):
30 url = "https://www.winamax.fr/poker/tournament.php?ID=%s" % tourney_id
31 data = urllib2.urlopen(url).read()
32 return data
34 def write_file(filename, data):
35 f = open(filename, 'w')
36 print f
37 f.write(data)
38 f.close()
39 print f
41 def main():
42 config = Configuration.Config()
43 db = Database.Database(config)
45 tourney_ids = db.getSiteTourneyNos("Winamax")
46 tids = []
48 for tid in tourney_ids:
49 blah, = tid # Unpack tuple
50 tids.append(str(blah))
51 # winamax_get_winning(tid,"blah")
52 results_dir = config.get_import_parameters().get("ResultsDirectory")
53 results_dir = os.path.expanduser(results_dir)
54 site_dir = os.path.join(results_dir, "Winamax")
55 print "DEBUG: site_dir: %s" % site_dir
56 filelist = [file for file in os.listdir(site_dir) if not file in [".",".."]]
57 print "DEBUG: filelist : %s" % filelist
58 print "DEBUG: tids : %s" % tids
60 for f in filelist:
61 try:
62 tids.remove(f)
63 except ValueError:
64 print "Warning: '%s' is not a known tourney_id" % f
66 if len(tids) == 0:
67 print "No tourney results files to fetch"
68 else:
69 for tid in tids:
70 filename = os.path.join(site_dir, tid)
71 data = fetch_winamax_results_page(tid)
72 print u"DEBUG: write_file(%s)" %(filename)
73 write_file(filename, data)
75 if __name__ == '__main__':
76 main()