Improve EHentai backend
This commit is contained in:
parent
ee7ae31abf
commit
c74362edb7
3 changed files with 47 additions and 0 deletions
|
|
@ -20,6 +20,9 @@
|
|||
|
||||
from dateutil import tz
|
||||
from logging import warning
|
||||
from random import random
|
||||
from time import time, sleep
|
||||
from os import stat, utime
|
||||
import sys
|
||||
import traceback
|
||||
import types
|
||||
|
|
@ -117,3 +120,22 @@ def limit(iterator, lim):
|
|||
yield iterator.next()
|
||||
count += 1
|
||||
raise StopIteration()
|
||||
|
||||
def ratelimit(function, group, delay):
|
||||
path = '/tmp/weboob_ratelimit.%s' % group
|
||||
while True:
|
||||
try:
|
||||
offset = time() - stat(path).st_mtime
|
||||
except OSError:
|
||||
with open(path, 'w'):
|
||||
pass
|
||||
print 'creating %s' % path
|
||||
offset = 0
|
||||
|
||||
if delay < offset:
|
||||
break
|
||||
|
||||
sleep(delay - offset)
|
||||
|
||||
utime(path, None)
|
||||
function()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue