-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_persons.py
More file actions
159 lines (130 loc) · 4.33 KB
/
add_persons.py
File metadata and controls
159 lines (130 loc) · 4.33 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import argparse
import random
from datetime import datetime, timezone
from Mongo_db import get_collection, db
AGE_OPTIONS = ["Under 18", "18-20", "21-23", "24-26", "27+"]
GENDER_OPTIONS = ["Male", "Female", "Prefer not to say"]
HOBBY_OPTIONS = [
"Programming",
"Sports",
"Art",
"Music",
"Gaming",
"Gym",
"Chess",
"Photography",
]
LANGUAGE_OPTIONS = ["Italian", "English", "Bilingual"]
ITALIAN_BRAINROT_NAMES = [
"Gigachad Gennaro",
"Spaghettino Supremo",
"Pasta Wizard Piero",
"Mozzarella Maverick",
"Risotto Rambo",
"Espresso Enforcer",
"Cappuccino Commando",
"Lasagna Legend",
"Polenta Phantom",
"Cannolo Crusher",
"Zio Sigma Salvo",
"Nonno Turbo Nino",
"Trenbolone Tonino",
"Focaccia Fury Fabio",
"Biscotto Boss Beppe",
"Mandolino Matrix Marco",
"Pesto Paladin Paolo",
"Carbonara Captain Carlo",
"Tiramisu Titan Tino",
"Gelato Gladiator Gianni",
]
def username_from_name(name: str, idx: int) -> str:
compact = "".join(ch for ch in name.lower() if ch.isalnum())
return f"{compact[:18]}_{idx}"
def make_fake_user(idx: int) -> dict:
name = ITALIAN_BRAINROT_NAMES[idx % len(ITALIAN_BRAINROT_NAMES)]
hobby_count = random.randint(2, 4)
hobbies = random.sample(HOBBY_OPTIONS, hobby_count)
return {
"telegram_user_id": 900000 + idx,
"username": username_from_name(name, idx),
"display_name": name,
"in_group": random.choice([True, False]),
"age": random.choice(AGE_OPTIONS),
"gender": random.choice(GENDER_OPTIONS),
"hobbies": hobbies,
"language": random.choice(LANGUAGE_OPTIONS),
"completed": True,
"updated_at": datetime.now(timezone.utc),
}
def seed_users(count: int) -> tuple[int, int]:
collection = get_collection()
inserted = 0
updated = 0
for i in range(count):
user_doc = make_fake_user(i)
result = collection.update_one(
{"telegram_user_id": user_doc["telegram_user_id"]},
{
"$set": user_doc,
"$setOnInsert": {"created_at": datetime.now(timezone.utc)},
},
upsert=True,
)
if result.upserted_id is not None:
inserted += 1
else:
updated += 1
return inserted, updated
def seed_groups_with_space():
groups_col = db["groups"]
users_col = db["users"]
# Get the fake users we just created (IDs >= 900000)
fake_users = list(users_col.find({"telegram_user_id": {"$gte": 900000}}))
group_names = [
"Study_Club_AI",
"Python_Beginners",
"Data_Crunchers",
"Cyber_Security_Lab",
"ML_Enthusiasts",
"Web_Dev_Squad",
"Deep_Learning_Circle",
]
user_idx = 0
for g_name in group_names:
# Check if we still have users left to assign
if user_idx >= len(fake_users):
print(f"Stopping at {g_name}: No more fake users available to fill groups.")
break
# Pick 1 to 3 users
num_members = random.randint(1, 3)
members_for_this_group = fake_users[user_idx : user_idx + num_members]
user_idx += num_members
member_ids = [u["telegram_user_id"] for u in members_for_this_group]
leader_id = member_ids[0]
groups_col.update_one(
{"name": g_name},
{"$set": {"name": g_name, "leader_id": leader_id, "members": member_ids}},
upsert=True,
)
users_col.update_many(
{"telegram_user_id": {"$in": member_ids}},
{"$set": {"group_name": g_name, "in_group": True}},
)
print(f"Groups successfully seeded: {group_names[:user_idx]}")
def main() -> None:
parser = argparse.ArgumentParser(description="Seed fake users into MongoDB")
parser.add_argument("--count", type=int, default=20, help="Number of fake users")
parser.add_argument(
"--seed", type=int, default=42, help="Random seed for reproducible data"
)
args = parser.parse_args()
if args.count <= 0:
raise ValueError("--count must be greater than 0")
random.seed(args.seed)
inserted, updated = seed_users(args.count)
print(
f"Seeding complete. Requested={args.count}, inserted={inserted}, updated={updated}"
)
seed_groups_with_space()
if __name__ == "__main__":
main()