Commit d6e41e6a authored by Lucas Ficheux's avatar Lucas Ficheux Committed by hydrargyrum
Browse files

[cragr] Fix regex for card id

parent 11a21a04
...@@ -355,26 +355,27 @@ def get_cards_parameters(self): ...@@ -355,26 +355,27 @@ def get_cards_parameters(self):
# Ignore coming lines without a link # Ignore coming lines without a link
continue continue
# Cards may be accessed via a url or a form: assert 'javascript' in raw_link, 'No form associated'
if 'javascript' in raw_link: # We extract the form name (e.g. 'frmc6') from a pattern
# We extract the form name (e.g. 'frmc6') from a pattern # such as "javascript:fwkPUAvancerForm('Cartes','frmc6')"
# such as "javascript:fwkPUAvancerForm('Cartes','frmc6')" form_search = re.search(r"\('Cartes','(.*)'\)", raw_link)
form_search = re.search(r"\('Cartes','(.*)'\)", raw_link) if form_search:
if form_search: card_link = form_search.group(1)
card_link = form_search.group(1)
else:
# This link does not correspond to a card
continue
else: else:
assert False, 'WE DO NOT HANDLE CARDS WITH URL YET!!!' # This link does not correspond to a card
continue
# The id of the card parent account is the closest # The id of the card parent account is the closest
# upper node containing an account id: # upper node containing an account id:
for el in coming.xpath('./preceding-sibling::tr')[::-1]: coming_info = coming.xpath('./preceding-sibling::tr')
m = re.search(r'> (\d+) ', CleanText(el)(self)) assert coming_info, "Couldn't find card info"
parent_id = None
for regex in (r'> (\d+) ', r'\s(\d+)\s'):
m = re.search(regex, CleanText('.')(coming_info[-1]))
if m: if m:
parent_id = m.group(1) parent_id = m.group(1)
break break
assert parent_id is not None, "Couldn't find the id of current card's parent account"
cards_parameters.add((card_link, parent_id)) cards_parameters.add((card_link, parent_id))
return cards_parameters return cards_parameters
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment