Commit e6285c57 by 高宇强

gyq

parent 862ede08
...@@ -36,10 +36,19 @@ def SaveLogoResource(inputdata,msg_id,cur): ...@@ -36,10 +36,19 @@ def SaveLogoResource(inputdata,msg_id,cur):
# params = json.dumps(data, ensure_ascii=False) # params = json.dumps(data, ensure_ascii=False)
sptagdata = [] sptagdata = []
try: try:
sptagdata = requests.post(sptagapi, json=data1).json()#得到logoid sptagdata1 = requests.post(sptagapi, json=data1).json() # 得到logoid
# 过滤行业
idlist = []
for idinfo in sptagdata1:
idlist.append(idinfo["id"])
select_sql = "select * from logo_desc where id = %s" % idinfo["id"]
cur.execute(select_sql)
msg = cur.fetchone()
if msg["profession"] == inputdata["profession"]:
sptagdata.append({"id": msg["id"]})
except:#若语义分析出错,随机取50个 except:#若语义分析出错,随机取50个
select_sql = 'SELECT id FROM `logo_desc` WHERE type = "standard" and mark = 0 and id >= ( SELECT floor(RAND() ' \ select_sql = 'SELECT id FROM `logo_desc` WHERE type = "standard" and mark = 0 and profession = %s and id >= ( SELECT floor(RAND() ' \
'* (SELECT MAX(id) FROM `logo_desc`))) ORDER BY id LIMIT 50' '* (SELECT MAX(id) FROM `logo_desc`))) ORDER BY id LIMIT 50' % inputdata["profession"]
cur.execute(select_sql) cur.execute(select_sql)
msgs = cur.fetchall() msgs = cur.fetchall()
for ms in msgs: for ms in msgs:
...@@ -88,8 +97,6 @@ def SaveLogoResource(inputdata,msg_id,cur): ...@@ -88,8 +97,6 @@ def SaveLogoResource(inputdata,msg_id,cur):
#把生成的单个Logo信息存入数据库 #把生成的单个Logo信息存入数据库
def SaveSingleLogo(inputdata): def SaveSingleLogo(inputdata):
print('--------------------------开始生成logo---------------------')
starttime = time.time()
try: try:
#3.调用云飞生成logo方法,把json_str传过去 #3.调用云飞生成logo方法,把json_str传过去
#print("调用云飞生成logo方法") #print("调用云飞生成logo方法")
...@@ -128,8 +135,6 @@ def SaveSingleLogo(inputdata): ...@@ -128,8 +135,6 @@ def SaveSingleLogo(inputdata):
json_str = customizelogosmall.gen_main(gen_json) json_str = customizelogosmall.gen_main(gen_json)
if json_str["status"]: if json_str["status"]:
js=json_str["image_gen_url"] js=json_str["image_gen_url"]
endtime = time.time()
print('--------------------------结束生成logo---------------------',endtime-starttime)
return True,js return True,js
else: else:
...@@ -398,9 +403,16 @@ def ChangeABatch(inputdata): ...@@ -398,9 +403,16 @@ def ChangeABatch(inputdata):
res["font_description"] = font_dec res["font_description"] = font_dec
Update_sql = "UPDATE `logo_msg`.`logo_res` SET `pic_url`=%s,`font_id`=%s WHERE `id`=%s " Update_sql = "UPDATE `logo_msg`.`logo_res` SET `pic_url`=%s,`font_id`=%s WHERE `id`=%s "
if not res["pic_url"]: if not res["pic_url"]:
iserror, res["pic_url"] = SaveSingleLogo(res) #改成调服务
#c_url = 'http://127.0.0.1:5000/api/createlogo'
c_url = 'http://ailogo-CreatLogo-Serverice/api/createlogo'
data1 = requests.post(c_url, json=res).json()
if data1["status"] == 0:
res["pic_url"] = data1["data"]
tub = (res["pic_url"], res["font_id"], res["id"]) tub = (res["pic_url"], res["font_id"], res["id"])
cur.execute(Update_sql, tub) cur.execute(Update_sql, tub)
else:
iserror = False
try: try:
connection.commit() connection.commit()
except: except:
...@@ -547,9 +559,16 @@ def ReturnLogoInfo(inputdata,curpage,pagesize): ...@@ -547,9 +559,16 @@ def ReturnLogoInfo(inputdata,curpage,pagesize):
Update_sql = "UPDATE `logo_msg`.`logo_res` SET `pic_url`=%s,`font_id`=%s WHERE `id`=%s " Update_sql = "UPDATE `logo_msg`.`logo_res` SET `pic_url`=%s,`font_id`=%s WHERE `id`=%s "
for r in list_r: for r in list_r:
if not r["pic_url"]: if not r["pic_url"]:
iserror, r["pic_url"] = SaveSingleLogo(r) # 改成调服务
tub = (r["pic_url"], r["font_id"], r["id"]) #c_url = 'http://127.0.0.1:5000/api/createlogo'
cur.execute(Update_sql, tub) c_url = 'http://ailogo-CreatLogo-Serverice/api/createlogo'
data1 = requests.post(c_url, json=r).json()
if data1["status"] == 0:
r["pic_url"] = data1["data"]
tub = (r["pic_url"], r["font_id"], r["id"])
cur.execute(Update_sql, tub)
else:
iserror = False
try: try:
connection.commit() connection.commit()
except: except:
......
#!/usr/bin/python3
# -*- coding: utf-8 -*- #文件也为UTF-8
import LogoReqAnalysis
import LogoGenerator
import pymysql,requests
import random
import re
import customizelogosmall
import json
import time
#随机取50个descid,其中15个模板id,35个logoid
def GetDescId(sptagdata,templatedata):
returnlist = []
if len(templatedata) <= 15:
returnlist.extend(templatedata)
else:
returnlist.extend(random.sample(templatedata,15))
if len(sptagdata) <= (50- len(returnlist)):
returnlist.extend(sptagdata)
else:
returnlist.extend(random.sample(sptagdata, 50- len(returnlist)))
return returnlist
#把计算的LOGO结果存入数据库
def SaveLogoResource(inputdata,msg_id,cur):
#connection = pymysql.connect(host='172.16.18.140', port=3306, user='root', passwd='x8BOQk./1}bC&=+', db='logo_msg')
#connection = pymysql.connect(host='43.247.184.94', port=8898, user='root', passwd='x8BOQk./1}bC&=+', db='logo_msg')
#cur = connection.cursor()
try:
# 调用process方法或服务
sptagapi = 'http://172.16.18.140:8009/gsb/api/textquery'
text = inputdata["title"]
data1 = {"input_text":text } # 接口访问参数
# params = json.dumps(data, ensure_ascii=False)
sptagdata = []
try:
sptagdata = requests.post(sptagapi, json=data1).json()#得到logoid
except:#若语义分析出错,随机取50个
select_sql = 'SELECT id FROM `logo_desc` WHERE type = "standard" and mark = 0 and id >= ( SELECT floor(RAND() ' \
'* (SELECT MAX(id) FROM `logo_desc`))) ORDER BY id LIMIT 50'
cur.execute(select_sql)
msgs = cur.fetchall()
for ms in msgs:
sptagdata.append({"id": ms["id"]})
#sptagdata = [{"id":"1"},{"id":"2"},{"id":"3"}]
#取模板id
templatedata = []
select_sql = 'select id from logo_desc where type = "template" '
cur.execute(select_sql)
msgs = cur.fetchall()
for ms in msgs:
templatedata.append({"id":ms["id"]})
#取30条语义分析结果都是logo的,再随机20条模板
descList = GetDescId(sptagdata,templatedata)
for data in descList:
select_sql='select id,first_color,sec_color,height,width,profession,description,textpos,' \
'originality,type from logo_desc where id = "%s"' % data["id"]
cur.execute(select_sql)
msg=cur.fetchone()
insert_sql='insert into logo_res (logo_id,first_color,sec_color,height,width,profession,description,textpos,' \
'originality,type,msg_id) VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)'
logo_id = msg["id"]
first_color = msg["first_color"]
sec_color = msg["sec_color"]
height = msg["height"]
width = msg["width"]
profession = msg["profession"]
description = msg["description"]
originality = msg["originality"]
textpos = msg["textpos"]
type = msg["type"]
#msg_id = msg_id
tup = (logo_id, first_color, sec_color, height, width, profession, description,textpos,originality,
type,msg_id)
#print(str(tup))
cur.execute(insert_sql, tup)
#connection.commit()
#connection.close()
return True
except Exception as e:
#print(str(e))
#connection.rollback()
#connection.close()
return False
#把生成的单个Logo信息存入数据库
def SaveSingleLogo(inputdata):
try:
#3.调用云飞生成logo方法,把json_str传过去
#print("调用云飞生成logo方法")
if inputdata["type"] == "standard":
gen_json = {
'brand_text': inputdata['title'], # 品牌名称
'brand_font': inputdata["font_url"], # 字体路径
'brand_color': inputdata['first_color'], # 字体颜色
'brand_location': inputdata['textpos'], # 左右上下
'slogan_text': inputdata['subtitle'], # 标语名称
'slogan_font': inputdata["font_url"], # 字体路径
'slogan_color': inputdata['sec_color'], # 标语颜色
'logo_url': inputdata['log_url'] # 图片地址
}
json_str = LogoGenerator.gen_main(gen_json)
else:
#因目前只有八个模板,且是画的,需要把数据库的模板id对应到1-8的模板上
model_id = 1
if inputdata["logo_id"] > 76 and inputdata["logo_id"] < 83:
model_id = inputdata["logo_id"] - 76
elif inputdata["logo_id"] > 84 and inputdata["logo_id"] < 87:
model_id = inputdata["logo_id"] - 78
gen_json = {
'brand_text': inputdata['title'], # 品牌名称
'brand_font': inputdata["font_url"], # 字体路径
'brand_color': inputdata['first_color'], # 字体颜色
'brand_location': inputdata['textpos'], # 左右上下
'slogan_text': inputdata['subtitle'], # 标语名称
'slogan_font': inputdata["font_url"], # 字体路径
'slogan_color': inputdata['sec_color'], # 标语颜色
'logo_url': inputdata['log_url'], # 图片地址
'model_id': model_id # 目前是数据库id减76,用于满足1-8的要求
}
json_str = customizelogosmall.gen_main(gen_json)
if json_str["status"]:
js=json_str["image_gen_url"]
return True,js
else:
return False, ""
except Exception as e:
return False,""
#保存用户输入的信息
def SaveInputdata(inputdata):
connection = pymysql.connect(host='43.247.184.94', port=8898, user='root', passwd='x8BOQk./1}bC&=+', db='logo_msg')
cur = connection.cursor()
try:
# 把用户信息插入数据库
insert_sql='insert into input_msg (title,subtitle,profession,description) VALUES (%s,%s,%s,%s)'
data =inputdata
title=data["title"]
subtitle=data["subtitle"]
profession=data["profession"]
description=data["description"]
tub=(title,subtitle,profession,description)
cur.execute(insert_sql,tub)
connection.commit()
connection.close()
return True
except:
connection.close()
return False
#分页输出
def GetPaging(random_list,curpage,pagesize):
logo=[]
for i in range(1,len(random_list)):
for it in random_list:
dict=it
logo.append(dict)
total=len(random_list)
max_page,a = divmod(total,pagesize)
if a > 0:
max_page = max_page + 1
# print(a) #0
# print(max_page)#2
while True:
if curpage< 1 or curpage > max_page:
return "页码错误"
else:
start = (curpage-1)* pagesize
end = curpage * pagesize
data = random_list[start:end]
for item in data:
logo=item
print(item)
return logo
#获取Logo信息
def GetLogoInfo(inputdata):
#1.根据用户信息获取信息ID
connection = pymysql.connect(host='43.247.184.94', port=8898, user='root', passwd='x8BOQk./1}bC&=+', db='logo_msg')
cur = connection.cursor()
print("根据信息获取id")
select_sql='select * from logo_task where title="%s" and subtitle="%s" and profession="%s"' \
' and description = "%s"' % (inputdata["title"],inputdata["subtitle"]
,inputdata["profession"],inputdata["description"])
insert_msgid_sql='insert into logo_task (title,subtitle,profession,description,`date`,msg_id) select ' \
'title,subtitle,profession,description,now(),id from input_msg where input_msg.title="%s" ' \
'and input_msg.subtitle="%s" and input_msg.profession="%s"' \
' and input_msg.description = "%s"' % (inputdata["title"],inputdata["subtitle"]
,inputdata["profession"],inputdata["description"])
#insert_logo_id='update logo_task,logo_res set logo_task.logo_id =logo_res.logo_id where `logo_task`.`msg_id`=%s '
updatet_msgid_sql='update logo_task, input_msg set logo_task.msg_id = input_msg.id where ' \
'logo_task.title=input_msg.title and logo_task.subtitle=input_msg.subtitle and ' \
'logo_task.profession=input_msg.profession and logo_task.description=input_msg.description'
select_msg_id='select msg_id from logo_task where title="%s" and subtitle="%s" and profession="%s"' \
' and description = "%s"' % (inputdata["title"],inputdata["subtitle"]
,inputdata["profession"],inputdata["description"])
#select_logo_id='select logo_id from logo_task where msg_id=%s' #kong
update_res_msg_id='update logo_res set msg_id=%s'
cur.execute(select_sql)
datas=cur.fetchone()
print(datas)
if datas ==None:
cur.execute(insert_msgid_sql)
print(insert_msgid_sql)
connection.commit()
cur.execute(select_msg_id)
msg_id=cur.fetchone()
msg_id=max(msg_id)
cur.execute(update_res_msg_id,msg_id)
connection.commit()
# cur.execute(insert_logo_id,msg_id)
# connection.commit()
# print(insert_logo_id)
# cur.execute(select_logo_id,msg_id)
# logo_ids=cur.fetchone()
# print(logo_ids)
else:
cur.execute(updatet_msgid_sql)
connection.commit()
cur.execute(select_msg_id)
msg_id=cur.fetchone()
msg_id=max(msg_id)
# print(msg_id)
cur.execute(update_res_msg_id,msg_id)
connection.commit()
# cur.execute(insert_logo_id,msg_id)
# connection.commit()
# print(insert_logo_id)
# cur.execute(select_logo_id,msg_id)
# logo_ids=cur.fetchone()
# print(logo_ids)
# logo_ids=max(logo_ids)
# tup=(msg_id,logo_ids)
# cur.execute(update_res_msg_id,tup)
# print(update_res_msg_id)
# print("haha")
#2.根据信息id获取所有logo信息
logoinfo=[]
select_sql='select * from logo_res where msg_id=%s' %msg_id
cur.execute(select_sql)
datas = cur.fetchall()
lit=[]
infoid=""
for itm in datas:
res = {}
res["id"] = itm[0]
res["logo_id"]=itm[1]
res["first_color"] = itm[2]
res["sec_color"] = itm[3]
res["height"] = itm[4]
res["width"] = itm[5]
res["profession"] = itm[6]
res["description"] = itm[7]
res["textpso"] = itm[8]
res["pic_url"] = itm[9]
res["originality"] = itm[10]
res["groundcolor"]=itm[11]
res["people"]=itm[12]
res["type"]=itm[13]
lit.append(res)
#3.取出的信息做随机
random_list = random.sample(lit, len(lit))
print(len(random_list))
print(random_list)
#4.根据curpage,pagesize返回信息logoinfo
#logoinfo=GetPaging(random_list,curpage,pagesize)
logoinfo=random_list
#logoinfo=lit
#5.判断URL是否为空,
# 若空,代表未生成,调用SaveSingleLogo(inputdata)生成logo
for it in logoinfo:
print("-=-=-=-=-=-==")
print(it)
if it["pic_url"]==None:
SaveSingleLogo(it,inputdata)
print(it["pic_url"])
sql='select * from logo_res'
cur.execute(sql)
logos=cur.fetchall()
print(logos)
# connection.close()
print('---======================')
l=[]
for logo in logos:
l=logo
print(l)
logoinfo.append(l)
print(logoinfo)
return logoinfo
#换一批
def ChangeABatch(inputdata):
connection = pymysql.connect(host='172.16.18.140', port=3306, user='root', passwd='x8BOQk./1}bC&=+', db='logo_msg')
#connection = pymysql.connect(host='43.247.184.94', port=8898, user='root', passwd='x8BOQk./1}bC&=+', db='logo_msg')
cur = connection.cursor(cursor=pymysql.cursors.DictCursor)
try:
select_sql = 'select * from input_msg where title="%s" and subtitle="%s" and profession="%s"' \
' and description = "%s"' % (inputdata["title"], inputdata["subtitle"]
, inputdata["profession"], inputdata["description"])
cur.execute(select_sql)
data = cur.fetchone()
res_list = []
if data and data["isasy"]:#说明已做过生成
mgs_id = data["id"]
select_sql = "select * from logo_res where msg_id = %s and (pic_url is null or pic_url = '') " % mgs_id
cur.execute(select_sql)
data = cur.fetchall()
if data:#如果存在未生成图片的
len1 = 10
if len(data) < 10:
len1 = len(data)
random_list = random.sample(data, len1)
for dl in random_list:
dict1 = {
"id": dl["id"],
"logo_id": dl["logo_id"],
"font_id": dl["font_id"],
"title":inputdata["title"],
"subtitle":inputdata["subtitle"],
"first_color": dl["first_color"],
"sec_color": dl["sec_color"],
"textpos": dl["textpos"],
"type": dl["type"],
"pic_url": ""
}
res_list.append(dict1)
if len(res_list) < 10:#说明未生成的小于10个,去已生成的中再取其他的
len1 = 10-len(res_list)
select_sql = "select * from logo_res where msg_id = %s and (pic_url is not null and pic_url <> '') " % mgs_id
cur.execute(select_sql)
data = cur.fetchall()
random_list = random.sample(data, len1)
for dl in random_list:
dict1 = {
"id": dl["id"],
"logo_id": dl["logo_id"],
"font_id": dl["font_id"],
"title": inputdata["title"],
"subtitle": inputdata["subtitle"],
"first_color": dl["first_color"],
"sec_color": dl["sec_color"],
"textpos":dl["textpos"],
"type": dl["type"],
"pic_url": dl["pic_url"]
}
res_list.append(dict1)
#对res_list中的数据做处理
# 取所有字体
fontlist = []
select_sql = 'select * from logo_font '
cur.execute(select_sql)
data = cur.fetchall()
for item in data:
imagepath = re.sub(r'http://43.247.184.94:7170/', '', item["fonts_url"])
baseimagepath = '/data/' + imagepath
fontlist.append({"id": item["id"], "fonts_url": baseimagepath, "font_name": item["name"],
"font_description": item["description"]})
iserror = True
for res in res_list:
# qu一次log_url
select_sql = "select * from logo_desc where id = %s" % res["logo_id"]
cur.execute(select_sql)
data22 = cur.fetchone()
if data22:
res["log_url"] = data22["pic_url"]
res["color_description"] = data22["description"]
else:
res["log_url"] = ""
res["color_description"] = ""
#随机一个字体
randnum = random.randint(0, len(fontlist) - 1)
font_url = fontlist[randnum]["fonts_url"]
font_id = fontlist[randnum]["id"]
font_name = fontlist[randnum]["font_name"]
font_dec = fontlist[randnum]["font_description"]
res["font_id"] = font_id
res["font_url"] = font_url
res["font_name"] = font_name
res["font_description"] = font_dec
Update_sql = "UPDATE `logo_msg`.`logo_res` SET `pic_url`=%s,`font_id`=%s WHERE `id`=%s "
if not res["pic_url"]:
iserror, res["pic_url"] = SaveSingleLogo(res)
tub = (res["pic_url"], res["font_id"], res["id"])
cur.execute(Update_sql, tub)
try:
connection.commit()
except:
connection.rollback()
iserror = False
connection.close()
if iserror:
if iserror:
return True, len(res_list), res_list
else:
return False, 0, []
else:#说明该任务信息还没有做过生成
connection.close()
return ReturnLogoInfo(inputdata,1,10)
except Exception as e:
return False,0,[]
#返回logo信息
def ReturnLogoInfo(inputdata,curpage,pagesize):
starttime = time.time()
connection = pymysql.connect(host='172.16.18.140', port=3306, user='root', passwd='x8BOQk./1}bC&=+', db='logo_msg')
#connection = pymysql.connect(host='43.247.184.94', port=8898, user='root', passwd='x8BOQk./1}bC&=+', db='logo_msg')
cur = connection.cursor(cursor=pymysql.cursors.DictCursor)
iserror = True
try:
select_sql='select * from input_msg where title="%s" and subtitle="%s" and profession="%s"' \
' and description = "%s"' % (inputdata["title"],inputdata["subtitle"]
,inputdata["profession"],inputdata["description"])
cur.execute(select_sql)
data=cur.fetchone()
msg_id = ""
isasy = 0#是否做过语义分析
if data:#若信息存在
#取msg_id
msg_id = data["id"]
isasy = data["isasy"]
insert_sql = 'INSERT INTO `logo_msg`.`logo_task` ( `title`, `subtitle`, `profession`, `description`, `date`, `msg_id`) VALUES (%s,%s,%s,%s,%s,%s)'
tub = (inputdata["title"],inputdata["subtitle"] ,inputdata["profession"],inputdata["description"], time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),msg_id)
cur.execute(insert_sql,tub)
else:#信息不存在
#插入信息表
insert_sql = 'INSERT INTO `logo_msg`.`input_msg` (`title`, `subtitle`, `profession`, `description`) VALUES (%s,%s,%s,%s)'
tub = (inputdata["title"],inputdata["subtitle"] ,inputdata["profession"],inputdata["description"])
cur.execute(insert_sql,tub)
select_sql = 'select * from input_msg where title="%s" and subtitle="%s" and profession="%s"' \
' and description = "%s"' % (inputdata["title"], inputdata["subtitle"]
, inputdata["profession"], inputdata["description"])
cur.execute(select_sql)
data1 = cur.fetchone()
if data1:
msg_id = data1["id"]
insert_sql = 'INSERT INTO `logo_msg`.`logo_task` ( `title`, `subtitle`, `profession`, `description`, `date`, `msg_id`) VALUES (%s,%s,%s,%s,%s,%s)'
tub = (inputdata["title"],inputdata["subtitle"] ,inputdata["profession"],inputdata["description"], time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),msg_id)
cur.execute(insert_sql,tub)
#connection.commit()
if not isasy:
#如果没做过语义分析,调用语义分析
if not SaveLogoResource(inputdata,msg_id,cur):
iserror = False; #语义分析失败
else:
update_sql = "update input_msg set isasy = %s where id = %s"
tub = (1,msg_id)
cur.execute(update_sql, tub)
#根据id取语义分析的结果
select_sql = 'select * from logo_res where msg_id = "%s"' % msg_id
#cur = connection.cursor(cursor=pymysql.cursors.DictCursor)
cur.execute(select_sql)
res_list = cur.fetchall()
re_count = 30
if len(res_list) <30:
re_count = len(res_list)
random_list = random.sample(res_list, re_count)
#取所有字体
fontlist = []
select_sql = 'select * from logo_font '
cur.execute(select_sql)
data = cur.fetchall()
for item in data:
imagepath = re.sub(r'http://43.247.184.94:7170/', '', item["fonts_url"])
baseimagepath = '/data/' + imagepath
fontlist.append({"id": item["id"], "fonts_url": baseimagepath, "font_name": item["name"],
"font_description": item["description"]})
#把结果分页,根据分页结果
nfen = 1 #从第一页开始
fen_dict = {}#分页信息
temp_list = []
for res in random_list:
dict1= {}
dict1["id"] = res["id"]
dict1["title"] = inputdata["title"]
dict1["subtitle"] = inputdata["subtitle"]
dict1["first_color"] = res["first_color"]
dict1["sec_color"] = res["sec_color"]
dict1["height"] = res["height"]
dict1["width"] = res["width"]
dict1["profession"] = res["profession"]
dict1["description"] = res["description"]
dict1["textpos"] = res["textpos"]
dict1["pic_url"] = res["pic_url"]
dict1["originality"] = res["originality"]
dict1["groundcolor"] = res["groundcolor"]
dict1["type"] = res["type"]
dict1["logo_id"] = res["logo_id"]
#qu一次log_url
select_sql = "select * from logo_desc where id = %s" % res["logo_id"]
cur.execute(select_sql)
data22 = cur.fetchone()
if data22:
dict1["log_url"] = data22["pic_url"]
dict1["color_description"] = data22["description"]
else:
dict1["log_url"] = ""
dict1["color_description"] = ""
# 随机一个字体
randnum = random.randint(0, len(fontlist) - 1)
font_url = fontlist[randnum]["fonts_url"]
font_id = fontlist[randnum]["id"]
font_name = fontlist[randnum]["font_name"]
font_dec = fontlist[randnum]["font_description"]
dict1["font_id"] = font_id
dict1["font_url"] = font_url #
dict1["font_name"] = font_name
dict1["font_description"] = font_dec
temp_list.append(dict1)
if len(temp_list) == pagesize:
fen_dict[nfen] = temp_list
nfen += 1
temp_list = []
if temp_list:
fen_dict[nfen] = temp_list
#根据前端的当前page和pagesize
if curpage > len(fen_dict):
curpage = len(fen_dict)
list_r = fen_dict[curpage]
Update_sql = "UPDATE `logo_msg`.`logo_res` SET `pic_url`=%s,`font_id`=%s WHERE `id`=%s "
for r in list_r:
if not r["pic_url"]:
iserror, r["pic_url"] = SaveSingleLogo(r)
tub = (r["pic_url"], r["font_id"], r["id"])
cur.execute(Update_sql, tub)
try:
connection.commit()
except:
connection.rollback()
iserror = False
connection.close()
if iserror:
endtime = time.time()
print('------------generator logo time:', endtime - starttime)
return True, re_count, list_r
else:
endtime = time.time()
print('------------generator logo time:', endtime - starttime)
return False,0,[]
except Exception as e:
try:
connection.rollback()
connection.close()
endtime = time.time()
print('------------generator logo time:', endtime - starttime)
return False, 0, []
except:
endtime = time.time()
print('------------generator logo time:', endtime - starttime)
return False, 0, []
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
from flask import Flask, render_template, request from flask import Flask, render_template, request
import json import json
import pymysql import pymysql,sys,os
from flask_cors import CORS from flask_cors import CORS
import LogoManage import LogoManage
import GetLogo import GetLogo
...@@ -15,6 +15,8 @@ import CreateScene ...@@ -15,6 +15,8 @@ import CreateScene
# 服务器接口API # 服务器接口API
interface_path = os.path.dirname(__file__)
sys.path.insert(0, interface_path) # 将当前文件的父目录加入临时系统变量
app = Flask(__name__) app = Flask(__name__)
@app.route('/api/singlelogo', methods = ['POST']) @app.route('/api/singlelogo', methods = ['POST'])
def SingleLogoApi():#获取单个logo def SingleLogoApi():#获取单个logo
...@@ -105,12 +107,6 @@ def ChangeABatchApi():#换一批 ...@@ -105,12 +107,6 @@ def ChangeABatchApi():#换一批
profession = request.get_json().get("profession") profession = request.get_json().get("profession")
if "description" in request.get_json() and request.get_json().get("description"): if "description" in request.get_json() and request.get_json().get("description"):
description = request.get_json().get("description") description = request.get_json().get("description")
# curpage =1
# pagesize =10
# if "curpage" in request.get_json() and request.get_json().get("curpage"):
# curpage = request.get_json().get("curpage")
# if "pagesize" in request.get_json() and request.get_json().get("pagesize"):
# pagesize = request.get_json().get("pagesize")
if not title or not profession: if not title or not profession:
return json.dumps({"status": -1, "msg": "参数不正确", "data": {}}, ensure_ascii=False) return json.dumps({"status": -1, "msg": "参数不正确", "data": {}}, ensure_ascii=False)
...@@ -165,9 +161,59 @@ def DownloadSceneApi():#得到场景信息 ...@@ -165,9 +161,59 @@ def DownloadSceneApi():#得到场景信息
return json.dumps({"status": -1, "msg": "调用服务出错", "data": []}, ensure_ascii=False) return json.dumps({"status": -1, "msg": "调用服务出错", "data": []}, ensure_ascii=False)
@app.route('/api/createlogo', methods = ['POST'])#生成单个logo服务
def CreateLogoApi():#得到场景信息
try:
type = ""
title = ""
font_url = ""
first_color = ""
textpos = ""
subtitle = ""
sec_color = ""
log_url = ""
logo_id = 0
if "type" in request.get_json().keys() and request.get_json().get("type"):
type = request.get_json().get("type")
if "title" in request.get_json().keys() and request.get_json().get("title"):
title = request.get_json().get("title")
if "subtitle" in request.get_json().keys() and request.get_json().get("subtitle"):
subtitle = request.get_json().get("subtitle")
if "font_url" in request.get_json().keys() and request.get_json().get("font_url"):
font_url = request.get_json().get("font_url")
if "first_color" in request.get_json().keys() and request.get_json().get("first_color"):
first_color = request.get_json().get("first_color")
if "textpos" in request.get_json().keys() and request.get_json().get("textpos"):
textpos = request.get_json().get("textpos")
if "sec_color" in request.get_json().keys() and request.get_json().get("sec_color"):
sec_color = request.get_json().get("sec_color")
if "log_url" in request.get_json().keys() and request.get_json().get("log_url"):
log_url = request.get_json().get("log_url")
if "logo_id" in request.get_json().keys() and request.get_json().get("logo_id"):
logo_id = request.get_json().get("logo_id")
inputdata = {
"type": type,
"title": title,
"subtitle": subtitle,
"font_url": font_url,
"first_color": first_color,
"textpos": textpos,
"sec_color": sec_color,
"log_url": log_url,
"logo_id": logo_id
}
istrue, pic_url = LogoManage.SaveSingleLogo(inputdata)
if istrue:
return json.dumps({"status": 0, "msg": "成功", "data": pic_url}, ensure_ascii=False)
else:
return json.dumps({"status": -1, "msg": "生成图像出错", "data": ""}, ensure_ascii=False)
except:
return json.dumps({"status": -1, "msg": "调用服务出错", "data": ""}, ensure_ascii=False)
if __name__ == '__main__': if __name__ == '__main__':
CORS(app, supports_credentials=True)#允许跨域 CORS(app, supports_credentials=True)#允许跨域
#app.run(host='172.16.18.2', port=15501, debug=True)
app.run(host='0.0.0.0', port=80, debug=True) app.run(host='0.0.0.0', port=80, debug=True)
#app.run(host='127.0.0.1', port=5000, debug=True)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment