Skip to content

Commit 34d1dec

Browse files
committed
Updated and moved the populate DB script
1 parent 42f2753 commit 34d1dec

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

backend/populate_database.py renamed to backend/PyMatcha/utils/populate_database.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import datetime
22
import json
3+
import os
34
import random
45
import string
56

@@ -20,10 +21,11 @@ def gen_datetime(min_year: int = 1900, max_year: int = datetime.datetime.now().y
2021
return start + (end - start) * random.random()
2122

2223

23-
def populate_users():
24-
User.drop_table()
25-
User.create_table()
26-
for i in range(0, 150):
24+
def populate_users(amount=150, drop_user_table=False):
25+
if drop_user_table:
26+
User.drop_table()
27+
User.create_table()
28+
for i in range(0, amount):
2729
gender = random.choice(["male", "female", "other"])
2830

2931
orientation = random.choice(["heterosexual", "homosexual", "bisexual", "other"])
@@ -58,7 +60,7 @@ def populate_users():
5860
username = first_name + end_of_username
5961

6062
try:
61-
u = User.create(
63+
User.create(
6264
first_name=first_name,
6365
last_name=last_name,
6466
email=email.lower(),
@@ -77,7 +79,8 @@ def populate_users():
7779
is_confirmed=True,
7880
confirmed_on=datetime.datetime.utcnow(),
7981
)
80-
with open("tags.json") as handle:
82+
dir_path = os.path.dirname(os.path.realpath(__file__))
83+
with open(dir_path + "/tags.json") as handle:
8184
json_list = json.load(handle)
8285
u = get_user(username)
8386
tags = list(set(random.sample(json_list, 8)))

0 commit comments

Comments
 (0)