forked from david-vendel/facebook-auto-liker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
time_util.py
34 lines (24 loc) · 816 Bytes
/
time_util.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
"""Helper module to handle time related stuff"""
from random import gauss
from time import sleep as original_sleep
# Amount of variance to be introduced
# i.e. random time will be in the range: TIME +/- STDEV %
STDEV = 0.5
sleep_percentage = 1
def randomize_time(mean):
allowed_range = mean * STDEV
stdev = allowed_range / 3 # 99.73% chance to be in the allowed range
t = 0
while abs(mean - t) > allowed_range:
t = gauss(mean, stdev)
return t
def set_sleep_percentage(percentage):
global sleep_percentage
sleep_percentage = percentage/100
def sleep(t, custom_percentage=None):
if custom_percentage is None:
custom_percentage = sleep_percentage
time = randomize_time(t)*custom_percentage
original_sleep(time)
def sleep_actual(t):
original_sleep(t)