-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from abbeyokgo/master
update
- Loading branch information
Showing
20 changed files
with
1,239 additions
and
71 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -4,8 +4,9 @@ __pycache__/ | |
*$py.class | ||
|
||
parser.py | ||
parser_.py | ||
data.sqlite | ||
|
||
config.py | ||
# C extensions | ||
*.so | ||
|
||
|
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
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
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,49 @@ | ||
# coding:utf-8 | ||
from functools import wraps | ||
from flask import abort, redirect, url_for, g, request, jsonify | ||
from functools import update_wrapper | ||
import time | ||
from flask_login import current_user | ||
from . import rd | ||
from datetime import datetime | ||
|
||
|
||
class RateLimit(object): | ||
expiration_window = 10 | ||
|
||
def __init__(self, key_prefix, limit, per, send_x_headers): | ||
self.reset = (int(time.time()) // per) * per + per | ||
self.key = key_prefix + str(self.reset) | ||
self.limit = limit | ||
self.per = per | ||
self.send_x_headers = send_x_headers | ||
p = rd.pipeline() | ||
p.incr(self.key) | ||
p.expireat(self.key, self.reset + self.expiration_window) | ||
self.current = min(p.execute()[0], limit) | ||
remaining = property(lambda x: x.limit - x.current) | ||
over_limit = property(lambda x: x.current >= x.limit) | ||
|
||
|
||
def get_view_rate_limit(): | ||
return getattr(g, '_view_rate_limit', None) | ||
|
||
|
||
def on_over_limit(limit): | ||
return jsonify(dict(message='限制频率', status='fail')), 200 | ||
|
||
|
||
def ratelimit(limit, per=300, send_x_headers=True, | ||
over_limit=on_over_limit, | ||
scope_func=lambda: request.remote_addr, | ||
key_func=lambda: request.endpoint): | ||
def decorator(f): | ||
def rate_limited(*args, **kwargs): | ||
key = 'rate-limit/%s/%s/' % (key_func(), scope_func()) | ||
rlimit = RateLimit(key, limit, per, send_x_headers) | ||
g._view_rate_limit = rlimit | ||
if over_limit is not None and rlimit.over_limit: | ||
return over_limit(rlimit) | ||
return f(*args, **kwargs) | ||
return update_wrapper(rate_limited, f) | ||
return decorator |
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 |
---|---|---|
@@ -1,32 +1,37 @@ | ||
#-*- coding=utf-8 -*- | ||
from app import db | ||
|
||
#Tumblr | ||
# Tumblr | ||
|
||
|
||
class ID(db.Model): | ||
__tablename__='id_table' | ||
id=db.Column(db.String(64),primary_key=True) | ||
parseTimes=db.Column(db.Integer,default=0) #解析次数 | ||
updateTime=db.Column(db.String(64)) #最近更新时间 | ||
__tablename__ = 'id_table' | ||
id = db.Column(db.String(64), primary_key=True) | ||
parseTimes = db.Column(db.Integer, default=0) # 解析次数 | ||
updateTime = db.Column(db.String(64)) # 最近更新时间 | ||
postnum = db.Column(db.Integer) | ||
|
||
def __init__(self,**kwargs): | ||
super(ID,self).__init__(**kwargs) | ||
def __init__(self, **kwargs): | ||
super(ID, self).__init__(**kwargs) | ||
|
||
def __repr__(self): | ||
return self.id | ||
|
||
# | ||
|
||
|
||
class Context(db.Model): | ||
__tablename__='context_table' | ||
id=db.Column(db.String(64),primary_key=True) | ||
urls=db.Column(db.String(200),primary_key=True) | ||
isvideo=db.Column(db.Integer,default=0) #0=no,1=yes | ||
poster=db.Column(db.String(200)) | ||
|
||
def __init__(self,id,urls,isvideo,poster): | ||
self.id=id | ||
self.urls=urls | ||
self.isvideo=isvideo | ||
self.poster=poster | ||
__tablename__ = 'context_table' | ||
uid = db.Column(db.String(64), primary_key=True) | ||
pid=db.Column(db.String(64),primary_key=True) | ||
urls = db.Column(db.String(200)) | ||
isvideo = db.Column(db.Integer, default=0) # 0=no,1=yes | ||
poster = db.Column(db.String(200)) | ||
posttime = db.Column(db.DateTime()) | ||
description = db.Column(db.String(500)) | ||
|
||
def __init__(self, **kwargs): | ||
super(Context, self).__init__(**kwargs) | ||
|
||
def __repr__(self): | ||
return self.id | ||
return self.uid |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
Oops, something went wrong.