def main(): logging.debug("log4qiniu starting") signal.signal(signal.SIGINT, onsignal_term) arguments = docopt(__doc__, version='1.0.0rc1') rebuild_options(arguments) domains = [".qianbaocard.com"] log_date = get_date(delay_days) auth = qiniu.Auth(access_key, secret_key) cdn = qiniu.CdnManager(auth) logging.info("log4qiniu get data %s at %s" % (domains, log_date)) result = cdn.get_log_list_data(domains, log_date) if result[0] is None: logging.error("log4qiniu download failed") sys.exit(1) for v in result[0]["data"].values(): for log in v[0:max_download]: url = log["url"] if verbose > 0: print "downloading: %s" % (url) logging.info("log4qiniu downloading %s" % (url)) name = log["name"] r = requests.get(url) write_disk(BASE_DIR, name, r.content) if is_exited: break cmd = "gunzip -f %s/*.gz" % (BASE_DIR) os.system(cmd) logging.debug("log4qiniu complate")
def cdn_flush(key): auth = qiniu_auth() cdn_manager = qiniu.CdnManager(auth) domine = qiniu_config['domine'] need_flush_url = domine + key # 需要刷新的文件链接 urls = [ need_flush_url, ] # URL刷新链接 refresh_url_result = cdn_manager.refresh_urls(urls) return
os.system('zip -r -9 "Minecraft-Mod-Language-Modpack.zip" "assets" "pack.mcmeta" "pack.png" "README.md" "LICENSE"') # 多加一步,上传到七牛云 # 从环境变量获取 Access Key 和 Secret Key access_key = os.getenv('Access_Key') secret_key = os.getenv('Secret_Key') # 构建鉴权对象 q = qiniu.Auth(access_key, secret_key) # 要上传的空间 bucket_name = 'langpack' # 上传到七牛后保存的文件名 key = 'Minecraft-Mod-Language-Modpack.zip'; # 生成上传 Token,可以指定过期时间等 token = q.upload_token(bucket_name, key, 120) # 要上传文件的本地路径 localfile = './Minecraft-Mod-Language-Modpack.zip' ret, info = qiniu.put_file(token, key, localfile) print(info) assert ret['key'] == key assert ret['hash'] == qiniu.etag(localfile) # 刷新七牛云文件缓存 cdn_manager = qiniu.CdnManager(q) # 需要刷新的文件链接 urls = [ 'http://downloader.meitangdehulu.com/Minecraft-Mod-Language-Modpack.zip' ] # 刷新链接 refresh_url_result = cdn_manager.refresh_urls(urls) print(refresh_url_result)
def __init__(self, access_key, secret_key): self.secret_key = secret_key self.access_key = access_key self.auth = qiniu.Auth(self.access_key, self.secret_key) self.bucket = qiniu.BucketManager(self.auth) self.cdn = qiniu.CdnManager(self.auth)