1211-诗词时空背景
诗词时空背景
来源
根据目前的诗词,找出其创作时间,根据创作时间找出相近的诗词创作,提取诗词的背景信息以及对应的诗句,将该诗词创作的前后时间补充完整
def get_poemtime_about_poem():
poem_name = request.form.get("poem_name")
db=MySqLHelper()
desty = ['tang', 'song', 'yuan', 'ming', 'qing']
author=''
bg_time=''
for it in desty:
sql = "select * from " + it + " where title = '" + poem_name + "';"
ret = db.selectone(sql=sql)
if ret!=None:
author=ret[2]
bg_time=str(ret[9]).replace('年','')
break
# print(author)
# print(bg_time)
date_list=[]
back_list=[]
poem_list=[]
content_list=[]
left=int(bg_time)-3
right=int(bg_time)+3
for it in desty:
sql = "select * from " + it + " where author = '" + author + "';"
ret,count = db.selectall(sql=sql)
if ret!=None:
for row in ret:
if str(row[9])!='无' and str(row[9]).find('.')==-1 and str(row[9]).find('—')==-1 and str(row[6])!='无':
time=int(str(row[9]).replace('年',''))
if time>=left and time<=right and bool(re.search(r'\d', row[6])):
date_list.append(time)
back_list.append(row[6])
poem_list.append(row[0])
content_list.append(row[3])
jsonData=[]
for dd in range(left,right+1):
for i in range(len(date_list)):
time=date_list[i]
poem=poem_list[i]
back=back_list[i]
content=content_list[i].replace('\n','').split('。')
ans_content=[]
for it in content:
if it!='':
ans_content.append(it+"。")
if time==dd:
dic={}
dic['time']=str(time)+"年"
dic['title']=poem
dic['back']=back
dic['content']=ans_content
jsonData.append(dic)
#print(json.dumps(jsonData).encode('utf-8').decode("unicode-escape"))
return json.dumps(jsonData)
效果