Files
you-xi-pa-chong/SMDL_NS_POST.py
T

74 lines
2.0 KiB
Python

import requests
import json
import re
import os
import time
if not os.path.exists("database/"):
os.makedirs("database/")
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
file_name="database/switch_"+str(int(time.time()))+".json"
f=open(file_name,"w",encoding='utf8')
f.write(getdata(NS_id))
f.close
print("NS_saved")
f=open(file_name,'r',encoding='utf8')
jsdata=json.loads(f.read())
url='http://beta.lmve.net/index.php?app=pricetrend&ac=do&ts=add_more'
for i in jsdata['item_list']:
post_data={}
post_data['SUK']=i['item_no']
post_data['platform']="NS"
post_data['salestart']=i['salestart']
post_data['price']=i['nowprice']
stock=re.findall("[0-9]+",i['stock_text'])[0]
post_data['const']=stock
post_data['price_type']="MOP"
post_data['sources']="reptile"
post_data['shop']="数码动力"
#print(post_data)
r=requests.post(url,post_data)
if(r.status_code==200):
htmlx=r.text
print(htmlx)