Skip to content

Commit

Permalink
[Fix] #51
Browse files Browse the repository at this point in the history
  • Loading branch information
wxy1343 committed Sep 25, 2021
1 parent ba42a3c commit 287b113
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 17 deletions.
2 changes: 1 addition & 1 deletion aliyunpan/about.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.7.14'
__version__ = '2.7.15'
18 changes: 13 additions & 5 deletions aliyunpan/api/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
from threading import RLock

import requests
import simplejson

from aliyunpan.api import ua
# from aliyunpan.api import ua
from aliyunpan.api.req import *
from aliyunpan.api.type import UserInfo, AlibumInfo
from aliyunpan.api.utils import *
Expand Down Expand Up @@ -46,12 +47,13 @@ def __init__(self, refresh_token: str = None, album: bool = False):
lambda self, value: setattr(self, '_drive_id', value))
album = property(lambda self: self._album, lambda self, value: setattr(self, '_album', value))

def login(self, username: str = None, password: str = None):
def login(self, username: str = None, password: str = None, ua: str = None):
"""
登录api
https://github.com/zhjc1124/aliyundrive
:param username:
:param password:
:param ua:
:return:
"""
if username:
Expand All @@ -72,7 +74,7 @@ def login(self, username: str = None, password: str = None):
'loginId': username,
'password2': password2,
'appName': 'aliyun_drive',
'ua': ua.get_ua()
'ua': ua
}
}
logger.info('Logging in.')
Expand All @@ -95,7 +97,7 @@ def login(self, username: str = None, password: str = None):
pass
raise LoginFailed

def get_file_list(self, parent_file_id: str = 'root', next_marker: str = None) -> list:
def get_file_list(self, parent_file_id: str = 'root', next_marker: str = None, retry=3) -> list:
"""
获取文件列表
:param parent_file_id:
Expand All @@ -106,7 +108,13 @@ def get_file_list(self, parent_file_id: str = 'root', next_marker: str = None) -
json = {"drive_id": self.drive_id, "parent_file_id": parent_file_id, 'fields': '*', 'marker': next_marker}
logger.info(f'Get the list of parent_file_id {parent_file_id}.')
r = self._req.post(url, json=json)
logger.debug(r.json())
try:
logger.debug(r.json())
except simplejson.errors.JSONDecodeError:
if retry:
return self.get_file_list(parent_file_id=parent_file_id, next_marker=next_marker, retry=retry - 1)
else:
raise
if 'items' not in r.json():
return []
file_list = r.json()['items']
Expand Down
3 changes: 2 additions & 1 deletion aliyunpan/api/req.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from threading import RLock

import requests
import simplejson
from requests.packages.urllib3.exceptions import InsecureRequestWarning

from aliyunpan.api.utils import logger
Expand Down Expand Up @@ -81,7 +82,7 @@ def _req(self, method, *args, **kwargs):
raise InvalidAccessToken
except (KeyboardInterrupt, InvalidAccessToken, LoginFailed):
raise
except json.decoder.JSONDecodeError:
except (json.decoder.JSONDecodeError, simplejson.errors.JSONDecodeError):
logger.debug(r.text)
except KeyError:
pass
Expand Down
15 changes: 10 additions & 5 deletions aliyunpan/cli/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import platform
from typing import List

import aria2p
Expand Down Expand Up @@ -105,14 +106,18 @@ def ls(self, path='root', l=False, query=None):
file_info_list = self._path_list.get_file_info(self._disk.search(query))
else:
file_info_list = self._path_list.get_path_list(path, update=False)
for i in file_info_list:
for i, j in enumerate(file_info_list):
if l:
if i.type:
print(str_of_size(i.size), time.strftime('%d %b %H:%M', i.ctime), i.id, i.name)
if j.type:
print(str_of_size(j.size), time.strftime('%d %b %H:%M', j.ctime), j.id, j.name, end='')
else:
print('-', time.strftime('%d %b %H:%M', i.ctime), i.id, i.name)
print('-', time.strftime('%d %b %H:%M', j.ctime), j.id, j.name, end='')
if i + 1 < len(file_info_list):
print()
else:
print(i.name, end='\t')
print(j.name, end='\t')
if platform.system() != 'Windows':
print()

def get_path_list(self, path='root') -> List[FileInfo]:
return self._path_list.get_path_list(path, update=False)
Expand Down
4 changes: 1 addition & 3 deletions aliyunpan/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import io
import os
import platform
import sys
import time
from abc import abstractmethod
Expand Down Expand Up @@ -147,8 +146,7 @@ def __init__(self):
self.print_line = False

def __del__(self):
if platform.system() != 'Windows':
self._stdout.write('\n')
pass

output = property(lambda self: self._print,
lambda self, value: (self._lock.acquire(), setattr(self, '_', None),
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ colorama~=0.4.3
npyscreen==4.10.5
windows-curses;platform_system=="Windows"
pyperclip~=1.8.1
aria2p
aria2p~=0.10.4
Flask
PyExecJS
simplejson~=3.17.3

0 comments on commit 287b113

Please sign in to comment.