78 lines
2.0 KiB
Python
78 lines
2.0 KiB
Python
import requests
|
|
import json
|
|
import os
|
|
import time
|
|
from threading import Timer
|
|
|
|
if not os.path.exists("database/"):
|
|
os.makedirs("database/")
|
|
|
|
if not os.path.exists("images/"):
|
|
os.makedirs("images/")
|
|
|
|
NS_id='15558'
|
|
PS5_id='15791'
|
|
PS4_id='11591'
|
|
|
|
url='https://853life.com/api/'
|
|
data={
|
|
'todo':'get_category',
|
|
'now_domain': '853life.com',
|
|
'category_id':'15558',
|
|
'item_type':'0',
|
|
}
|
|
|
|
def getdata(tyhpe):
|
|
data['category_id']=tyhpe
|
|
r=requests.post(url,data)
|
|
if(r.status_code==200):
|
|
htmlx=r.content
|
|
htmlx=str(htmlx,'utf-8')
|
|
#htmlx=htmlx.encode('utf-8').decode('unicode_escape')
|
|
jsdata=json.loads(htmlx)
|
|
for i in jsdata['item_list']:
|
|
local_image="images/"+i['main_photo']
|
|
if not os.path.isfile(local_image):
|
|
image_url="https://images.cube.mo/items/"+i['main_photo']
|
|
downloadimage=requests.get(image_url)
|
|
print("try download image:"+image_url)
|
|
if downloadimage.status_code==200:
|
|
image_f=open(local_image,"wb")
|
|
image_f.write(downloadimage.content)
|
|
image_f.close
|
|
else:
|
|
print("have image: "+local_image)
|
|
|
|
jsdump=json.dumps(jsdata,ensure_ascii=False, indent=4, separators=(',', ': '))
|
|
return jsdump
|
|
#print(jsdump)
|
|
#f=open("database/switch_"+str(int(time.time()))+".json","w",encoding='utf8')
|
|
#f.write(jsdump)
|
|
#f.close
|
|
#print("saved")
|
|
|
|
|
|
def runaway():
|
|
f=open("database/switch_"+str(int(time.time()))+".json","w",encoding='utf8')
|
|
f.write(getdata(NS_id))
|
|
f.close
|
|
print("NS_saved")
|
|
|
|
f=open("database/ps5_"+str(int(time.time()))+".json","w",encoding='utf8')
|
|
f.write(getdata(PS5_id))
|
|
f.close
|
|
print("PS5_saved")
|
|
|
|
f=open("database/ps4_"+str(int(time.time()))+".json","w",encoding='utf8')
|
|
f.write(getdata(PS4_id))
|
|
f.close
|
|
print("PS4_saved")
|
|
|
|
t = Timer(600.0, runaway)
|
|
t.start()
|
|
|
|
print("with 10 min")
|
|
|
|
|
|
t = Timer(1.0, runaway)
|
|
t.start() |