From 5eab62491f2e9f568a3d8ca0f7bc5cb2e3861c89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=A0=E9=99=90=E8=B6=85=E9=A2=91?= <1029559041@qq.com> Date: Sun, 22 Apr 2018 23:29:36 +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/__init__.py | 0 PixivSearch/aliyun/photo/AliyunPhoto.py | 79 +++++++++++++++++++++++++ PixivSearch/baidu/__init__.py | 0 PixivSearch/dao/bangumi.py | 2 +- 4 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 PixivSearch/aliyun/__init__.py create mode 100644 PixivSearch/aliyun/photo/AliyunPhoto.py create mode 100644 PixivSearch/baidu/__init__.py diff --git a/PixivSearch/aliyun/__init__.py b/PixivSearch/aliyun/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/PixivSearch/aliyun/photo/AliyunPhoto.py b/PixivSearch/aliyun/photo/AliyunPhoto.py new file mode 100644 index 0000000..e5f053c --- /dev/null +++ b/PixivSearch/aliyun/photo/AliyunPhoto.py @@ -0,0 +1,79 @@ +import base64 +import calendar +import datetime +import hashlib +import hmac +import os +import random +import time +from urllib import parse + +import requests + + +def get_md5_01(file_path): + md5 = None + if os.path.isfile(file_path): + f = open(file_path, 'rb') + md5_obj = hashlib.md5() + md5_obj.update(f.read()) + hash_code = md5_obj.hexdigest() + f.close() + md5 = str(hash_code).lower() + return md5 + + +def createTransaction(HTTPMethod, filePath): + fileName = filePath.split('/')[-1] + + for Version in getBetweenDay('2017-01-01'): + print("Version={Version}".format(Version=Version)) + param = { + "Format": "JSON", + "Version": Version, + "AccessKeyId": "LTAIeS8aBuPBZxV2", + "SignatureMethod": "HMAC-SHA1", + "Timestamp": int(time.time()), + "SignatureVersion": "1.0", + "SignatureNonce": random.randint(0, 9), + "Action": "CreateTransaction", + "Ext": fileName[-fileName[::-1].index('.'):], + "Md5": get_md5_01(filePath), + "Size": os.path.getsize(filePath) + } + AccessKeySecret = b'hyPeTaDQBQs6jetYcqY0BUdpacXTH3' + canonicalQueryString = '' + for i in sorted(param.items(), key=lambda d: d[0]): + canonicalQueryString += '&' + i[0] + parse.quote('=' + str(i[1])) + # print(canonicalQueryString[1:]) + + strUrlEncoding = HTTPMethod + '&%2F&' + canonicalQueryString[1:] + print(strUrlEncoding) + stringToSign = base64.b64encode(hmac.new(AccessKeySecret, strUrlEncoding.encode('UTF-8'), 'sha1').digest()) + + server = 'https://cloudphoto.cn-shanghai.aliyuncs.com' + url = server + "?" + canonicalQueryString[1:] + '&Signature=' + stringToSign.decode('utf-8').replace('+','%20').replace('/','%2F').replace('=','%3D') + print(url) + result = requests.get(url) + + if result.status_code == 200: + break + else: + print(result.content) + time.sleep(1) + + +def getBetweenDay(begin_date): + date_list = [] + begin_date = datetime.datetime.strptime(begin_date, "%Y-%m-%d") + end_date = datetime.datetime.strptime(time.strftime('%Y-%m-%d', time.localtime(time.time())), "%Y-%m-%d") + while begin_date <= end_date: + date_str = begin_date.strftime("%Y-%m-%d") + date_list.append(date_str) + begin_date += datetime.timedelta(days=1) + return date_list + + +if __name__ == '__main__': + createTransaction("GET", "C:/Users/10295/Desktop/灵梦.png") + # print(getBetweenDay('2017-01-01')) diff --git a/PixivSearch/baidu/__init__.py b/PixivSearch/baidu/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/PixivSearch/dao/bangumi.py b/PixivSearch/dao/bangumi.py index 40e4694..7fc523b 100644 --- a/PixivSearch/dao/bangumi.py +++ b/PixivSearch/dao/bangumi.py @@ -240,7 +240,7 @@ if __name__ == '__main__': # obj = loadData( # [49052, 49053, 51525, 51526, 53407, 54180, 55295, 55296, 57255, 57256, 59288, 59289, 61559, 61560, 64034, 64035, # 67024, 67025, 69284, 73333, 73334, 74024, 74025], ['穹']) - f = getCommentSort(episodeIdToCid(172129), ['小樱']) + f = getCommentSort(episodeIdToCid(172095), []) # obj = loadData([34807341], []) for i in sorted(f["data"].items(), key=lambda d: d[1], reverse=True)[:50]: