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"""
20 _
= L10n
.get_translation()
25 import logging
, os
, sys
29 def fetch_results_page(tourney_id
):
30 url
= "http://www.carbonpoker.ag/tournaments/tournament-details.html?id=%s-1" % tourney_id
32 data
= urllib2
.urlopen(url
).read()
34 except urllib2
.HTTPError
, e
:
38 def write_file(filename
, data
):
39 f
= open(filename
, 'w')
44 Configuration
.set_logfile("fpdb-log.txt")
45 config
= Configuration
.Config()
46 db
= Database
.Database(config
)
48 tourney_ids
= db
.getSiteTourneyNos("Merge")
51 for tid
in tourney_ids
:
52 blah
, = tid
# Unpack tuple
53 tids
.append(str(blah
))
54 # winamax_get_winning(tid,"blah")
55 results_dir
= config
.get_import_parameters().get("ResultsDirectory")
56 results_dir
= os
.path
.expanduser(results_dir
)
57 site_dir
= os
.path
.join(results_dir
, "Merge")
58 print "DEBUG: site_dir: %s" % site_dir
59 filelist
= [file for file in os
.listdir(site_dir
) if not file in [".",".."]]
60 print "DEBUG: filelist : %s" % filelist
61 print "DEBUG: tids : %s" % tids
67 print "Warning: '%s' is not a known tourney_id" % f
70 print "No tourney results files to fetch"
73 filename
= os
.path
.join(site_dir
, tid
)
74 data
= fetch_results_page(tid
)
76 print u
"DEBUG: write_file(%s)" %(filename)
77 write_file(filename
, data
)
79 if __name__
== '__main__':