增加新闻显示页
This commit is contained in:
parent
89baa3e396
commit
fa56a2d968
24
ml/Search.py
24
ml/Search.py
@ -72,6 +72,7 @@ class Search:
|
||||
tm = time.localtime(int(data['time']))
|
||||
data['time'] = time.strftime('%Y-%m-%d %H:%M:%S',tm)
|
||||
data['content'] = data['content'][0:Global.snippetsize]
|
||||
data['id'] = rst
|
||||
newslist.append(data)
|
||||
return newslist
|
||||
|
||||
@ -80,8 +81,27 @@ class Search:
|
||||
pass
|
||||
|
||||
#返回最新新闻
|
||||
def QueryByTime(self):
|
||||
pass
|
||||
def QueryByTime(self,searchPhrase):
|
||||
newslist = self.QueryPhrase(searchPhrase,False)
|
||||
return sorted(newslist,lambda x,y:cmp(y['time'],x['time']))
|
||||
|
||||
def QueryById(self,no):
|
||||
no = int(no.decode('utf-8'))
|
||||
default = dict()
|
||||
default['title'] = "No Such News"
|
||||
default['time']=''
|
||||
default['content'] = "Oh No!"
|
||||
default['url'] = "#"
|
||||
if not no:
|
||||
return default
|
||||
cut = Cut()
|
||||
line = cut.getRow(no,Global.cutnews_origin_dir,Global.filesize)
|
||||
if line:
|
||||
data = json.loads(line)
|
||||
return data
|
||||
else:
|
||||
return default
|
||||
|
||||
|
||||
#search = Search()
|
||||
#search.QueryPhrase(sys.argv[1])
|
||||
|
BIN
ml/Search.pyc
BIN
ml/Search.pyc
Binary file not shown.
22
web/main.py
22
web/main.py
@ -16,21 +16,27 @@ class index:
|
||||
def __init__(self):
|
||||
self.se = Search()
|
||||
def GET(self):
|
||||
searchword = web.input().searchword
|
||||
data = web.input()
|
||||
if data:
|
||||
searchword = data.searchword
|
||||
else:
|
||||
searchword = ''
|
||||
newslist=list()
|
||||
if searchword:
|
||||
newslist = self.se.QueryPhrase(searchword,False)
|
||||
return render.header(searchword,newslist)
|
||||
newslist = self.se.QueryByTime(searchword)
|
||||
return render.index(searchword,newslist)
|
||||
|
||||
class news:
|
||||
def __init__(self):
|
||||
self.se = Search()
|
||||
def GET(self):
|
||||
searchword = web.input().searchword
|
||||
newslist=list()
|
||||
if searchword:
|
||||
newslist = self.se.QueryPhrase(searchword,False)
|
||||
return render.header(searchword,newslist)
|
||||
data = web.input()
|
||||
if data:
|
||||
ID = data.id
|
||||
else:
|
||||
ID=''
|
||||
news = self.se.QueryById(ID)
|
||||
return render.news(news)
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = web.application(urls,globals())
|
||||
|
BIN
web/main.pyc
BIN
web/main.pyc
Binary file not shown.
@ -16,7 +16,7 @@ $def with(searchword,newslist)
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control" name="searchword" placeholder=$searchword>
|
||||
<span class="input-group-btn">
|
||||
<button class="btn btn-default" type="button">搜索</button>
|
||||
<button class="btn btn-default" type="submit">搜索</button>
|
||||
</span>
|
||||
</div><!-- /input-group -->
|
||||
</div><!-- /.col-lg-6 -->
|
||||
@ -32,7 +32,7 @@ $if len(newslist) > 0:
|
||||
时间:$news['time'] $news['title']
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
$news['content'] ... <a href="#">查看全文>>></a>
|
||||
$news['content'] ... <a href="/news?id=$news['id']" >查看全文>>></a>
|
||||
<br><br>
|
||||
原始网页链接:<a href=$news['url']>$news['url']</a>
|
||||
</div>
|
@ -1,31 +1,42 @@
|
||||
$def with(news)
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<title>新闻聚合搜索引擎</title>
|
||||
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.0/css/bootstrap-combined.min.css" rel="stylesheet">
|
||||
<link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
|
||||
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
|
||||
<script src="http://libs.baidu.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class='navbar navbar-inverse'>
|
||||
<div class='nav-collapse' style="height: auto;">
|
||||
<ul class="nav">
|
||||
<li class="active"><a href="#">Home</a></li>
|
||||
<li><a href="#">Page One</a></li>
|
||||
<li><a href="#">Page Two</a></li>
|
||||
<!--<div style="padding: 100px 100px 8px;margin-top:10px"> -->
|
||||
$if news:
|
||||
<div style="margin-top:30px">
|
||||
<div class="col-lg-6 col-lg-offset-1">
|
||||
<div class="panel panel-info">
|
||||
<div class="panel-heading">
|
||||
$news['time'] $news['title']
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
$news['content']
|
||||
<br><br>
|
||||
原始网页链接:<a href=$news['url']>$news['url']</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-2 col-lg-offset-1">
|
||||
<div class= "panel panel-primary">
|
||||
<div class="panel-heading">相关新闻</div>
|
||||
<div class= "panel-body">
|
||||
<ul>
|
||||
<li>AAAA</li>
|
||||
<li>BBBB</li>
|
||||
<li>CCCC</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id='content' class='row-fluid'>
|
||||
<div class='span9 main'>
|
||||
<h2><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum.</p>
|
||||
|
||||
<p>Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.</p> </h2>
|
||||
</div>
|
||||
<div class='span3 sidebar'>
|
||||
<h2>Sidebar</h2>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,10 +0,0 @@
|
||||
<head>
|
||||
<style type="text/css">
|
||||
@import "../static/index.css"
|
||||
</style>
|
||||
<head>
|
||||
<caption>新闻聚合搜索</caption>
|
||||
<div style="text-align: center;">
|
||||
<input id='search' class='input'>
|
||||
<a href='#' class='button'>Search</a>
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user