-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
SwimmingFish6
committed
Jun 22, 2017
0 parents
commit 43fe851
Showing
14,778 changed files
with
2,080,991 additions
and
0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from flask import Flask | ||
from flask_mongoengine import MongoEngine | ||
from config import config | ||
|
||
db = MongoEngine() | ||
|
||
def create_app(config_name): | ||
app = Flask(__name__) | ||
|
||
app.config['MONGODB_DB'] = 'python' | ||
app.config['MONGODB_HOST'] = 'localhost' | ||
app.config['MONGODB_PORT'] = 27017 | ||
app.config.from_object(config[config_name]) | ||
config[config_name].init_app(app) | ||
db.init_app(app) | ||
|
||
|
||
from .main import main as main_blueprint | ||
app.register_blueprint(main_blueprint) | ||
return app |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from flask import Blueprint | ||
|
||
main = Blueprint('main', __name__) | ||
|
||
from . import views, errors |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from flask import render_template | ||
from . import main | ||
|
||
@main.app_errorhandler(404) | ||
def page_not_found(e): | ||
return render_template('404.html'), 404 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
|
||
class Item: | ||
def __init__(self, news_date, news_title, news_source, news_content, news_key, news_type, news_image, news_digest): | ||
self.news_date = news_date | ||
self.news_title = news_title | ||
self.news_source = news_source | ||
self.news_content = news_content | ||
self.news_key = news_key | ||
self.news_type = news_type | ||
self.news_image = news_image | ||
self.news_digest = news_digest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
from flask import render_template, request, jsonify | ||
from . import main | ||
from ..models import NewsItem | ||
from ..models import User | ||
from .item import Item | ||
|
||
type_dict = {'news': '新闻', 'sports': '体育', 'ent': '娱乐', 'economy': "财经", 'war': '军事', 'car': '汽车', 'tech': '科技', | ||
'mobile': '手机', 'digit': '数码', 'lady': '女性', 'edu': '教育', 'health': '健康', 'tour': '旅游', 'child': '亲子', | ||
'home': '家居', 'house': '房产'} | ||
|
||
|
||
@main.route('/') | ||
def index(): | ||
return render_template('index.html') | ||
|
||
|
||
@main.app_errorhandler(404) | ||
def page_not_found(e): | ||
return render_template('404.html'), 404 | ||
|
||
|
||
@main.errorhandler(500) | ||
def internal_server_error(e): | ||
return render_template('500.html'), 500 | ||
|
||
|
||
@main.route('/get_new', methods=['GET']) | ||
def get_new(): | ||
data = [] | ||
|
||
# print(email); | ||
|
||
|
||
for entry in NewsItem.objects.order_by("-news_date")[0:10]: | ||
item = Item(entry.news_date, entry.news_title, entry.news_source, entry.news_content, entry.news_key, | ||
entry.news_type, entry.news_image, entry.news_digest) | ||
news_item = convert_to_dict(item) | ||
data.append(news_item) | ||
|
||
return jsonify(state=True, data=data) | ||
|
||
|
||
@main.route('/recommend', methods=['GET']) | ||
def recommend(): | ||
email = request.args['email'] | ||
hobby = User.objects(user_email=email)[0].user_hobby | ||
|
||
if hobby == []: | ||
return jsonify(state=True, data=[]) | ||
|
||
data = [] | ||
|
||
count = 0; | ||
index = 0; | ||
|
||
while True: | ||
for type in hobby: | ||
for entry in NewsItem.objects(news_type=type_dict[type]).order_by("-news_date")[index:index + 1]: | ||
item = Item(entry.news_date, entry.news_title, entry.news_source, entry.news_content, entry.news_key, | ||
entry.news_type, entry.news_image, entry.news_digest) | ||
news_item = convert_to_dict(item) | ||
data.append(news_item) | ||
count += 1 | ||
if count >= 10: | ||
break | ||
if count >= 10: | ||
break | ||
index += 1 | ||
|
||
return jsonify(state=True, data=data) | ||
|
||
|
||
@main.route('/update', methods=['POST']) | ||
def update(): | ||
email = request.form['email'] | ||
hobby=[] | ||
|
||
if request.form['hobby'] != '[]': | ||
hobby = request.form['hobby'][2:-2].split('\",\"') | ||
|
||
User.objects(user_email=email).update_one(user_hobby=hobby) | ||
|
||
user = User.objects(user_email=email) | ||
|
||
item = user[0] | ||
|
||
userInfo = {} | ||
|
||
userInfo['nickname'] = item.user_nickname | ||
userInfo['email'] = item.user_email | ||
userInfo['hobby'] = item.user_hobby | ||
|
||
|
||
return jsonify(state=True, userInfo=userInfo) | ||
|
||
|
||
@main.route('/verify', methods=['GET']) | ||
def verify(): | ||
email = request.args['email'] | ||
password = request.args['password'] | ||
|
||
user = User.objects(user_email=email) | ||
|
||
if user.count() == 0: | ||
return jsonify(state=False, errormsg="不存在该用户名") | ||
|
||
item = user[0] | ||
|
||
userInfo = {} | ||
|
||
if item.user_password == password: | ||
userInfo['nickname'] = item.user_nickname | ||
userInfo['email'] = item.user_email | ||
userInfo['hobby'] = item.user_hobby | ||
return jsonify(state=True, userInfo=userInfo) | ||
else: | ||
return jsonify(state=False, errormsg="密码错误") | ||
|
||
|
||
@main.route('/register', methods=['POST']) | ||
def register(): | ||
user = User() | ||
user.user_nickname = request.form['nickname'] | ||
user.user_phone = request.form['phone'] | ||
user.user_password = request.form['password'] | ||
user.user_email = request.form['email'] | ||
user.user_hobby = [] | ||
user.save() | ||
return jsonify(state='true') | ||
|
||
|
||
@main.route('/get_list', methods=['GET']) | ||
def getNews(): | ||
type = request.args['type'] | ||
page = int(request.args['page']) | ||
|
||
news_type = type_dict[type] | ||
|
||
data = [] | ||
|
||
page_beign = 20 * (page - 1) | ||
|
||
page_end = 20 * page | ||
|
||
for entry in NewsItem.objects(news_type=news_type)[page_beign:page_end]: | ||
item = Item(entry.news_date, entry.news_title, entry.news_source, entry.news_content, entry.news_key, | ||
entry.news_type, entry.news_image, entry.news_digest) | ||
news_item = convert_to_dict(item) | ||
data.append(news_item) | ||
|
||
return jsonify(status='success', data=data) | ||
|
||
|
||
def convert_to_dict(obj): | ||
dict = {} | ||
dict.update(obj.__dict__) | ||
return dict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import datetime | ||
from manage import db | ||
|
||
class NewsItem(db.Document): | ||
news_date = db.DateTimeField(default=datetime.datetime.now, required=True) | ||
news_title = db.StringField(required=True) | ||
news_source = db.StringField(required=True) | ||
news_content = db.StringField(required=True) | ||
news_key = db.StringField(required=True) | ||
news_type = db.StringField(required=True) | ||
news_image = db.StringField(required=True) | ||
news_digest = db.StringField(required=True) | ||
|
||
meta = { | ||
'collection': 'news_data', | ||
'ordering': ['-create_at'], | ||
'strict': False, | ||
} | ||
|
||
class User(db.Document): | ||
user_nickname = db.StringField(max_length=20, required=True) | ||
user_email = db.StringField(max_length=20, required=True) | ||
user_phone = db.StringField(max_length=20, required=True) | ||
user_password = db.StringField(max_length=20, required=True) | ||
user_hobby = db.ListField(db.StringField(max_length=10, required=True)) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
.foot-wrap { | ||
position: relative; | ||
width: 100%; | ||
background-color: #373f48; | ||
margin-top: -270px; /* footer高度的负值 */ | ||
clear:both; | ||
} | ||
.row-content > h3 { | ||
color: #DDD; | ||
font-size: 16px; | ||
font-weight: 300; | ||
line-height: 16px; | ||
margin: 40px 0 30px 34px; | ||
} | ||
.row-content > ul { | ||
font-size: 13px; | ||
line-height: 24px; | ||
} | ||
.row-content > ul > li { | ||
list-style: none; | ||
} | ||
.row-content > ul > li > a { | ||
color: #878B91; | ||
} | ||
.row-content > ul > li > a:hover { | ||
text-decoration: none; | ||
color: #c1ba62; | ||
} | ||
ul.social { | ||
margin: 0; | ||
padding: 0; | ||
width: 100%; | ||
text-align: center; | ||
} | ||
ul.social > li { | ||
display: inline-block; | ||
} | ||
ul.social > li > a { | ||
display: inline-block; | ||
font-size: 18px; | ||
line-height: 30px; | ||
border-radius: 36px; | ||
color: #fff; | ||
margin: 0 3px 3px 0; | ||
} | ||
ul.social > li > a:hover { | ||
text-decoration: none; | ||
} |
Oops, something went wrong.