Use debian 2.7 only
[fpbd-bostik.git] / pyfpdb / ScriptFetchWinamaxResults.py
blobb58cc6f2fcd8d67a1bf90fb8449ebcebaa45d48c
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 Configuration.set_logfile("fpdb-log.txt")
43 config = Configuration.Config()
44 db = Database.Database(config)
46 tourney_ids = db.getSiteTourneyNos("Winamax")
47 tids = []
49 for tid in tourney_ids:
50 blah, = tid # Unpack tuple
51 tids.append(str(blah))
52 # winamax_get_winning(tid,"blah")
53 results_dir = config.get_import_parameters().get("ResultsDirectory")
54 results_dir = os.path.expanduser(results_dir)
55 site_dir = os.path.join(results_dir, "Winamax")
56 print "DEBUG: site_dir: %s" % site_dir
57 filelist = [file for file in os.listdir(site_dir) if not file in [".",".."]]
58 print "DEBUG: filelist : %s" % filelist
59 print "DEBUG: tids : %s" % tids
61 for f in filelist:
62 try:
63 tids.remove(f)
64 except ValueError:
65 print "Warning: '%s' is not a known tourney_id" % f
67 if len(tids) == 0:
68 print "No tourney results files to fetch"
69 else:
70 for tid in tids:
71 filename = os.path.join(site_dir, tid)
72 data = fetch_winamax_results_page(tid)
73 print u"DEBUG: write_file(%s)" %(filename)
74 write_file(filename, data)
76 if __name__ == '__main__':
77 main()