koenverhagen commited on
Commit
ae213bd
1 Parent(s): d94a30f
Files changed (2) hide show
  1. consts.py +1 -0
  2. createlookalike.py +22 -9
consts.py ADDED
@@ -0,0 +1 @@
 
 
1
+ API_KEY ='34dsadfF$$%#$TGREGEFGE%Q*)(*&%'
createlookalike.py CHANGED
@@ -23,6 +23,7 @@ from collections import OrderedDict
23
  #
24
  # from generate_csv_file import generate_csv_files
25
  # from load_data import load_data, get_shops
 
26
  from schemas import Shop
27
 
28
 
@@ -140,18 +141,15 @@ async def calculate_shop(shop: Shop, feat_extractor) -> None:
140
  design_list.append(v)
141
 
142
  design_dict = {"shop_id": shop.id, "design": im,
143
- "results": design_list
144
  }
145
 
146
  print(design_dict)
147
- try:
148
- response = requests.post(shop.webhook_url, json=design_dict)
149
- if response.status_code == 200:
150
- print(f"result for {im} is sent to {shop.webhook_url}")
151
- else:
152
- print(f"Error sending data {shop.webhook_url} to for result {im}: {response.status_code}")
153
- except Exception as e:
154
- print(f"Error sending data {shop.webhook_url} to for result {im}: {response.status_code}", e)
155
 
156
  # idx_closest = sorted(range(len(similar_idx)), key=lambda k: similar_idx[k])
157
 
@@ -164,3 +162,18 @@ async def calculate_shop(shop: Shop, feat_extractor) -> None:
164
  end = datetime.today()
165
 
166
  # return {'shop_id': shop.id, 'start_time': start, 'end_time': end, 'designs': design_json}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  #
24
  # from generate_csv_file import generate_csv_files
25
  # from load_data import load_data, get_shops
26
+ from consts import API_KEY
27
  from schemas import Shop
28
 
29
 
 
141
  design_list.append(v)
142
 
143
  design_dict = {"shop_id": shop.id, "design": im,
144
+ "recommendations": design_list
145
  }
146
 
147
  print(design_dict)
148
+ if await push_home(design_dict, im, shop):
149
+ pass
150
+ else:
151
+ raise
152
+
 
 
 
153
 
154
  # idx_closest = sorted(range(len(similar_idx)), key=lambda k: similar_idx[k])
155
 
 
162
  end = datetime.today()
163
 
164
  # return {'shop_id': shop.id, 'start_time': start, 'end_time': end, 'designs': design_json}
165
+
166
+
167
+ async def push_home(design_dict, im, shop):
168
+ headers: dict[str, str] = {
169
+ "Authorization": API_KEY,
170
+ "Content-type": "application/json",
171
+ }
172
+ try:
173
+
174
+ response = requests.post(shop.webhook_url, json=design_dict, headers=headers)
175
+ response.raise_for_status()
176
+ return True
177
+
178
+ except Exception as e:
179
+ return False