Last active
June 28, 2023 19:47
-
-
Save litefeel/e4fb635b7085a972d3e79dfc2f0c751b to your computer and use it in GitHub Desktop.
简单的腾讯鉴黄脚本
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# encoding=utf-8 | |
# api | |
# https://www.qcloud.com/document/product/275/6101 | |
import httplib, urllib | |
import json | |
import time | |
import base64 | |
import hmac, hashlib | |
import argparse | |
appid = "" | |
bucket = "" | |
secretId = "" | |
secretKey = "" | |
params = { | |
"appid": appid, | |
"bucket": bucket, | |
"url_list" : [ | |
'http://jw3dalbum-1251020887.image.myqcloud.com/6886926a3cb840c3859ff0695524349f/80_1487905993895_h09xv.jpg', | |
'http://jw3dalbum-1251020887.image.myqcloud.com/6886926a3cb840c3859ff0695524349f/80_1487906006400_lwvmf.jpg', | |
], | |
} | |
def getSign(): | |
current = int(time.time()) | |
expired = current + 1000 | |
srcStr = 'a=%s&b=%s&k=%s&t=%d&e=%d' % (appid, bucket, secretId, current, expired) | |
sign = base64.standard_b64encode(hmac.new(secretKey, srcStr, digestmod=hashlib.sha1).digest()+srcStr) | |
return sign | |
def request(): | |
headers = { "Content-type": "application/json", "Accept": "text/plain", 'Authorization':getSign() } | |
conn = httplib.HTTPConnection("service.image.myqcloud.com") | |
conn.request("POST", "/detection/porn_detect", json.dumps(params), headers) | |
response = conn.getresponse() | |
# print("%d %s" % (response.status, response.reason)) | |
data = response.read() | |
print(data) | |
conn.close() | |
# -------------- main ---------------- | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser(usage='%(prog)s [options] [url] ...', | |
description='detect porn by qcloud') | |
parser.add_argument('url', nargs='*') | |
args = parser.parse_args() | |
if len(args.url) > 0: | |
params['url_list'] = args.url | |
request() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment