1515from PyMatcha .utils .errors import ConflictError
1616from randomuser import RandomUser
1717
18+ FRANCE_GEOHASH_START = ("u0" , "gb" , "ez" , "sp" )
19+ NATIONALITIES_PARAMS = {"nat" : "fr" }
20+
1821
1922def gen_datetime (min_year : int = 1900 , max_year : int = datetime .datetime .now ().year ) -> datetime .datetime :
2023 # generate a datetime in format yyyy-mm-dd hh:mm:ss.000000
@@ -29,10 +32,10 @@ def populate_users(amount=150, drop_user_table=False):
2932 User .drop_table ()
3033 User .create_table ()
3134 try :
32- users = RandomUser .generate_users (amount = amount )
35+ users = RandomUser .generate_users (amount = amount , get_params = NATIONALITIES_PARAMS )
3336 except HTTPError :
3437 sleep (10 )
35- users = RandomUser .generate_users (amount = amount , get_params = { "nat" : "fr" } )
38+ users = RandomUser .generate_users (amount = amount , get_params = NATIONALITIES_PARAMS )
3639 for user in users :
3740 gender = random .choice (["male" , "female" , "other" ])
3841 if gender != "other" :
@@ -46,10 +49,9 @@ def populate_users(amount=150, drop_user_table=False):
4649
4750 coords = user .get_coordinates ()
4851 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" )):
52+ if not geohash .startswith (FRANCE_GEOHASH_START ):
5153 old = geohash [0 :2 ]
52- geohash = geohash .replace (old , "u0" , 1 )
54+ geohash = geohash .replace (old , FRANCE_GEOHASH_START [ 0 ] , 1 )
5355
5456 date_joined = gen_datetime (min_year = 2017 , max_year = datetime .datetime .now ().year )
5557
0 commit comments