11import itertools
22from typing import List
3+ from typing import Optional
34
45from fuzzywuzzy import fuzz
56from Geohash import decode
67from geopy .distance import distance
78from PyMatcha .models .user import User
89
910
10- def _get_distance (geohash_1 : str , geohash_2 : str ) -> float :
11- coords_1 = decode (geohash_1 )
12- coords_2 = decode (geohash_2 )
13- return distance (coords_1 , coords_2 ).kilometers
11+ def _get_distance (geohash_1 : str , geohash_2 : str ) -> Optional [float ]:
12+ try :
13+ coords_1 = decode (geohash_1 )
14+ coords_2 = decode (geohash_2 )
15+ except TypeError :
16+ return None
17+ else :
18+ return distance (coords_1 , coords_2 ).kilometers
1419
1520
1621def _get_common_tags (tag_list_1 : list , tag_list_2 : list ) -> List [str ]:
@@ -33,28 +38,34 @@ def _get_gender_query(orientation, gender):
3338 if gender == "female" :
3439 q1 = User .get_multis (orientation = orientation , gender = "male" )
3540 q2 = User .get_multis (orientation = "other" , gender = "male" )
36- return q1 .extend (q2 )
41+ q1 .extend (q2 )
42+ return q1
3743 elif gender == "male" :
3844 q1 = User .get_multis (orientation = orientation , gender = "female" )
3945 q2 = User .get_multis (orientation = "other" , gender = "female" )
40- return q1 .extend (q2 )
46+ q1 .extend (q2 )
47+ return q1
4148 else :
4249 q1 = User .get_multis (orientation = orientation , gender = "female" )
4350 q2 = User .get_multis (orientation = orientation , gender = "male" )
44- return q1 .extend (q2 )
51+ q1 .extend (q2 )
52+ return q1
4553 elif orientation == "homosexual" :
4654 if gender == "female" :
4755 q1 = User .get_multis (orientation = orientation , gender = "female" )
4856 q2 = User .get_multis (orientation = "other" , gender = "female" )
49- return q1 .extend (q2 )
57+ q1 .extend (q2 )
58+ return q1
5059 elif gender == "male" :
5160 q1 = User .get_multis (orientation = orientation , gender = "male" )
5261 q2 = User .get_multis (orientation = "other" , gender = "male" )
53- return q1 .extend (q2 )
62+ q1 .extend (q2 )
63+ return q1
5464 else :
5565 q1 = User .get_multis (orientation = orientation , gender = "female" )
5666 q2 = User .get_multis (orientation = orientation , gender = "male" )
57- return q1 .extend (q2 )
67+ q1 .extend (q2 )
68+ return q1
5869 elif orientation == "bisexual" :
5970 q1 = User .get_multis (orientation = orientation , gender = "female" )
6071 q3 = User .get_multis (orientation = orientation , gender = "male" )
0 commit comments