Skip to content

Commit

Permalink
Merge pull request #18 from claromes/cs-cz-locale
Browse files Browse the repository at this point in the history
Add cs-CZ locale
  • Loading branch information
claromes authored Jan 7, 2024
2 parents f54419e + d0aa1e6 commit 0c80fa1
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ volleystats [--help] --fed FED (--match MATCH | --comp COMP) [--log]

- pt-BR
- en-GB
- cs-CZ

## Docs

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
name='volleystats',
version=version,
author='Claromes',
description='CLI tool to get volleyball statistics from the Data Project Web Competition websites (WCM)',
description='Command-line tool to scrape volleyball statistics from Data Project Web Competition websites',
long_description=long_description,
long_description_content_type='text/markdown',
keywords='volleyball sports cli dataset analytics',
keywords='volleyball sports command-line dataset analytics',
url='https://github.com/claromes/volleystats',
project_urls={
'Documentation': 'https://claromes.github.io/volleystats',
Expand Down
6 changes: 6 additions & 0 deletions volleystats/spiders/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ def parse(self, response):

ptBR = response.xpath("//*[contains(@class, 'RCB_Culture_pt-BR')]/span/input/@value").get()
enGB = response.xpath("//*[contains(@class, 'RCB_Culture_en-GB')]/span/input/@value").get()
csCZ = response.xpath("//*[contains(@class, 'RCB_Culture_cs-CZ')]/span/input/@value").get()

if ptBR == 'PT':
match_date = parse_ptbr_date(match_date_text)
elif enGB == 'EN':
match_date = parse_engb_date(match_date_text)
elif csCZ == 'CZ':
match_date = parse_cscz_date(match_date_text)

home_team_string = response.xpath("normalize-space(//span[@id='Content_Main_LBL_HomeTeam']/text())").get().replace(' ', '-').lower()
home_team = re.sub('[^A-Za-z0-9]+', '-', home_team_string)
Expand Down Expand Up @@ -80,11 +83,14 @@ def parse(self, response):

ptBR = response.xpath("//*[contains(@class, 'RCB_Culture_pt-BR')]/span/input/@value").get()
enGB = response.xpath("//*[contains(@class, 'RCB_Culture_en-GB')]/span/input/@value").get()
csCZ = response.xpath("//*[contains(@class, 'RCB_Culture_cs-CZ')]/span/input/@value").get()

if ptBR == 'PT':
match_date = parse_ptbr_date(match_date_text)
elif enGB == 'EN':
match_date = parse_engb_date(match_date_text)
elif csCZ == 'CZ':
match_date = parse_cscz_date(match_date_text)

guest_team_string = response.xpath("normalize-space(//span[@id='Content_Main_LBL_GuestTeam']/text())").get().replace(' ', '-').lower()
guest_team = re.sub('[^A-Za-z0-9]+', '-', guest_team_string)
Expand Down
46 changes: 43 additions & 3 deletions volleystats/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ def parse_ptbr_date(date_string):
date_re_1 = re.search(r'-(\w+)-', str_4)
date_re_2 = date_re_1.group(1)

date_re_en = ''

if date_re_2 == 'janeiro':
date_re_en = 'january'
elif date_re_2 == 'fevereiro':
Expand Down Expand Up @@ -61,4 +59,46 @@ def parse_engb_date(date_string):

parsed_engb_date = datetime.strptime(str_2, '%d-%B-%Y').date()

return parsed_engb_date
return parsed_engb_date

# cs-CZ: 'čtvrtek 26. října 2023 - 14:00' to 2023-10-26
def parse_cscz_date(date_string):
str_1 = date_string.replace(' ', '-')
str_2 = str_1.rsplit('---', 1)[0]
str_3 = str_2.replace('.', '')
str_4 = str_3.split('-', 1)[1]

date_re_1 = re.search(r'-(\w+)-', str_4)
date_re_2 = date_re_1.group(1)

if date_re_2 == 'ledna':
date_re_en = 'January'
elif date_re_2 == 'února':
date_re_en = 'February'
elif date_re_2 == 'března':
date_re_en = 'March'
elif date_re_2 == 'dubna':
date_re_en = 'April'
elif date_re_2 == 'května':
date_re_en = 'May'
elif date_re_2 == 'června':
date_re_en = 'June'
elif date_re_2 == 'července':
date_re_en = 'July'
elif date_re_2 == 'srpna':
date_re_en = 'August'
elif date_re_2 == 'září':
date_re_en = 'September'
elif date_re_2 == 'října':
date_re_en = 'October'
elif date_re_2 == 'listopadu':
date_re_en = 'November'
elif date_re_2 == 'prosince':
date_re_en = 'December'

var_date_re_2 = f'{re.escape(date_re_2)}-'
parsed_date = re.sub(var_date_re_2, f'{date_re_en}-', str_4)

parsed_cscz_date = datetime.strptime(parsed_date, '%d-%B-%Y').date()

return parsed_cscz_date
2 changes: 1 addition & 1 deletion volleystats/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.5'
__version__ = '0.5.1'

0 comments on commit 0c80fa1

Please sign in to comment.