由于一些原因,需要SAE上站点的日志文件,从SAE上只能按天下载,下载下来手动处理比较蛋疼,尤其是数量很大的时候。还好SAE提供了API可以批量获得日志文件下载地址,刚刚写了python脚本自动下载和合并这些文件
调用API获得下载地址
文档位置在这里
设置自己的应用和下载参数
请求中需要设置的变量如下
复制代码 代码如下:
api_url = 'http://dloadcenter.sae.sina.com.cn/interapi.php"codetitle">复制代码 代码如下:
params = dict()
params['act'] = 'log'
params['appname'] = appname
params['from'] = from_date
params['to'] = to_date
params['type'] = url_type
if url_type == 'http':
params['type2'] = url_type2
params = collections.OrderedDict(sorted(params.items()))
request = ''
for k,v in params.iteritems():
request += k+'='+v+'&'
sign = request.replace('&','')
sign += secret_key
md5 = hashlib.md5()
md5.update(sign)
sign = md5.hexdigest()
request = api_url + request + 'sign=' + sign
if response['errno'] != 0:
print '[!] '+response['errmsg']
exit()
print '[#] request success'
下载日志文件
SAE将每天的日志文件都打包成tar.gz的格式,下载保存下来即可,文件名以日期.tar.gz命名
复制代码 代码如下:
log_files = list()
for down_url in response['data']:
file_name = re.compile(r'\d{4}-\d{2}-\d{2}').findall(down_url)[0] + '.tar.gz'
log_files.append(file_name)
data = urllib2.urlopen(down_url).read()
with open(file_name, "wb") as file:
file.write(data)
print '[#] you got %d log files' % len(log_files)
合并文件
合并文件方式用trafile库解压缩每个文件,然后把文件内容附加到access_log下就可以了
复制代码 代码如下:
# compress these files to access_log
access_log = open('access_log','w');
for log_file in log_files:
tar = tarfile.open(log_file)
log_name = tar.getnames()[0]
tar.extract(log_name)
# save to access_log
data = open(log_name).read()
access_log.write(data)
os.remove(log_name)
print '[#] all file has writen to access_log'
完整代码
复制代码 代码如下:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: Su Yan <http://yansu.org>
# @Date: 2014-01-17 12:05:19
# @Last Modified by: Su Yan
# @Last Modified time: 2014-01-17 14:15:41
import os
import collections
import hashlib
import urllib2
import json
import re
import tarfile
# settings
# documents http://sae.sina.com.cn/"wb") as file:
file.write(data)
print '[#] you got %d log files' % len(log_files)
# compress these files to access_log
access_log = open('access_log','w');
for log_file in log_files:
tar = tarfile.open(log_file)
log_name = tar.getnames()[0]
tar.extract(log_name)
# save to access_log
data = open(log_name).read()
access_log.write(data)
os.remove(log_name)
print '[#] all file has writen to access_log'
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新日志
- 《原神》「星路拾忆」网页活动壁纸展示
- 群星.2024-祝你幸福!电影原声带【阿里巴巴】【FLAC分轨】
- 于台烟.2004-执着【乾坤唱片】【WAV+CUE】
- 黄品源.2004-感谢·情人(引进版)【滚石】【WAV+CUE】
- 《最终幻想16》评测:游、戏两难全的系列转折
- 《纸嫁衣》五部打包¥104,《鬼泣5》仅需¥44
- 《崩坏:星穹铁道》造物大赛卷出新高度
- 《王菲 菲常传奇 2CD》[WAV+CUE][950MB]
- 《王菲 空灵独味唱腔 非常传奇 紫水晶2CD》[WAV+CUE][860MB]
- 《车载专业测试王1号 极品音质》[WAV/分轨][980MB]
- 炉石传说的国服回归送什么奖励 炉石传说9.25回归最新消息介绍
- 云顶之弈最强阵容汇总2024 云顶之弈最强阵容搭配最新版本
- S14lol全球总决赛在哪观看 lol全球总决赛观赛直播地址汇总
- 黄思婷2011-感谢天[豪记唱片][WAV+CUE]
- 孙淑媚2013-太阳[台湾首版][WAV+CUE]