From 86dcf1756cfbf98b884b32beec163d2edb79a3ad Mon Sep 17 00:00:00 2001 From: n0str Date: Sun, 22 Sep 2024 17:23:48 +0300 Subject: [PATCH] Add some randomness to demo events --- example/fill_events.py | 22 ++++++++++++++++++++-- example/requirements.txt | 3 ++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/example/fill_events.py b/example/fill_events.py index dda7fd5..2915630 100644 --- a/example/fill_events.py +++ b/example/fill_events.py @@ -1,6 +1,9 @@ import random import os import hawkcatcher +from faker import Faker + +fake = Faker() def divide_by_zero(): a = random.randint(1, 100) @@ -32,6 +35,12 @@ def value_error(): invalid_strings = ['abc', 'NaN', 'invalid'] return int(random.choice(invalid_strings)) +def random_exception(): + title = fake.sentence(nb_words=6) + exception_types = [ValueError, KeyError, IndexError, TypeError, AssertionError, ZeroDivisionError] + selected_exception = random.choice(exception_types) + raise selected_exception(f"Error: {title}") + exceptions = [ divide_by_zero, trigger_manual_exception, invalid_operation, index_out_of_range, key_error, @@ -46,5 +55,14 @@ def value_error(): func = random.choice(exceptions) func() except Exception as e: - random_ip = f'{random.randint(1, 255)}.{random.randint(1, 255)}.{random.randint(1, 255)}.{random.randint(1, 255)}' - hawkcatcher.send(e, {'ip': random_ip, 'value': random.randint(1, 100)}) \ No newline at end of file + random_username = fake.user_name() + random_email = fake.email() + hawkcatcher.send(e, {'username': random_username, 'value': random_email}) + +for _ in range(2): + try: + random_exception() + except Exception as e: + random_username = fake.user_name() + random_email = fake.email() + hawkcatcher.send(e, {'username': random_username, 'value': random_email}) \ No newline at end of file diff --git a/example/requirements.txt b/example/requirements.txt index dccf877..e345682 100644 --- a/example/requirements.txt +++ b/example/requirements.txt @@ -1 +1,2 @@ -hawkcatcher \ No newline at end of file +hawkcatcher +faker \ No newline at end of file