autotasker/examples/do_something_1.py

32 lines
993 B
Python
Raw Permalink Normal View History

import os, sys
2024-04-27 09:59:43 +00:00
import random
import string
from time import sleep
def main():
iterations = random.randint(15, int(os.getenv("SIMULATION_MAX_ITERATIONS") or 100))
2024-04-27 09:59:43 +00:00
speed = float(os.getenv("SIMULATION_SPEED") or 0.8)
print(f"Going for {iterations=} with {speed=}")
2024-04-27 09:59:43 +00:00
for i in range(iterations):
if random.uniform(0, 1) > 0.8:
print("Some error we will see", file=sys.stderr)
2024-04-27 09:59:43 +00:00
print(
str(i) + " " +
''.join(
random.sample(
" "+string.ascii_uppercase+string.ascii_lowercase+string.digits,
int(random.uniform(10, 50))
)
)
)
sleep(
(1/speed) * (0.02 * random.expovariate(0.5) +
2024-04-27 09:59:43 +00:00
(random.uniform(0, 1) if random.uniform(0, 1) > 0.8 else 0) +
(random.uniform(0, 5) if random.uniform(0, 1) > 0.99 else 0))
)
print("Done, script is finished")
2024-04-27 09:59:43 +00:00
if __name__ == "__main__":
main()