77
88import Geohash
99import lorem
10+ import requests
1011from PyMatcha .models .image import Image
1112from PyMatcha .models .tag import Tag
1213from PyMatcha .models .user import get_user
@@ -31,7 +32,7 @@ def populate_users(amount=150, drop_user_table=False):
3132 users = RandomUser .generate_users (amount = amount )
3233 except HTTPError :
3334 sleep (10 )
34- users = RandomUser .generate_users (amount = amount )
35+ users = RandomUser .generate_users (amount = amount , get_params = { "nat" : "fr" } )
3536 for user in users :
3637 gender = random .choice (["male" , "female" , "other" ])
3738 if gender != "other" :
@@ -44,7 +45,11 @@ def populate_users(amount=150, drop_user_table=False):
4445 bio = lorem .paragraph ()
4546
4647 coords = user .get_coordinates ()
47- geohash = Geohash .encode (float (coords ["latitude" ]), float (coords ["longitude" ]))
48+ geohash = str (Geohash .encode (float (coords ["latitude" ]), float (coords ["longitude" ])))
49+ # u0, gb, ez, sp corresponds to the start of geohash inside of France
50+ if not geohash .startswith (("u0" , "gb" , "ez" , "sp" )):
51+ old = geohash [0 :2 ]
52+ geohash = geohash .replace (old , "u0" , 1 )
4853
4954 date_joined = gen_datetime (min_year = 2017 , max_year = datetime .datetime .now ().year )
5055
@@ -80,7 +85,8 @@ def populate_users(amount=150, drop_user_table=False):
8085
8186 for tag in tags :
8287 Tag .create (name = tag , user_id = u .id )
83- Image .create (user_id = u .id , link = user .get_picture (), is_primary = True )
88+ image_url = requests .get (f"https://picsum.photos/seed/{ username } /1000/1000" ).url
89+ Image .create (user_id = u .id , link = image_url , is_primary = True )
8490 except ConflictError :
8591 pass # Pass on the conflict error, this user wont be created because the username is taken. Who cares ?
8692
0 commit comments