Skip to content

Commit

Permalink
Improved handling of wrong passwords in COD deposition page
Browse files Browse the repository at this point in the history
  • Loading branch information
dkratzert committed Feb 6, 2024
1 parent 5e6c50b commit 93bea3d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 5 additions & 1 deletion finalcif/cif/cod/deposit.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def __init__(self, ui: Ui_FinalCifWindow, cif: Union[CifContainer, None], option
self.ui = ui
self.settings = FinalCifSettings()
self._cif = cif
self.token_valid = False
self.options = options
self._set_checkbox_states()
self.ui.depositorUsernameLineEdit.textChanged.connect(self._set_username)
Expand Down Expand Up @@ -206,8 +207,10 @@ def _refresh_cod_list(self):

def get_structures_from_cod(self):
f = CODFetcher(main_url=self.main_url)
if not self._cod_token:
if not self.token_valid:
self._cod_token = f.get_token(username=self.username, password=self.password)
if f.authenticated:
self.token_valid = True
f.get_table_data_by_token(self._cod_token)
parser = MyCODStructuresParser()
parser.feed(f.table_html)
Expand Down Expand Up @@ -360,6 +363,7 @@ def _set_username(self, text: str):
self.username = text

def _set_password(self, text: str):
self.token_valid = False
# Do not store this anywhere!
if len(text) > 4:
self.ui.refreshDepositListPushButton.setText('Refresh List')
Expand Down
3 changes: 3 additions & 0 deletions finalcif/cif/cod/deposition_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class CODFetcher():
def __init__(self, main_url: str):
self.table_html = ''
self.main_url = main_url
self.authenticated = False

@property
def _url(self):
Expand All @@ -31,6 +32,8 @@ def get_table_data_by_token(self, token: str):

def _extract_token(self, text: str, token: str = '') -> str:
for line in text.splitlines():
if "Deposited structures" in line:
self.authenticated = True
if 'CODSESSION' in line and '=' in line:
token = line.split('=')[-1].split('"')[0]
break
Expand Down
4 changes: 2 additions & 2 deletions finalcif/cif/cod/website_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def __init__(self):
def __repr__(self):
txt = ''
for st in self.structures:
txt = txt + 'https://www.crystallography.net/cod/information_card.php?id={0}&CODSESSION={1}\n' \
.format(st['number'], self.token)
txt = txt + (f'https://www.crystallography.net/cod/'
f'information_card.php?id={st["number"]}&CODSESSION={self.token}\n')
return txt

def init_structure(self) -> Dict[str, Union[str, None]]:
Expand Down

0 comments on commit 93bea3d

Please sign in to comment.