Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
zhichan
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
蒋勇
zhichan
Commits
b777802c
Commit
b777802c
authored
May 11, 2020
by
高宇强
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gyq
parent
5559140d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
87 additions
and
386 deletions
+87
-386
ailogo/CreateScene.py
+2
-2
ailogo/GetLogo.py
+4
-4
ailogo/LogoManage.py
+81
-208
ailogo/LogoReqAnalysis.py
+0
-172
No files found.
ailogo/CreateScene.py
View file @
b777802c
...
@@ -20,8 +20,8 @@ def queryscene(api,inputdata):
...
@@ -20,8 +20,8 @@ def queryscene(api,inputdata):
return
""
return
""
def
sceneservers
(
inputdata
):
def
sceneservers
(
inputdata
):
#connection = pymysql.connect(host='172.16.18.140', port=3306, user='root', passwd='x8BOQk./1}bC&=+', db='logo_msg')
connection
=
pymysql
.
connect
(
host
=
'rm-2zey194899z131oufao.mysql.rds.aliyuncs.com'
,
port
=
3306
,
user
=
'root'
,
connection
=
pymysql
.
connect
(
host
=
'43.247.184.94'
,
port
=
8898
,
user
=
'root'
,
passwd
=
'x8BOQk./1}bC&=+'
,
db
=
'logo_msg'
)
passwd
=
'Gongsibao2018'
,
db
=
'logo_msg'
)
# 阿里云
cur
=
connection
.
cursor
(
cursor
=
pymysql
.
cursors
.
DictCursor
)
cur
=
connection
.
cursor
(
cursor
=
pymysql
.
cursors
.
DictCursor
)
try
:
try
:
# 得到gen_json
# 得到gen_json
...
...
ailogo/GetLogo.py
View file @
b777802c
...
@@ -10,8 +10,8 @@ import pymysql
...
@@ -10,8 +10,8 @@ import pymysql
import
re
import
re
def
getLogoUrl
(
inputdata
):
def
getLogoUrl
(
inputdata
):
#connection = pymysql.connect(host='172.16.18.140', port=3306, user='root', passwd='x8BOQk./1}bC&=+', db='logo_msg')
connection
=
pymysql
.
connect
(
host
=
'rm-2zey194899z131oufao.mysql.rds.aliyuncs.com'
,
port
=
3306
,
user
=
'root'
,
connection
=
pymysql
.
connect
(
host
=
'43.247.184.94'
,
port
=
8898
,
user
=
'root'
,
passwd
=
'x8BOQk./1}bC&=+'
,
db
=
'logo_msg'
)
passwd
=
'Gongsibao2018'
,
db
=
'logo_msg'
)
# 阿里云
cur
=
connection
.
cursor
(
cursor
=
pymysql
.
cursors
.
DictCursor
)
cur
=
connection
.
cursor
(
cursor
=
pymysql
.
cursors
.
DictCursor
)
try
:
try
:
#得到gen_json
#得到gen_json
...
@@ -75,8 +75,8 @@ def getLogoUrl(inputdata):
...
@@ -75,8 +75,8 @@ def getLogoUrl(inputdata):
return
False
,{}
return
False
,{}
def
updateData
(
inputdata
):
def
updateData
(
inputdata
):
#connection = pymysql.connect(host='172.16.18.140', port=3306, user='root', passwd='x8BOQk./1}bC&=+', db='logo_msg')
connection
=
pymysql
.
connect
(
host
=
'rm-2zey194899z131oufao.mysql.rds.aliyuncs.com'
,
port
=
3306
,
user
=
'root'
,
connection
=
pymysql
.
connect
(
host
=
'43.247.184.94'
,
port
=
8898
,
user
=
'root'
,
passwd
=
'x8BOQk./1}bC&=+'
,
db
=
'logo_msg'
)
passwd
=
'Gongsibao2018'
,
db
=
'logo_msg'
)
# 阿里云
cur
=
connection
.
cursor
(
cursor
=
pymysql
.
cursors
.
DictCursor
)
cur
=
connection
.
cursor
(
cursor
=
pymysql
.
cursors
.
DictCursor
)
try
:
try
:
#更新数据库中的标记
#更新数据库中的标记
...
...
ailogo/LogoManage.py
View file @
b777802c
#!/usr/bin/python3
#!/usr/bin/python3
# -*- coding: utf-8 -*- #文件也为UTF-8
# -*- coding: utf-8 -*- #文件也为UTF-8
import
LogoReqAnalysis
import
LogoGenerator
import
LogoGenerator
import
pymysql
,
requests
import
pymysql
,
requests
import
random
import
random
...
@@ -8,6 +7,7 @@ import re
...
@@ -8,6 +7,7 @@ import re
import
customizelogosmall
import
customizelogosmall
import
json
import
json
import
time
import
time
from
threading
import
Thread
#随机取50个descid,其中15个模板id,35个logoid
#随机取50个descid,其中15个模板id,35个logoid
def
GetDescId
(
sptagdata
,
templatedata
):
def
GetDescId
(
sptagdata
,
templatedata
):
...
@@ -22,12 +22,33 @@ def GetDescId(sptagdata,templatedata):
...
@@ -22,12 +22,33 @@ def GetDescId(sptagdata,templatedata):
returnlist
.
extend
(
random
.
sample
(
sptagdata
,
50
-
len
(
returnlist
)))
returnlist
.
extend
(
random
.
sample
(
sptagdata
,
50
-
len
(
returnlist
)))
return
returnlist
return
returnlist
#多线程处理生成logo
def
wgetlogo
(
logourl
,
logoinfo
):
res_info
=
logoinfo
data1
=
requests
.
post
(
logourl
,
json
=
logoinfo
)
.
json
()
if
data1
[
"status"
]
==
0
:
res_info
[
"pic_url"
]
=
data1
[
"data"
]
return
res_info
else
:
return
{}
class
MyThread
(
Thread
):
def
__init__
(
self
,
func
,
args
):
super
(
MyThread
,
self
)
.
__init__
()
self
.
func
=
func
self
.
args
=
args
def
run
(
self
):
self
.
result
=
self
.
func
(
*
self
.
args
)
def
get_result
(
self
):
try
:
return
self
.
result
except
Exception
:
return
None
#把计算的LOGO结果存入数据库
#把计算的LOGO结果存入数据库
def
SaveLogoResource
(
inputdata
,
msg_id
,
cur
):
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
:
try
:
# 调用process方法或服务
# 调用process方法或服务
sptagapi
=
'http://43.247.184.94:18009/gsb/api/textquery'
sptagapi
=
'http://43.247.184.94:18009/gsb/api/textquery'
...
@@ -142,176 +163,10 @@ def SaveSingleLogo(inputdata):
...
@@ -142,176 +163,10 @@ def SaveSingleLogo(inputdata):
except
Exception
as
e
:
except
Exception
as
e
:
return
False
,
""
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
):
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
=
'rm-2zey194899z131oufao.mysql.rds.aliyuncs.com'
,
port
=
3306
,
user
=
'root'
,
connection
=
pymysql
.
connect
(
host
=
'43.247.184.94'
,
port
=
8898
,
user
=
'root'
,
passwd
=
'x8BOQk./1}bC&=+'
,
db
=
'logo_msg'
)
passwd
=
'Gongsibao2018'
,
db
=
'logo_msg'
)
# 阿里云
cur
=
connection
.
cursor
(
cursor
=
pymysql
.
cursors
.
DictCursor
)
cur
=
connection
.
cursor
(
cursor
=
pymysql
.
cursors
.
DictCursor
)
try
:
try
:
select_sql
=
'select * from input_msg where title="
%
s" and subtitle="
%
s" and profession="
%
s"'
\
select_sql
=
'select * from input_msg where title="
%
s" and subtitle="
%
s" and profession="
%
s"'
\
...
@@ -379,6 +234,8 @@ def ChangeABatch(inputdata):
...
@@ -379,6 +234,8 @@ def ChangeABatch(inputdata):
"font_description"
:
item
[
"description"
]})
"font_description"
:
item
[
"description"
]})
iserror
=
True
iserror
=
True
threadlist
=
[]
#多线程
res_temp
=
[]
#最后返回的结果
for
res
in
res_list
:
for
res
in
res_list
:
# qu一次log_url
# qu一次log_url
select_sql
=
"select * from logo_desc where id =
%
s"
%
res
[
"logo_id"
]
select_sql
=
"select * from logo_desc where id =
%
s"
%
res
[
"logo_id"
]
...
@@ -401,29 +258,36 @@ def ChangeABatch(inputdata):
...
@@ -401,29 +258,36 @@ def ChangeABatch(inputdata):
res
[
"font_url"
]
=
font_url
res
[
"font_url"
]
=
font_url
res
[
"font_name"
]
=
font_name
res
[
"font_name"
]
=
font_name
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 "
if
not
res
[
"pic_url"
]:
if
not
res
[
"pic_url"
]:
#改成调服务
k
=
MyThread
(
wgetlogo
,
args
=
(
'http://createlogo-service/api/createlogo'
,
res
))
#c_url = 'http://127.0.0.1:5000/api/createlogo'
k
.
start
()
c_url
=
'http://createlogo-service/api/createlogo'
threadlist
.
append
(
k
)
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"
])
cur
.
execute
(
Update_sql
,
tub
)
else
:
iserror
=
False
try
:
connection
.
commit
()
except
:
connection
.
rollback
()
iserror
=
False
connection
.
close
()
if
iserror
:
if
iserror
:
return
True
,
len
(
res_list
),
res_list
else
:
else
:
return
False
,
0
,
[]
res_temp
.
append
(
res
)
for
th
in
threadlist
:
th
.
join
()
if
th
.
get_result
():
res_temp
.
append
(
th
.
get_result
())
Update_sql
=
"UPDATE `logo_msg`.`logo_res` SET `pic_url`=
%
s,`font_id`=
%
s WHERE `id`=
%
s "
update_list
=
[]
for
res
in
res_temp
:
if
res
[
"pic_url"
]:
tub
=
(
res
[
"pic_url"
],
res
[
"font_id"
],
res
[
"id"
])
update_list
.
append
(
tub
)
cur
.
executemany
(
Update_sql
,
update_list
)
try
:
connection
.
commit
()
except
:
connection
.
rollback
()
iserror
=
False
connection
.
close
()
if
iserror
and
len
(
res_temp
):
return
True
,
len
(
res_temp
),
res_temp
else
:
return
False
,
0
,
[]
else
:
#说明该任务信息还没有做过生成
else
:
#说明该任务信息还没有做过生成
connection
.
close
()
connection
.
close
()
return
ReturnLogoInfo
(
inputdata
,
1
,
10
)
return
ReturnLogoInfo
(
inputdata
,
1
,
10
)
...
@@ -433,8 +297,8 @@ def ChangeABatch(inputdata):
...
@@ -433,8 +297,8 @@ def ChangeABatch(inputdata):
#返回logo信息
#返回logo信息
def
ReturnLogoInfo
(
inputdata
,
curpage
,
pagesize
):
def
ReturnLogoInfo
(
inputdata
,
curpage
,
pagesize
):
#connection = pymysql.connect(host='172.16.18.140', port=3306, user='root', passwd='x8BOQk./1}bC&=+', db='logo_msg')
connection
=
pymysql
.
connect
(
host
=
'rm-2zey194899z131oufao.mysql.rds.aliyuncs.com'
,
port
=
3306
,
user
=
'root'
,
connection
=
pymysql
.
connect
(
host
=
'43.247.184.94'
,
port
=
8898
,
user
=
'root'
,
passwd
=
'x8BOQk./1}bC&=+'
,
db
=
'logo_msg'
)
passwd
=
'Gongsibao2018'
,
db
=
'logo_msg'
)
# 阿里云
cur
=
connection
.
cursor
(
cursor
=
pymysql
.
cursors
.
DictCursor
)
cur
=
connection
.
cursor
(
cursor
=
pymysql
.
cursors
.
DictCursor
)
iserror
=
True
iserror
=
True
try
:
try
:
...
@@ -505,6 +369,8 @@ def ReturnLogoInfo(inputdata,curpage,pagesize):
...
@@ -505,6 +369,8 @@ def ReturnLogoInfo(inputdata,curpage,pagesize):
nfen
=
1
#从第一页开始
nfen
=
1
#从第一页开始
fen_dict
=
{}
#分页信息
fen_dict
=
{}
#分页信息
temp_list
=
[]
temp_list
=
[]
threadlist
=
[]
res_temp
=
[]
for
res
in
random_list
:
for
res
in
random_list
:
dict1
=
{}
dict1
=
{}
dict1
[
"id"
]
=
res
[
"id"
]
dict1
[
"id"
]
=
res
[
"id"
]
...
@@ -556,27 +422,34 @@ def ReturnLogoInfo(inputdata,curpage,pagesize):
...
@@ -556,27 +422,34 @@ def ReturnLogoInfo(inputdata,curpage,pagesize):
if
curpage
>
len
(
fen_dict
):
if
curpage
>
len
(
fen_dict
):
curpage
=
len
(
fen_dict
)
curpage
=
len
(
fen_dict
)
list_r
=
fen_dict
[
curpage
]
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
:
for
r
in
list_r
:
if
not
r
[
"pic_url"
]:
if
not
r
[
"pic_url"
]:
# 改成调服务
k
=
MyThread
(
wgetlogo
,
args
=
(
'http://createlogo-service/api/createlogo'
,
r
))
#c_url = 'http://127.0.0.1:5000/api/createlogo'
k
.
start
()
c_url
=
'http://createlogo-service/api/createlogo'
threadlist
.
append
(
k
)
data1
=
requests
.
post
(
c_url
,
json
=
r
)
.
json
()
else
:
if
data1
[
"status"
]
==
0
:
res_temp
.
append
(
r
)
r
[
"pic_url"
]
=
data1
[
"data"
]
tub
=
(
r
[
"pic_url"
],
r
[
"font_id"
],
r
[
"id"
])
cur
.
execute
(
Update_sql
,
tub
)
for
th
in
threadlist
:
else
:
th
.
join
()
iserror
=
False
if
th
.
get_result
():
res_temp
.
append
(
th
.
get_result
())
Update_sql
=
"UPDATE `logo_msg`.`logo_res` SET `pic_url`=
%
s,`font_id`=
%
s WHERE `id`=
%
s "
update_list
=
[]
for
res
in
res_temp
:
if
res
[
"pic_url"
]:
#没有生成图片的不返回
tub
=
(
res
[
"pic_url"
],
res
[
"font_id"
],
res
[
"id"
])
update_list
.
append
(
tub
)
cur
.
executemany
(
Update_sql
,
update_list
)
try
:
try
:
connection
.
commit
()
connection
.
commit
()
except
:
except
:
connection
.
rollback
()
connection
.
rollback
()
iserror
=
False
iserror
=
False
connection
.
close
()
connection
.
close
()
if
iserror
:
if
iserror
and
len
(
res_temp
)
:
return
True
,
re_count
,
list_r
return
True
,
len
(
res_temp
),
res_temp
else
:
else
:
return
False
,
0
,[]
return
False
,
0
,[]
except
Exception
as
e
:
except
Exception
as
e
:
...
...
ailogo/LogoReqAnalysis.py
deleted
100644 → 0
View file @
5559140d
#!/usr/bin/python3
# -*- coding: utf-8 -*- #文件也为UTF-8
import
json
import
random
import
pymysql
# 客户输入信息
#0.读取配置信息和
connection
=
pymysql
.
connect
(
host
=
'43.247.184.94'
,
port
=
8898
,
user
=
'root'
,
passwd
=
'x8BOQk./1}bC&=+'
,
db
=
'logo_msg'
)
#connection = pymysql.connect(host='172.16.18.140', port=3306, user='root', passwd='x8BOQk./1}bC&=+', db='logo_msg')
cur
=
connection
.
cursor
()
LogoHash
=
{}
#fontlist=["font/cn/hwzs.ttf","font/cn/hwfs.ttf"]
fontlist
=
[
"font/cn/hwzs.ttf"
,
"font/cn/hwfs.ttf"
,
"font/cn/白舟·侍.ttf"
,
"font/cn/白舟隼風.ttf"
,
"font/cn/潮字社風雲繁.ttf"
,
"font/cn/潮字社凌渡鯤鵬繁.ttf"
,
"font/cn/潮字社时光简.ttf"
,
"font/cn/潮字社時光繁.ttf"
,
"font/cn/德彪钢笔行书字库.ttf"
,
"font/cn/郭小语钢笔楷体.ttf"
,
"font/cn/微软vista雅黑.ttf"
]
def
Init
():
#LogoHash加入数据
#字体增加到系统
fontlist
.
append
(
"font/cn/hwzs.ttf"
)
return
""
def
LogoHashInit
():
#实现这个方法,从数据库里获取logo信息
sql
=
'select id,first_color,sec_color,height,width,profession,description,textpos,pic_url,'
\
'originality,logo_id from logo_desc '
cur
.
execute
(
sql
)
data
=
cur
.
fetchall
()
result
=
[]
for
itm
in
data
:
res
=
{}
res
[
"id"
]
=
itm
[
0
]
res
[
"first_color"
]
=
itm
[
1
]
res
[
"sec_color"
]
=
itm
[
2
]
res
[
"height"
]
=
itm
[
3
]
res
[
"width"
]
=
itm
[
4
]
res
[
"profession"
]
=
itm
[
5
]
res
[
"description"
]
=
itm
[
6
]
res
[
"textpso"
]
=
itm
[
7
]
res
[
"pic_url"
]
=
itm
[
8
]
res
[
"originality"
]
=
itm
[
9
]
res
[
"logo_id"
]
=
itm
[
10
]
result
.
append
(
res
)
connection
.
close
()
return
result
def
FontInit
():
#实现这个方法,从数据库里获取字体信息
#从数据库里获取字体名称,放到fontlist里
select_sql
=
'select name from logo_font'
cur
.
execute
(
select_sql
)
datas
=
cur
.
fetchall
()
for
data
in
datas
:
fontlist
.
append
(
data
)
font
=
random
.
sample
(
fontlist
,
1
)
connection
.
close
()
return
font
def
search
(
text
):
logo_res
=
[]
#bc = BertClient()
#textmatrix=bc.encode(['暴风粒子'])
#xx=search(textmatrix)
#处理xx,得到logoIDs
#logo_res.append(logoIDs)
return
logo_res
def
logoFilter
(
logo_res
,
profession
):
logo_res_content
=
[]
for
logoNo
in
logo_res
:
logocontent
=
LogoHash
[
logoNo
]
if
logocontent
[
"profession"
]
==
profession
:
logo_res_content
.
append
(
logocontent
)
return
logo_res_content
def
semanticsAnalysis
(
text
,
profession
):
logo_res
=
[]
logo_res_content
=
[]
#检索得到logo结合
logo_res
=
search
(
text
)
for
logoNo
in
logo_res
:
logocontent
=
LogoHash
[
logoNo
]
logo_res_content
.
append
(
logocontent
)
#1.3分析行业属性,利用行业过滤logo
logo_res_content
=
logoFilter
(
logo_res_content
,
profession
)
#1.5过滤50个
logo_res_content
=
logo_res_content
[
0
:
50
]
return
logo_res
def
templateAnalysis
(
text
,
profession
):
logo_res
=
[]
return
logo_res
def
process
(
inputdata
):
# inputdata = {
# 'title': '微信',
# 'subtitle':'wechat',
# 'profession':'通讯行业',
# 'description':'一款跨平台的通讯工具。支持单人、多人参与。通过手机网络发送语音、图片、视频和文字。'
# }
print
(
inputdata
)
#调用语义引擎进行logo获取
#1.1语义分析(对title进行分析).语义分析有规则
semlogo_res
=
semanticsAnalysis
(
inputdata
[
'title'
],
inputdata
[
'profession'
])
#调用模板引擎进行logo获取
temlogo_res
=
templateAnalysis
(
inputdata
[
'title'
],
inputdata
[
'profession'
])
#logo
semlogo_res
=
semlogo_res
.
append
(
temlogo_res
)
#logo顺序随机
# 随机list
#reslist = random.sample(semlogo_res, len(semlogo_res))
reslist
=
[]
#结果样例
logo_resource
=
{
"logo_id"
:
1
,
"first_color"
:
"(192,52,116)"
,
#logo主色 --title
"sec_color"
:
"(230,231,232)"
,
#logo配色 --subtitle
"height"
:
900
,
#logo高度
"width"
:
900
,
#logo宽度
"profession"
:
"通讯行业"
,
#logo所属行业
"description"
:
"深红色象征着热情,活泼,张扬"
,
#主色描述
"textpos"
:
"right"
,
#文字位置 上下左右
"pic_url"
:
"d:/logo1.png"
,
#logo地址
"originality"
:
"火"
,
#logo创意 带字母的 带山带水等
"groundcolor"
:
"(255,255,255)"
,
#背景色
"people"
:
"qw"
,
#加工人
"type"
:
"standard"
,
#template or standard
"msg_id"
:
1
}
reslist
.
append
(
logo_resource
)
print
(
reslist
)
return
reslist
#inputdata是输入数据
#resitem是一个logo信息
def
TemplateSingleLogoProcess
(
inputdata
):
#5.2 随机一个
randnum
=
random
.
randint
(
0
,
len
(
fontlist
)
-
1
)
font
=
fontlist
[
randnum
]
print
(
font
)
#6.拼结果对象,生成logo
logogendata
=
{}
#输出
logogendata
=
{
'brand_text'
:
inputdata
[
'title'
],
#品牌名称
'brand_font'
:
font
,
#
'brand_color'
:
inputdata
[
'first_color'
],
#字体颜色
'brand_location'
:
inputdata
[
'textpos'
],
#左右上下
'slogan_text'
:
inputdata
[
'subtitle'
],
#标语名称
'slogan_font'
:
font
,
#
'slogan_color'
:
inputdata
[
'sec_color'
],
#标语颜色
'logo_url'
:
inputdata
[
'log_url'
]
#图片地址
}
json_str
=
json
.
dumps
(
logogendata
)
return
json_str
def
StandardSingleLogoProcess
(
inputdata
):
#5.2 随机一个
print
(
"////////////////////"
)
print
(
len
(
fontlist
))
randnum
=
random
.
randint
(
0
,
len
(
fontlist
)
-
1
)
font
=
fontlist
[
randnum
]
#6.拼结果对象,生成logo
logogendata
=
{
'brand_text'
:
inputdata
[
'title'
],
#品牌名称
'brand_font'
:
font
,
#
'brand_color'
:
inputdata
[
'first_color'
],
#字体颜色
'brand_location'
:
inputdata
[
'textpos'
],
#左右上下
'slogan_text'
:
inputdata
[
'subtitle'
],
#标语名称
'slogan_font'
:
font
,
#
'slogan_color'
:
inputdata
[
'sec_color'
],
#标语颜色
'logo_url'
:
inputdata
[
'log_url'
]
#图片地址
}
json_str
=
logogendata
return
json_str
def
SingleLogoProcess
(
inputdata
):
if
inputdata
[
"type"
]
==
"template"
:
return
TemplateSingleLogoProcess
(
inputdata
)
else
:
return
StandardSingleLogoProcess
(
inputdata
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment