This repository has been archived by the owner on Mar 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.py
64 lines (46 loc) · 1.46 KB
/
controller.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from peewee import IntegrityError
from model import User, Post, Comment, Up, Sensitive
from app import app
try:
dup_check_list = range(app.config.get('DUP_MAX_SIZE'))
pre_comment = Comment.select().order_by(Comment.created_at.desc()).limit(app.config.get('DUP_MAX_SIZE'))
for item in pre_comment:
dup_check_list.pop(0)
dup_check_list.append(item.text)
sensitive_list = [i.word for i in Sensitive.select()]
recent_comments = Comment.select() \
.group_by(Comment.ip) \
.order_by(Comment.created_at.desc()) \
.limit(app.config.get('RCTC_MAX_SIZE'))
except Exception, err:
app.logger.warning(err)
def up(post_id, ip):
record = Post.select().where(Post.id == post_id).get()
try:
Up.create(ip=ip, post=post_id)
except IntegrityError, err:
app.logger.error(err)
else:
record.up_time += 1
ret = record.up_time
record.save()
return ret
def duplicate_check(content):
if content in dup_check_list:
return None
else:
dup_check_list.pop(0)
dup_check_list.append(content)
return content
def sensitive_check(content):
for word in sensitive_list:
content = content.replace(word, '*' * len(word))
return content
def comment_check(content):
dup_res = duplicate_check(content)
if not dup_res:
return None
sen_res = sensitive_check(dup_res)
return sen_res