fix
This commit is contained in:
@@ -67,8 +67,8 @@ if DDAL_EMAIL and DDAL_PASSWORD:
|
|||||||
raise Exception(f"{r['msg']} (alias = {repr(alias)}, url = {repr(url)})")
|
raise Exception(f"{r['msg']} (alias = {repr(alias)}, url = {repr(url)})")
|
||||||
return r['short']
|
return r['short']
|
||||||
|
|
||||||
def update(self, id, url) -> str:
|
def update(self, id, alias, url) -> str:
|
||||||
while True:
|
for _ in range(10):
|
||||||
with self.__token_lock:
|
with self.__token_lock:
|
||||||
bs = BeautifulSoup(self.__session.get(f'https://dd.al/user/edit/{id}').text, 'html.parser')
|
bs = BeautifulSoup(self.__session.get(f'https://dd.al/user/edit/{id}').text, 'html.parser')
|
||||||
token = bs.find('input', {'name': 'token'})
|
token = bs.find('input', {'name': 'token'})
|
||||||
@@ -82,17 +82,18 @@ if DDAL_EMAIL and DDAL_PASSWORD:
|
|||||||
loc = r.headers.get('Location')
|
loc = r.headers.get('Location')
|
||||||
if not (loc and urlsplit(loc).path != '/user'):
|
if not (loc and urlsplit(loc).path != '/user'):
|
||||||
raise Exception(f'loc = {repr(loc)}')
|
raise Exception(f'loc = {repr(loc)}')
|
||||||
short = next((item['short'] for item in self.search(url) if item['id'] == id), None)
|
item = next((item for item in self.search(alias) if item['id'] == id), None)
|
||||||
if short:
|
if item and item['original'] == url:
|
||||||
break
|
break
|
||||||
print(f'更新失败,正在重试... (id = {repr(id)}, url = {repr(url)})')
|
else:
|
||||||
return short
|
raise Exception(f'尝试 10 次更新 url 均失败 (id = {repr(id)}, url = {repr(url)})')
|
||||||
|
return item['short']
|
||||||
|
|
||||||
def upsert(self, alias, url) -> str:
|
def upsert(self, alias, url) -> str:
|
||||||
self.raise_for_alias(alias)
|
self.raise_for_alias(alias)
|
||||||
id = next((item['id'] for item in self.search(alias) if urlsplit(item['short']).path[1:] == alias), None)
|
id = next((item['id'] for item in self.search(alias) if urlsplit(item['short']).path[1:] == alias), None)
|
||||||
if id:
|
if id:
|
||||||
return self.update(id, url)
|
return self.update(id, alias, url)
|
||||||
else:
|
else:
|
||||||
return self.insert(alias, url)
|
return self.insert(alias, url)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user