From 6dcb3ee1f2f17256668cf65504fa16de508f57fc Mon Sep 17 00:00:00 2001 From: 10295 <1029559041@qq.com> Date: Sat, 28 Apr 2018 02:05:39 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=BF=E9=87=8C=E4=BA=91=E6=99=BA=E8=83=BD?= =?UTF-8?q?=E4=BA=91=E7=9B=B8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PixivSearch/aliyun/photo/AliyunPhoto.py | 136 +++++++++++++++--------- PixivSearch/baidu/downLoadBduImg.py | 44 ++++---- 2 files changed, 110 insertions(+), 70 deletions(-) diff --git a/PixivSearch/aliyun/photo/AliyunPhoto.py b/PixivSearch/aliyun/photo/AliyunPhoto.py index 6d8a534..69fb51e 100644 --- a/PixivSearch/aliyun/photo/AliyunPhoto.py +++ b/PixivSearch/aliyun/photo/AliyunPhoto.py @@ -1,6 +1,8 @@ +import datetime import hashlib import json import os +import time import aliyunsdkcore import oss2 as oss2 @@ -19,6 +21,8 @@ class UploadPhoto(AcsClient): aliyunsdkcore.request.set_default_protocol_type("https") self.domain = 'cloudphoto.cn-shanghai.aliyuncs.com' self.version = '2017-07-11' + self.LibraryId = None + self.StoreName = None def get_md5_01(self, file_path): md5 = None @@ -54,64 +58,94 @@ class UploadPhoto(AcsClient): print('{index}:{name}'.format(index=index + 1, name=option[key])) return choose[(int)(input('输入{desc}\n'.format(desc=desc))) - 1] + def getSL(self): + request = self.createAction('ListPhotoStores') + response = self.do_action_with_exception(request) + print('PhotoStores:') + photoStores = response['PhotoStores'] + self.StoreName = self.showOption(photoStores, 'Name', 'StoreName') + + # request = self.createAction('GetPhotoStore') + # request.add_query_param('StoreName', StoreName) + # response = self.do_action_with_exception(request) + # print(response) + + request = self.createAction('FetchLibraries') + request.add_query_param('StoreName', self.StoreName) + response = self.do_action_with_exception(request) + Libraries = response['Libraries'] + self.LibraryId = self.showOption(Libraries, 'LibraryId', 'LibraryId') + + # request = self.createAction('GetLibrary') + # request.add_body_params('StoreName', StoreName) + # request.add_body_params('LibraryId', LibraryId) + # response = self.do_action_with_exception(request) + # print(response) + + def uploadPhoto(self): + if self.StoreName is None or self.LibraryId is None: + return '未选择StoreName、LibraryId' + + request = self.createAction('CreateTransaction') + filePath = input('输入上传文件路径') + fileName = filePath.split('/')[-1] + request.add_query_param('Size', os.path.getsize(filePath)) + request.add_query_param('Ext', fileName[-fileName[::-1].index('.'):]) + request.add_query_param('Md5', self.get_md5_01(filePath)) + request.add_query_param('StoreName', self.StoreName) + + request.add_query_param('LibraryId', self.LibraryId) + response = self.do_action_with_exception(request) + print(response) + Upload = response['Transaction']['Upload'] + FileId = Upload['FileId'] + SessionId = Upload['SessionId'] + Bucket = Upload['Bucket'] + OssEndpoint = Upload['OssEndpoint'] + ObjectKey = Upload['ObjectKey'] + + auth = oss2.Auth(self.get_access_key(), self.get_access_secret()) + bucket = oss2.Bucket(auth, OssEndpoint, Bucket) + with open(filePath, 'rb') as fileobj: + result = bucket.put_object(ObjectKey, fileobj) + print('文件上传状态{status}'.format(status=result.status)) + + request = self.createAction('CreatePhoto') + request.add_query_param('FileId', FileId) + request.add_query_param('PhotoTitle', fileName) + request.add_query_param('SessionId', SessionId) + request.add_query_param('StoreName', self.StoreName) + request.add_query_param('UploadType', 'manual') + request.add_query_param('LibraryId', self.LibraryId) + response = self.do_action_with_exception(request) + print(response) + if __name__ == '__main__': client = UploadPhoto() - - request = client.createAction('ListPhotoStores') - response = client.do_action_with_exception(request) - print('PhotoStores:') - photoStores = response['PhotoStores'] - StoreName = client.showOption(photoStores, 'Name', 'StoreName') - - request = client.createAction('GetPhotoStore') - request.add_query_param('StoreName', StoreName) + client.getSL() + request = client.createAction('ListPhotos') + request.add_query_param('StoreName', client.StoreName) + request.add_query_param('LibraryId', client.LibraryId) + request.add_query_param('State', 'all') response = client.do_action_with_exception(request) print(response) - request = client.createAction('FetchLibraries') - request.add_query_param('StoreName', StoreName) - response = client.do_action_with_exception(request) - Libraries = response['Libraries'] - LibraryId = client.showOption(Libraries, 'LibraryId', 'LibraryId') + IdStr = client.showOption(response['Photos'], 'IdStr', '照片Id') - request = client.createAction('GetLibrary') - request.add_body_params('StoreName', StoreName) - request.add_body_params('LibraryId', LibraryId) + request = client.createAction('EditPhotos') + request.add_query_param('PhotoId.1', IdStr) + request.add_query_param('StoreName', client.StoreName) + request.add_query_param('LibraryId', client.LibraryId) + request.add_query_param('ShareExpireTime', int(round(time.time() * 1000)) + 60 * 60) response = client.do_action_with_exception(request) print(response) - request = client.createAction('CreateTransaction') - filePath = input('输入上传文件路径') - fileName = filePath.split('/')[-1] - request.add_query_param('Size', os.path.getsize(filePath)) - request.add_query_param('Ext', fileName[-fileName[::-1].index('.'):]) - request.add_query_param('Md5', client.get_md5_01(filePath)) - request.add_query_param('StoreName', StoreName) - - # request.add_query_param('LibraryId', liberaryId) - # response = json.loads(client.do_action_with_exception(request)) - # print(response) - # - # Upload=response['Transaction']['Upload'] - # FileId = Upload['FileId'] - # SessionId = Upload['SessionId'] - # Bucket=Upload['Bucket'] - # OssEndpoint=Upload['OssEndpoint'] - # ObjectKey=Upload['ObjectKey'] - # - # auth = oss2.Auth(client.get_access_key(), client.get_access_secret()) - # bucket = oss2.Bucket(auth, OssEndpoint,Bucket) - # with open(filePath, 'rb') as fileobj: - # result=bucket.put_object(ObjectKey,fileobj) - # print('文件上传状态{status}'.format(status=result.status)) - # - # request = client.createAction('CreatePhoto') - # request.add_query_param('FileId', FileId) - # request.add_query_param('PhotoTitle', fileName) - # request.add_query_param('SessionId', SessionId) - # request.add_query_param('StoreName', StoreName) - # request.add_query_param('UploadType', 'manual') - # request.add_query_param('LibraryId', liberaryId) - # response = json.loads(client.do_action_with_exception(request)) - # print(response) + request = client.createAction('GetPublicAccessUrls') + request.add_query_param('DomainType', 'OSS') + request.add_query_param('PhotoId.1', IdStr) + request.add_query_param('StoreName', client.StoreName) + request.add_query_param('ZoomType', 'style/1') + request.add_query_param('LibraryId', client.LibraryId) + response = client.do_action_with_exception(request) + print(response) \ No newline at end of file diff --git a/PixivSearch/baidu/downLoadBduImg.py b/PixivSearch/baidu/downLoadBduImg.py index 5085c44..03b1edc 100644 --- a/PixivSearch/baidu/downLoadBduImg.py +++ b/PixivSearch/baidu/downLoadBduImg.py @@ -91,22 +91,28 @@ def downImage(params): if __name__ == '__main__': - str = '' - while True: - str = input('输入要下载图片的关键字,输入 exit 退出程序\n') - if not str == 'exit': - while True: - savePath = input('输入图片存放目录:例如 E:/图片,注意目录之间使用正斜杠隔开"/"\n') - if re.fullmatch(r"[a-zA-z]:(/[\u4e00-\u9fa5_a-zA-Z0-9]+)+", savePath) is None: - print(r'图片目录{savePath}不合法请重新输入'.format(savePath=savePath)) - else: - break - getBaiduImage(str) - print(r'使用{threadNum}线程成功下载{count}张图片到目录{path}下,耗时:{second}'.format(threadNum=threadNum, - count=len(os.listdir(savePath)), - path=savePath, - second=datetime.now() - startTime)) - flag = False - else: - print('exit') - break + # str = '' + # while True: + # str = input('输入要下载图片的关键字,输入 exit 退出程序\n') + # if not str == 'exit': + # while True: + # savePath = input('输入图片存放目录:例如 E:/图片,注意目录之间使用正斜杠隔开"/"\n') + # if re.fullmatch(r"[a-zA-z]:(/[\u4e00-\u9fa5_a-zA-Z0-9]+)+", savePath) is None: + # print(r'图片目录{savePath}不合法请重新输入'.format(savePath=savePath)) + # else: + # break + # getBaiduImage(str) + # print(r'使用{threadNum}线程成功下载{count}张图片到目录{path}下,耗时:{second}'.format(threadNum=threadNum, + # count=len(os.listdir(savePath)), + # path=savePath, + # second=datetime.now() - startTime)) + # flag = False + # else: + # print('exit') + # break + req = requests.post('https://gifmaker.develophelper.com/gif/make', {'tplid': 1, + 'content': '好啊##$@?$?@$##就算你是一流工程师##$@?$?@$##就算你出报告再完美##$@?$?@$##我叫你改报告你就要改##$@?$?@$##毕竟我是客户##$@?$?@$##客户了不起啊##$@?$?@$##sorry 客户真的了不起##$@?$?@$##以后叫他天天改报告##$@?$?@$##天天改 天天改'}) + if req.status_code==200: + response = json.loads(req.content.decode()) + if 'd' in response: + print(response['d'])