oracle插入数据

import requests
from xpinyin import Pinyin
import cx_Oracle
from common.Excel import ExcelUtil
import os

filePath = "D:\\test_demo\\Excel\\test.xlsx"
sheetName = "Sheet1"
data = ExcelUtil(filePath, sheetName).dict_data()
brand_id = 0
id = 1
for i in data:
url = i['url']
name1 = i['name']
pin = Pinyin()

headers = {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"X-Requested-With": "XMLHttpRequest",
"Host": "tq.365taoquan.cn",
"Cookie": "JSESSIONID=350B1AA3EFD543460D552E85664036E7",
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 12_4 like Mac OS X) AppleWebKit/605.1.15 "
"(KHTML, like Gecko) Mobile/15E148 MicroMessenger/7.0.5(0x17000523) NetType/WIFI Language/zh_CN",
"Referer": "http://tq.365taoquan.cn/seller/?productId=23&agentId=-1&enableWK=YES",
"Connection": "keep-alive"
}
brand_id += 1

r = requests.get(url, headers=headers)
jsonRes = r.json()
g = Pinyin()
name = g.get_initials(name1, "").lower()
dirname = 'E:\\商品图片\\%s' % name
os.mkdir(dirname)
for i in jsonRes:
print(i['name'])
g = Pinyin()
name = g.get_initials(name1, "").lower()
file_name1 = i['name']

if file_name1.find("|") != -1:
file_name1 = file_name1.replace("|", "", file_name1.count("|"))
if file_name1.find("/") != -1:
file_name1 = file_name1.replace("/", "", file_name1.count("/"))
if file_name1.find("/") != -1:
file_name1 = file_name1.replace("(", "", file_name1.count("("))
if file_name1.find("/") != -1:
file_name1 = file_name1.replace(")", "", file_name1.count(")"))

test2 = g.get_initials(file_name1, "").lower()
# print(i['name'], i['remark'], i['collectPrice'], i['sellingPrice'], i['officialPrice'], i['useExplain'])

p = requests.get(i['remark'])

with open(dirname + "\\%s.jpg" % test2, 'wb') as jpg:
jpg.write(p.content)

image = 'http://static.100bm.cn/sup_images_service/' + name + '/' + test2 + '.jpg'

conn = cx_Oracle.connect('q_sup/123456@192.168.0.136:1521/ORCL136')
cur = conn.cursor()
sql = '''
declare
begin
insert into pt_card_product t
(t.ID,
t.NAME,
t.IMAGE,
t.OFFICIAL_PRICE,
t.STOCK,
t.SALE_NUM,
t.LIMIT_NUM,
t.BRAND_ID,
t.WARRANTY,
t.VALIDITY_PERIOD,
t.USE_INTRODUCTION,
t.REMARK,
t.CREATE_TIME,
t.CREATE_USER,
t.UPDATE_TIME,
t.UPDATE_USER,
t.DEL)
values
( '%s',
'%s',
'%s',
'%s',
'1000',
'0',
'10',
'%s',
'%s',
'%s',
'%s',
'0',
sysdate,
'0',
sysdate,
'1',
'1');
commit;
end;
''' % (
id, i['name'], image, i['officialPrice'], brand_id, '购买后次日10:00前', '购买后一天内激活绑定,3年内有效',
i['useExplain'] or "-")
print(i['useExplain'])
cur.execute(sql)
conn.commit()
id += 1

posted on 2019-09-07 13:57  WapN  阅读(262)  评论(0编辑  收藏  举报

导航