#获取截图
import sys
import types
# import url
import http.client
import time
import datetime
import urllib.request
import json
import base64
# def login_first():
# url = "http://103.244.254.21/cacti/index.php?action=login&__csrf_magic=sid:ee4027db9b9611d1345e38b4fe126a45ebde0e2d,1503888534&login_username=xxx&login_password=xxx"
# conn = http.client.HTTPConnection("103.244.254.21")
# conn.request(method="GET",url=url)
# response = conn.getresponse()
# res= response.read()
# print (res)
# denglu
# login_first()
d_url = 'http://103.244.254.21/cacti/graph_json.php?rra_id=0&graph_height=150&graph_width=550'
node_1 = "tree_anchor-3"
node_2 = "tree_anchor-4"
node_3 = "tree_anchor-5"
T_anchor_3=[5,104,224,237,222,240,226,225,482,133,135,18]
T_anchor_4=[293,255,294,292,295,296,251,28,30,539,298,288,253,254,300,305,32,352,282,340,194,347,215,536,533,537,444,513,425,426,384]
T_anchor_5=[42,52,233,452,224,225,226,240,237,222,163,246,247,357]
# local_graph_id
# graph_start=
# graph_end=
def get_img():
url = ""
today = datetime.date.today()
# time_1=time.strftime("%Y-%m-%d-1")
# time_2=time.strftime("%Y-%m-%d 00:00")
yesterday = today - datetime.timedelta(days=1)
date_1 = str(yesterday)+" 00:00"
date_2 = str(today)+" 00:00"
time_1 = time.strptime(date_1, "%Y-%m-%d %H:%M")
time_2 = time.strptime(date_2, "%Y-%m-%d %H:%M")
timestamp_1 = int(time.mktime(time_1))
timestamp_2 = int(time.mktime(time_2))
#print(timestamp_1,timestamp_2)
def get_json():
headers = {
'Connection':'keep-alive',
'Cache-Control':'max-age=0',
'Accept': 'text/html, */*; q=0.01',
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36',
'DNT':'1',
'Accept-Encoding': 'gzip, deflate, sdch',
'Accept-Language': 'zh-CN,zh;q=0.8,ja;q=0.6',
'Cookie': 'Cacti=o7rhms2forbbc1kfe6cokjr3e3'
}
data = None
req = urllib.request.Request(url, data, headers)
response = urllib.request.urlopen(req)
html = response.read()
s = json.loads(html)
# print(s.keys())
return s["image"]
if __name__ == "__main__":
# img_name=time.strftime("%Y-%m-%d 00:00")
for i in T_anchor_3:
url = "%s&graph_start=1503763200&graph_end=1503849600&local_graph_id=%s"%(d_url,i)
# url=d_url,'&graph_start=1503763200&graph_end=1503849600&local_graph_id=',i
#print(url)
get_img()
base_json=get_json()
imgdata=base64.b64decode(base_json)
#b64decode()为解码,b64encode为编码
file_name='%s.png'%i
print(file_name)
file=open(file_name,'wb')
file.write(imgdata)
file.close()
time.sleep(1)