kpt

【page.py】添加话题页接口

1 -from flask import Flask,session,render_template,redirect,Blueprint,request 1 +from flask import Flask, session, render_template, redirect, Blueprint, request
2 from snownlp import SnowNLP 2 from snownlp import SnowNLP
3 from utils.getHomePageData import * 3 from utils.getHomePageData import *
4 from utils.getHotWordPageData import * 4 from utils.getHotWordPageData import *
5 from utils.getTableData import * 5 from utils.getTableData import *
6 -from utils.getPublicData import getAllHotWords 6 +from utils.getPublicData import getAllHotWords, getAllTopics
7 from utils.getEchartsData import * 7 from utils.getEchartsData import *
8 -pb = Blueprint('page',__name__,url_prefix='/page',template_folder='templates') 8 +from utils.getTopicPageData import *
  9 +
  10 +pb = Blueprint('page',
  11 + __name__,
  12 + url_prefix='/page',
  13 + template_folder='templates')
  14 +
9 15
10 @pb.route('/home') 16 @pb.route('/home')
11 def home(): 17 def home():
12 username = session.get('username') 18 username = session.get('username')
13 - articleLenMax,likeCountMaxAuthorName,cityMax = getHomeTagsData() 19 + articleLenMax, likeCountMaxAuthorName, cityMax = getHomeTagsData()
14 commentsLikeCountTopFore = getHomeCommentsLikeCountTopFore() 20 commentsLikeCountTopFore = getHomeCommentsLikeCountTopFore()
15 - xData,yData = getHomeArticleCreatedAtChart() 21 + xData, yData = getHomeArticleCreatedAtChart()
16 typeChart = getHomeTypeChart() 22 typeChart = getHomeTypeChart()
17 createAtChart = getHomeCommentCreatedChart() 23 createAtChart = getHomeCommentCreatedChart()
18 # getUserNameWordCloud() 24 # getUserNameWordCloud()
@@ -25,17 +31,18 @@ def home(): @@ -25,17 +31,18 @@ def home():
25 xData=xData, 31 xData=xData,
26 yData=yData, 32 yData=yData,
27 typeChart=typeChart, 33 typeChart=typeChart,
28 - createAtChart=createAtChart  
29 - ) 34 + createAtChart=createAtChart)
  35 +
30 36
31 @pb.route('/hotWord') 37 @pb.route('/hotWord')
32 def hotWord(): 38 def hotWord():
33 username = session.get('username') 39 username = session.get('username')
34 hotWordList = getAllHotWords() 40 hotWordList = getAllHotWords()
35 defaultHotWord = hotWordList[0][0] 41 defaultHotWord = hotWordList[0][0]
36 - if request.args.get('hotWord'):defaultHotWord = request.args.get('hotWord') 42 + if request.args.get('hotWord'):
  43 + defaultHotWord = request.args.get('hotWord')
37 hotWordLen = getHotWordLen(defaultHotWord) 44 hotWordLen = getHotWordLen(defaultHotWord)
38 - xData,yData = getHotWordPageCreatedAtCharData(defaultHotWord) 45 + xData, yData = getHotWordPageCreatedAtCharData(defaultHotWord)
39 sentences = '' 46 sentences = ''
40 value = SnowNLP(defaultHotWord).sentiments 47 value = SnowNLP(defaultHotWord).sentiments
41 if value == 0.5: 48 if value == 0.5:
@@ -54,20 +61,45 @@ def hotWord(): @@ -54,20 +61,45 @@ def hotWord():
54 sentences=sentences, 61 sentences=sentences,
55 xData=xData, 62 xData=xData,
56 yData=yData, 63 yData=yData,
57 - comments=comments  
58 - ) 64 + comments=comments)
  65 +
  66 +
  67 +@pb.route('/hotTopic')
  68 +def hotTopic():
  69 + username = session.get('username')
  70 + topicList = getAllTopics()
  71 + defaultTopic = topicList[0][0]
  72 + if request.args.get('topic'):
  73 + defaultTopic = request.args.get('topic')
  74 + topicLen = getTopicLen(defaultTopic)
  75 + xData, yData = getTopicPageCreatedAtCharData()
  76 + sentences = ''
  77 +
  78 + # ... 这里要嵌入 topic 相关内容(热度?)来填充 sentences
  79 +
  80 + comments = getCommentFilterDataTopic(defaultTopic)
  81 + return render_template('hotWord.html',
  82 + username=username,
  83 + topicList=topicList,
  84 + defaultTopic=defaultTopic,
  85 + topicLen=topicLen,
  86 + sentences=sentences,
  87 + xData=xData,
  88 + yData=yData,
  89 + comments=comments)
  90 +
59 91
60 @pb.route('/tableData') 92 @pb.route('/tableData')
61 def tableData(): 93 def tableData():
62 username = session.get('username') 94 username = session.get('username')
63 defaultFlag = False 95 defaultFlag = False
64 - if request.args.get('flag'):defaultFlag = True 96 + if request.args.get('flag'): defaultFlag = True
65 tableData = getTableDataList(defaultFlag) 97 tableData = getTableDataList(defaultFlag)
66 return render_template('tableData.html', 98 return render_template('tableData.html',
67 username=username, 99 username=username,
68 tableData=tableData, 100 tableData=tableData,
69 - defaultFlag=defaultFlag  
70 - ) 101 + defaultFlag=defaultFlag)
  102 +
71 103
72 @pb.route('/articleChar') 104 @pb.route('/articleChar')
73 def articleChar(): 105 def articleChar():
@@ -75,9 +107,9 @@ def articleChar(): @@ -75,9 +107,9 @@ def articleChar():
75 typeList = getTypeList() 107 typeList = getTypeList()
76 defaultType = typeList[0] 108 defaultType = typeList[0]
77 if request.args.get('type'): defaultType = request.args.get('type') 109 if request.args.get('type'): defaultType = request.args.get('type')
78 - xData,yData = getArticleCharLikeCount(defaultType)  
79 - x1Data,y1Data = getArticleCharCommentsLen(defaultType)  
80 - x2Data,y2Data = getArticleCharRepotsLen(defaultType) 110 + xData, yData = getArticleCharLikeCount(defaultType)
  111 + x1Data, y1Data = getArticleCharCommentsLen(defaultType)
  112 + x2Data, y2Data = getArticleCharRepotsLen(defaultType)
81 return render_template('articleChar.html', 113 return render_template('articleChar.html',
82 username=username, 114 username=username,
83 typeList=typeList, 115 typeList=typeList,
@@ -87,8 +119,8 @@ def articleChar(): @@ -87,8 +119,8 @@ def articleChar():
87 x1Data=x1Data, 119 x1Data=x1Data,
88 y1Data=y1Data, 120 y1Data=y1Data,
89 x2Data=x2Data, 121 x2Data=x2Data,
90 - y2Data=y2Data  
91 - ) 122 + y2Data=y2Data)
  123 +
92 124
93 @pb.route('/ipChar') 125 @pb.route('/ipChar')
94 def ipChar(): 126 def ipChar():
@@ -98,27 +130,27 @@ def ipChar(): @@ -98,27 +130,27 @@ def ipChar():
98 return render_template('ipChar.html', 130 return render_template('ipChar.html',
99 username=username, 131 username=username,
100 articleRegionData=articleRegionData, 132 articleRegionData=articleRegionData,
101 - commentRegionData=commentRegionData  
102 - ) 133 + commentRegionData=commentRegionData)
  134 +
103 135
104 @pb.route('/commentChar') 136 @pb.route('/commentChar')
105 def commentChar(): 137 def commentChar():
106 username = session.get('username') 138 username = session.get('username')
107 - xData,yData = getCommentCharDataOne() 139 + xData, yData = getCommentCharDataOne()
108 genderPieData = getCommentCharDataTwo() 140 genderPieData = getCommentCharDataTwo()
109 return render_template('commentChar.html', 141 return render_template('commentChar.html',
110 username=username, 142 username=username,
111 xData=xData, 143 xData=xData,
112 yData=yData, 144 yData=yData,
113 - genderPieData=genderPieData  
114 - ) 145 + genderPieData=genderPieData)
  146 +
115 147
116 @pb.route('/yuqingChar') 148 @pb.route('/yuqingChar')
117 def yuqingChar(): 149 def yuqingChar():
118 username = session.get('username') 150 username = session.get('username')
119 - xData,yData,bieData = getYuQingCharDataOne()  
120 - bieData1,bieData2 = getYuQingCharDataTwo()  
121 - x1Data,y1Data = getYuQingCharDataThree() 151 + xData, yData, bieData = getYuQingCharDataOne()
  152 + bieData1, bieData2 = getYuQingCharDataTwo()
  153 + x1Data, y1Data = getYuQingCharDataThree()
122 return render_template('yuqingChar.html', 154 return render_template('yuqingChar.html',
123 username=username, 155 username=username,
124 xData=xData, 156 xData=xData,
@@ -127,12 +159,10 @@ def yuqingChar(): @@ -127,12 +159,10 @@ def yuqingChar():
127 bieData1=bieData1, 159 bieData1=bieData1,
128 bieData2=bieData2, 160 bieData2=bieData2,
129 x1Data=x1Data, 161 x1Data=x1Data,
130 - y1Data=y1Data  
131 - ) 162 + y1Data=y1Data)
  163 +
132 164
133 @pb.route('/articleCloud') 165 @pb.route('/articleCloud')
134 def articleCloud(): 166 def articleCloud():
135 username = session.get('username') 167 username = session.get('username')
136 - return render_template('articleContentCloud.html',  
137 - username=username  
138 - ) 168 + return render_template('articleContentCloud.html', username=username)