Skip to content

Commit 5bc6c71

Browse files
committed
Added random tags generation for populate_DB
1 parent 24ef302 commit 5bc6c71

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

backend/populate_database.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import datetime
2+
import json
23
import random
34
import string
45

@@ -7,8 +8,10 @@
78
import names
89
import PyMatcha.models.user as user_module
910
from PyMatcha.errors import ConflictError
11+
from PyMatcha.models.tag import Tag
1012

1113
User = user_module.User
14+
get_user = user_module.get_user
1215

1316

1417
def gen_datetime(min_year: int = 1900, max_year: int = datetime.datetime.now().year) -> datetime.datetime:
@@ -57,7 +60,7 @@ def populate_users():
5760
username = first_name + end_of_username
5861

5962
try:
60-
User.create(
63+
u = User.create(
6164
first_name=first_name,
6265
last_name=last_name,
6366
email=email.lower(),
@@ -68,7 +71,6 @@ def populate_users():
6871
orientation=orientation,
6972
birthdate=birthdate.date(),
7073
geohash=geohash,
71-
tags="", # TODO: Change to a real random tag generation
7274
heat_score=0,
7375
is_online=random.choice([True, False]),
7476
date_joined=date_joined,
@@ -77,6 +79,13 @@ def populate_users():
7779
is_confirmed=True,
7880
confirmed_on=datetime.datetime.utcnow(),
7981
)
82+
with open("tags.json") as handle:
83+
json_list = json.load(handle)
84+
u = get_user(username)
85+
tags = random.sample(json_list, 5)
86+
87+
for tag in tags:
88+
Tag.create(name=tag, user_id=u.id)
8089
except ConflictError:
8190
pass # Pass on the conflict error, this user wont be created because the username is taken. Who cares ?
8291
# TODO: Add images

backend/tags.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[
2+
"love",
3+
"instagood",
4+
"photooftheday",
5+
"fashion",
6+
"beautiful",
7+
"happy",
8+
"cute",
9+
"tbt",
10+
"like4like",
11+
"followme",
12+
"picoftheday",
13+
"follow",
14+
"me",
15+
"selfie",
16+
"summer",
17+
"art",
18+
"instadaily",
19+
"friends",
20+
"repost",
21+
"nature",
22+
"girl",
23+
"fun",
24+
"style",
25+
"smile",
26+
"food",
27+
"music",
28+
"games",
29+
"playing",
30+
"sex",
31+
"friends",
32+
"food",
33+
"travel"
34+
]

0 commit comments

Comments
 (0)