leadguru-jobs 0.726.0__py3-none-any.whl → 0.728.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: leadguru_jobs
3
- Version: 0.726.0
3
+ Version: 0.728.0
4
4
  Summary: LGT jobs builds
5
5
  Author-email: developer@leadguru.co
6
6
  Classifier: Development Status :: 5 - Production/Stable
@@ -32,11 +32,13 @@ Requires-Dist: mongoengine
32
32
  Requires-Dist: google
33
33
  Requires-Dist: google-cloud-pubsub
34
34
  Requires-Dist: google-cloud-storage
35
+ Requires-Dist: google-cloud-logging
35
36
  Requires-Dist: websockets
36
37
  Requires-Dist: aiohttp
37
38
  Requires-Dist: nameparser
38
39
  Requires-Dist: loguru
39
40
  Requires-Dist: redmail
41
+ Requires-Dist: tenacity
40
42
  Dynamic: author-email
41
43
  Dynamic: classifier
42
44
  Dynamic: requires-dist
@@ -4,7 +4,7 @@ lgt_jobs/env.py,sha256=HHlpQgZrRQMMuPZYhP94A8b29T_10sKRo98mh0_hh3Y,907
4
4
  lgt_jobs/main.py,sha256=zd0TdwFBUXUmFfUw552rPt6Rd_uG-LWEE6wTs8TCxIk,2081
5
5
  lgt_jobs/runner.py,sha256=pS-Qwyfuk22aQ1Mk3p-Q0ysdZfKy1Bh9YoWBlDaLeM8,2234
6
6
  lgt_jobs/simple_job.py,sha256=EBxhre3749GEAzJyaV1GXYy3P0pzwHchxcZ2kSN1vWU,527
7
- lgt_jobs/smtp.py,sha256=sAW-ewNgHEFYI3AhUNipmXqGFfvpdphX2oRHmHu0yIo,1304
7
+ lgt_jobs/smtp.py,sha256=M9RBuXdz9YyBwBZiA92EalqQWI5DDGdpRJlkum-zS8U,1787
8
8
  lgt_jobs/assets/images/arrow.png,sha256=Lr_zG1TyySAWX78jiojcV7j8BHe2S_Oi7eZYAfe4YbM,536
9
9
  lgt_jobs/assets/images/arrow_blue.png,sha256=opxsLU7K6C2tNfvFSvDvi9xcZBDf3t6jPz4TESN07o8,572
10
10
  lgt_jobs/assets/images/firework.png,sha256=9d_0lUpDFfT3e4JTgp5XVb03qAdtO9yNVi1c1KoQDp8,33754
@@ -38,10 +38,10 @@ lgt_jobs/lgt_common/pubsub/messages.py,sha256=rm7uKbxwDTWJqsVA8Kee-4YT58bThjCEV2
38
38
  lgt_jobs/lgt_common/pubsub/pubsubfactory.py,sha256=rfUDooYuhBQ2pE9FdDxZOpXjbrvlpiiQLCGOtnTFbSg,2204
39
39
  lgt_jobs/lgt_common/slack_client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
40
40
  lgt_jobs/lgt_common/slack_client/methods.py,sha256=ctKF_1UHEmSWaRsoGEgMZicVabV7eEufZ7pjxdMAx8g,1455
41
- lgt_jobs/lgt_common/slack_client/slack_client.py,sha256=x3JNoj107SCNUHZFYgeQv46Coi_hrO-xEL8mZxVGBTM,15248
41
+ lgt_jobs/lgt_common/slack_client/slack_client.py,sha256=CgqAPrkFDanzqTnWV_pCcDWdWHZ-t3aDDQhTNxUngxA,14042
42
42
  lgt_jobs/lgt_common/slack_client/web_client.py,sha256=WCu8mqYhauuxp9iDAMsjocchKD78iWdcnbu7Ozdyzq8,3448
43
43
  lgt_jobs/lgt_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
44
- lgt_jobs/lgt_data/analytics.py,sha256=yfrFPXrBofzZqUNn479JkrbZXDa2ljgk-Le0YrQ9rew,21690
44
+ lgt_jobs/lgt_data/analytics.py,sha256=H9YgALytIAWDM14ZkaFNRUaeb6foBJT5-Nvz_pu3gKA,21689
45
45
  lgt_jobs/lgt_data/engine.py,sha256=GY8FOl3dl7euKjQRML_H3ophaSTgfQ8ICMRv1NpE2oE,7745
46
46
  lgt_jobs/lgt_data/enums.py,sha256=xNE5uIot8yT2Yl6HufTYlPiR0uSJVP2fNbnObL5tsNE,2669
47
47
  lgt_jobs/lgt_data/helpers.py,sha256=S_1P7pnx14dllmen-TzjA9pkKWQr39x8-v6iv7FUYnQ,423
@@ -109,7 +109,7 @@ lgt_jobs/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU
109
109
  lgt_jobs/services/k8_manager.py,sha256=bXpka9psIQ5UJ6QG_e4xolmE_3gtmNrzzZeL03bJ62I,995
110
110
  lgt_jobs/services/web_client.py,sha256=oMyWJxwGeIe3f40fPT7xcisjDg3BhA3Ipf8dr1jVT-Y,1549
111
111
  lgt_jobs/templates/new_message.html,sha256=dZl8UmdAOOMq4nidvAgMFroSrTV7Pw0RWt2yLp_2idg,6989
112
- leadguru_jobs-0.726.0.dist-info/METADATA,sha256=BxF6izlWM2VOZwvqx3rtNDNe0av9CqzPf5ir_UF1S8k,1399
113
- leadguru_jobs-0.726.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
114
- leadguru_jobs-0.726.0.dist-info/top_level.txt,sha256=rIuw1DqwbnZyeoarBSC-bYeGOhv9mZBs7_afl9q4_JI,9
115
- leadguru_jobs-0.726.0.dist-info/RECORD,,
112
+ leadguru_jobs-0.728.0.dist-info/METADATA,sha256=IIF9KrHRr1SReaoo7qWAPPS9AkQmByjLDK25zdEtf8M,1459
113
+ leadguru_jobs-0.728.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
114
+ leadguru_jobs-0.728.0.dist-info/top_level.txt,sha256=rIuw1DqwbnZyeoarBSC-bYeGOhv9mZBs7_afl9q4_JI,9
115
+ leadguru_jobs-0.728.0.dist-info/RECORD,,
@@ -4,7 +4,6 @@ import requests
4
4
  import json
5
5
  import io
6
6
  from urllib import parse
7
- from pyppeteer import launch
8
7
  from requests import Response
9
8
  from websockets.client import WebSocketClientProtocol
10
9
  from lgt_jobs.lgt_common.slack_client.methods import SlackMethods
@@ -214,38 +213,6 @@ class SlackClient:
214
213
  headers = {'User-Agent': user_agent}
215
214
  response = requests.post(f"{self.base_url}{SlackMethods.confirm_email}", data=payload, headers=headers)
216
215
  result = response.json()['ok'] if response.status_code == 200 else False
217
-
218
- print(f"Result is {result}")
219
- if not result:
220
- print("Start pyppeteer")
221
- try:
222
- async def send_code():
223
- print("Launch browser")
224
- browser = await launch(headless=True)
225
- page = await browser.newPage()
226
-
227
- print("Go to Slack")
228
- await page.goto('https://slack.com/signin', waitUntil='networkidle2')
229
-
230
- print("Type email")
231
- await page.waitForSelector('input#signup_email')
232
- await page.type('input#signup_email', email)
233
- await asyncio.sleep(1.324)
234
-
235
- print("Press the button to submit")
236
- button = await page.querySelector('button#submit_btn')
237
- await button.tap()
238
-
239
- print("Wait for the next page")
240
- await page.waitForSelector('input[aria-label="digit 1 of 6"]')
241
-
242
- print("Close the browser")
243
- await browser.close()
244
-
245
- asyncio.run(send_code())
246
- return True
247
- except:
248
- return False
249
216
  return result
250
217
 
251
218
  def confirm_code(self, email: str, code: str, user_agent: str) -> requests.Response:
@@ -368,12 +368,11 @@ def get_date_aggregated_analytics(source_id=None, started_at: datetime = None,
368
368
  pipeline: list = _build_date_aggregated_analytics_pipeline(source_id=source_id, started_at=started_at,
369
369
  ended_at=ended_at, bots_ids=bots_ids)
370
370
 
371
- received_messages = list(db[f'received_messages'].aggregate(pipeline))
372
-
373
371
  if configs is not None:
374
- pipeline.insert(0, {"$match": {"attributes": {'$in': configs}}})
372
+ pipeline.insert(0, {"$match": {"configs.id": {'$in': configs}}})
375
373
 
376
374
  filtered_messages = list(db[f'filtered_messages'].aggregate(pipeline))
375
+ received_messages = list(db[f'received_messages'].aggregate(pipeline))
377
376
 
378
377
  received_messages_dic = _create_result_dic(started_at, ended_at)
379
378
  filtered_messages_dic = _create_result_dic(started_at, ended_at)
lgt_jobs/smtp.py CHANGED
@@ -1,3 +1,4 @@
1
+ from tenacity import retry, stop_after_attempt, wait_fixed, retry_if_exception_type
1
2
  from abc import ABC
2
3
  from pydantic import BaseModel
3
4
  import logging as log
@@ -13,11 +14,11 @@ gmail = EmailSender(
13
14
  username=smtp_login,
14
15
  password=smtp_password
15
16
  )
17
+
16
18
  """
17
19
  Send email
18
20
  """
19
21
 
20
-
21
22
  class SendMailJobData(BaseBackgroundJobData, BaseModel):
22
23
  html: str
23
24
  subject: str
@@ -31,10 +32,13 @@ class SendMailJob(BaseBackgroundJob, ABC):
31
32
  def job_data_type(self) -> type:
32
33
  return SendMailJobData
33
34
 
34
- def exec(self, data: SendMailJobData):
35
- body_image = {}
36
- for image in data.images:
37
- body_image[f'IMAGE_{ImageName(image.value).name}'] = f'lgt_jobs/assets/images/{image.value}'
35
+ @retry(
36
+ stop=stop_after_attempt(3),
37
+ wait=wait_fixed(5),
38
+ retry=retry_if_exception_type(Exception),
39
+ reraise=True
40
+ )
41
+ def send_email(self, data: SendMailJobData, body_images_map: dict):
38
42
  with gmail:
39
43
  if not gmail.is_alive:
40
44
  gmail.connect()
@@ -43,6 +47,16 @@ class SendMailJob(BaseBackgroundJob, ABC):
43
47
  receivers=[data.recipient],
44
48
  subject=data.subject,
45
49
  html=data.html,
46
- body_images=body_image
50
+ body_images=body_images_map
47
51
  )
48
- log.info('email message has been sent')
52
+ log.info('email message has been sent')
53
+
54
+ def exec(self, data: SendMailJobData):
55
+ body_images_map = {
56
+ f'IMAGE_{ImageName(image.value).name}': f'lgt_jobs/assets/images/{image.value}'
57
+ for image in data.images
58
+ }
59
+ try:
60
+ self.send_email(data, body_images_map)
61
+ except Exception as e:
62
+ log.error(f"Failed to send email after retries: {e}")