Skip to content

Commit

Permalink
#19 parse matchday correctly from request parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Sh4kE committed Mar 26, 2017
1 parent 51700b4 commit f1485bb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions core/managers/site_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ def download_transfer_excel(self, matchday=None):
if not self._is_transfer_file_present(matchday):
profile = webdriver.FirefoxProfile(os.path.join(BASE_DIR, 'ofm_transfer_data', 'firefox_profile'))
profile.set_preference("browser.download.dir", os.path.join(BASE_DIR, 'ofm_transfer_data'))

self.browser = webdriver.Firefox(firefox_profile=profile)

self.login()
Expand All @@ -99,10 +98,11 @@ def download_transfer_excel(self, matchday=None):

@staticmethod
def _is_transfer_file_present(matchday=None):

if not matchday:
matchday = Matchday.get_current()

if not os.path.isfile(os.path.join(BASE_DIR,
if os.path.isfile(os.path.join(BASE_DIR,
'ofm_transfer_data',
'ofm_spielerwechsel_{}_{}.csv'.format(
matchday.season.number,
Expand Down
13 changes: 12 additions & 1 deletion core/views/trigger_parsing_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from core.localization.messages import NOT_LOGGED_IN, NEWER_OFM_VERSION_AVAILABLE
from core.managers.parser_manager import ParserManager
from core.managers.site_manager import OFMSiteManager, OFMTransferSiteManager
from core.models import Matchday
from ofm_helper.common_settings import BASE_DIR


Expand Down Expand Up @@ -74,7 +75,17 @@ def trigger_match_parsing(request):
return trigger_single_parsing(request, pm.parse_all_matches, redirect_to)


def trigger_transfer_download(request, matchday=None):
def trigger_transfer_download(request):
matchday = request.GET.get("matchday")
current_matchday = Matchday.get_current()

filtered_matchdays = Matchday.objects.filter(season__number=current_matchday.season.number,
number=matchday if matchday else current_matchday.number)
if len(filtered_matchdays) == 1:
matchday = filtered_matchdays[0]
else:
matchday = current_matchday

site_manager = OFMTransferSiteManager(request.user)
site_manager.download_transfer_excel(matchday)
site_manager.kill_browser()
Expand Down

0 comments on commit f1485bb

Please sign in to comment.