Skip to content

Commit

Permalink
feat: 添加结果目录名配置的功能
Browse files Browse the repository at this point in the history
配置config.json的result_dir_name,值可为0或1,默认为0。值为0表示将结果文件保存到以昵称为名的文件夹里,值为1表示将结果文件保存到以id为名的文件夹里。
  • Loading branch information
dataabc committed Dec 1, 2020
1 parent a96f70e commit 5b58ac2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"retweet_pic_download": 0,
"original_video_download": 1,
"retweet_video_download": 0,
"result_dir_name": 1,
"cookie": "your cookie",
"mysql_config": {
"host": "localhost",
Expand Down
10 changes: 7 additions & 3 deletions weibo.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def __init__(self, config):
'original_video_download'] # 取值范围为0、1, 0代表不下载原创微博视频,1代表下载
self.retweet_video_download = config[
'retweet_video_download'] # 取值范围为0、1, 0代表不下载转发微博视频,1代表下载
self.result_dir_name = config.get(
'result_dir_name', 0) # 结果目录名,取值为0或1,决定结果文件存储在用户昵称文件夹里还是用户id文件夹里
cookie = config.get('cookie') # 微博cookie,可填可不填
user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36'
self.headers = {'User_Agent': user_agent, 'Cookie': cookie}
Expand Down Expand Up @@ -725,9 +727,11 @@ def get_write_info(self, wrote_count):
def get_filepath(self, type):
"""获取结果文件路径"""
try:
file_dir = os.path.split(
os.path.realpath(__file__)
)[0] + os.sep + 'weibo' + os.sep + self.user['screen_name']
dir_name = self.user['screen_name']
if self.result_dir_name:
dir_name = self.user_config['user_id']
file_dir = os.path.split(os.path.realpath(
__file__))[0] + os.sep + 'weibo' + os.sep + dir_name
if type == 'img' or type == 'video':
file_dir = file_dir + os.sep + type
if not os.path.isdir(file_dir):
Expand Down

0 comments on commit 5b58ac2

Please sign in to comment.