leadguru-jobs 0.543.0__py3-none-any.whl → 0.545.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.1
2
2
  Name: leadguru_jobs
3
- Version: 0.543.0
3
+ Version: 0.545.0
4
4
  Summary: LGT jobs builds
5
5
  Author-email: developer@leadguru.co
6
6
  Classifier: Development Status :: 5 - Production/Stable
@@ -2,7 +2,7 @@ lgt_jobs/__init__.py,sha256=lrhMUJ7a5YSkYswQkQe981b_w8h8NHyncwfEduXEq6Q,1992
2
2
  lgt_jobs/basejobs.py,sha256=LPEclvY6fIG17YMGy9pRK0Q58n62gkI5W1BTK6R2p-c,1234
3
3
  lgt_jobs/env.py,sha256=cRO03GGvstUjBsv3uYO-iakrOvAk_ZWUP_fnmf21iZQ,789
4
4
  lgt_jobs/main.py,sha256=cK_nkBtJHnUNDbba1WZotqPtI_6OWxiYQkAgco9OAmE,1539
5
- lgt_jobs/runner.py,sha256=MZ3_UvfyDSM707UI4uPDntlKKCXkIyN6h95D1i1SoQQ,2125
5
+ lgt_jobs/runner.py,sha256=7KHpMHWwCjDlPDKnkNqrGAyIVn4Po62VqjYGVa85if8,2218
6
6
  lgt_jobs/simple_job.py,sha256=sta7MP-57iwRewPycmTAc9dvSbocbGjWhb1QYYj7ccA,519
7
7
  lgt_jobs/smtp.py,sha256=Svaq2ghMjGwpPA4J92wVnzrLlVbI2FcM2d4liiAbHLo,1210
8
8
  lgt_jobs/assets/images/arrow.png,sha256=Lr_zG1TyySAWX78jiojcV7j8BHe2S_Oi7eZYAfe4YbM,536
@@ -34,10 +34,10 @@ lgt_jobs/lgt_common/pubsub/messages.py,sha256=rm7uKbxwDTWJqsVA8Kee-4YT58bThjCEV2
34
34
  lgt_jobs/lgt_common/pubsub/pubsubfactory.py,sha256=rfUDooYuhBQ2pE9FdDxZOpXjbrvlpiiQLCGOtnTFbSg,2204
35
35
  lgt_jobs/lgt_common/slack_client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
36
36
  lgt_jobs/lgt_common/slack_client/methods.py,sha256=ctKF_1UHEmSWaRsoGEgMZicVabV7eEufZ7pjxdMAx8g,1455
37
- lgt_jobs/lgt_common/slack_client/slack_client.py,sha256=mbwHaqixC3xCJ0KP9WepxJtwlsJwTSEWQ2O1hx0hjXE,12173
38
- lgt_jobs/lgt_common/slack_client/web_client.py,sha256=vAfE6qrT1oTyP35chRsgeH008xtbsNGYdPqMqCdJmlE,6063
37
+ lgt_jobs/lgt_common/slack_client/slack_client.py,sha256=6Jgz0ELARcqknL9YBW4yph75E_AUsDGBsoTpcoYNMBQ,13479
38
+ lgt_jobs/lgt_common/slack_client/web_client.py,sha256=JOW-VGYYGqFZgyoqjOZ3t_XUdZAOttETVjVBZUWiUDM,6245
39
39
  lgt_jobs/lgt_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
40
- lgt_jobs/lgt_data/analytics.py,sha256=FJxImuuJw-m4B-eKIddytBy_B19BVsdPEHib-5gNgyo,20172
40
+ lgt_jobs/lgt_data/analytics.py,sha256=TFUffL8Dn-vIJ3ZaCVN-cj1Qnjb8F9GJyuk6Fo7mR1s,21645
41
41
  lgt_jobs/lgt_data/engine.py,sha256=Rsbz-CApAo_TVDssdjBkv8v_fVOZm_Uh1S6W4fnaEWo,7728
42
42
  lgt_jobs/lgt_data/enums.py,sha256=pZz8Xv-44hhhttb01ci4YnMIj7gS1oNnhX24XnuX5UM,2160
43
43
  lgt_jobs/lgt_data/helpers.py,sha256=NDa-V5EYaJfkGoWsmQSwSe6N_jxNxs8tHRQzW1iST6k,480
@@ -46,7 +46,7 @@ lgt_jobs/lgt_data/mongo_repository.py,sha256=6Cv5L90jUPgzTbv5vCjsGSOkeCdzVJf0pTR
46
46
  lgt_jobs/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
47
47
  lgt_jobs/services/web_client.py,sha256=GLWsJkIC8rv6xLFaLwcMm4EwBlVDu0njORwkZqBJaE4,2086
48
48
  lgt_jobs/templates/new_message.html,sha256=BD_E90akmQ1Wf07wtZAjeK_7DUKRmja5HFHVo_AKI24,6994
49
- leadguru_jobs-0.543.0.dist-info/METADATA,sha256=BSC1hi76_fPJxmBt6C__Sd9VpnWH9vfbEV8VWq6d1IU,1319
50
- leadguru_jobs-0.543.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
51
- leadguru_jobs-0.543.0.dist-info/top_level.txt,sha256=rIuw1DqwbnZyeoarBSC-bYeGOhv9mZBs7_afl9q4_JI,9
52
- leadguru_jobs-0.543.0.dist-info/RECORD,,
49
+ leadguru_jobs-0.545.0.dist-info/METADATA,sha256=BYTjMaCmqkJ4CNTyv5RTAuUQLInOEj_pWXKn2WDeuY0,1319
50
+ leadguru_jobs-0.545.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
51
+ leadguru_jobs-0.545.0.dist-info/top_level.txt,sha256=rIuw1DqwbnZyeoarBSC-bYeGOhv9mZBs7_afl9q4_JI,9
52
+ leadguru_jobs-0.545.0.dist-info/RECORD,,
@@ -1,3 +1,5 @@
1
+ import asyncio
2
+ import aiohttp
1
3
  import requests
2
4
  import json
3
5
  import io
@@ -22,6 +24,34 @@ class SlackClient:
22
24
  else:
23
25
  self.cookies = cookies
24
26
 
27
+ def join_channels(self, channels):
28
+ loop = asyncio.new_event_loop()
29
+ asyncio.set_event_loop(loop)
30
+ tasks = asyncio.gather(*[self.join_channel_async(channel) for channel in channels])
31
+ results = loop.run_until_complete(tasks)
32
+ loop.close()
33
+ return results
34
+
35
+ def leave_channels(self, channels):
36
+ loop = asyncio.new_event_loop()
37
+ asyncio.set_event_loop(loop)
38
+ tasks = asyncio.gather(*[self.leave_channel_async(channel) for channel in channels])
39
+ results = loop.run_until_complete(tasks)
40
+ loop.close()
41
+ return results
42
+
43
+ async def join_channel_async(self, channel):
44
+ async with aiohttp.ClientSession() as session:
45
+ url = f'{self.base_url}{SlackMethods.conversations_join}?{self.__channel_payload(channel)}'
46
+ async with session.post(url=url, cookies=self.cookies) as response:
47
+ return await response.json()
48
+
49
+ async def leave_channel_async(self, channel):
50
+ async with aiohttp.ClientSession() as session:
51
+ url = f'{self.base_url}{SlackMethods.conversations_leave}?{self.__channel_payload(channel)}'
52
+ async with session.post(url=url, cookies=self.cookies) as response:
53
+ return await response.json()
54
+
25
55
  def upload_file(self, file, file_name):
26
56
  payload = {"content": file, "filename": file_name}
27
57
  return requests.post(f"{self.base_url}{SlackMethods.upload_file}", data=payload,
@@ -158,3 +158,9 @@ class SlackWebClient:
158
158
 
159
159
  def get_file_info(self, file_id: str):
160
160
  return self.client.get_file_info(file_id)
161
+
162
+ def channel_join(self, channels):
163
+ return self.client.join_channels(channels)
164
+
165
+ def channel_leave(self, channels):
166
+ return self.client.leave_channels(channels)
@@ -81,6 +81,51 @@ def _prepare_date_analytics_doc(doc, ordered_result_dict: Dict[str, int]):
81
81
  ordered_result_dict[str_date] = item["count"]
82
82
  return ordered_result_dict
83
83
 
84
+ def get_channel_aggregated_analytics(from_date: datetime = None, to_date: datetime = None,
85
+ bot_id: Optional[str | ObjectId] = None):
86
+ pipeline = [
87
+ {
88
+ '$match': {
89
+ 'extra_ids': {"$in": [str(bot_id)]}
90
+ }
91
+ },
92
+ {
93
+ "$group": {
94
+ '_id': {
95
+ '$arrayElemAt': [
96
+ '$attributes', 0
97
+ ]
98
+ },
99
+ 'count': {"$sum": 1}
100
+ }
101
+ },
102
+ {
103
+ '$limit': 1000
104
+ }
105
+ ]
106
+
107
+ if from_date:
108
+ beginning_of_the_day = datetime(from_date.year, from_date.month, from_date.day, 0, 0, 0, 0)
109
+ pipeline.insert(0, {"$match": {"created_at": {"$gte": beginning_of_the_day}}})
110
+
111
+ if to_date:
112
+ end_of_the_day = datetime(to_date.year, to_date.month, to_date.day, 23, 59, 59, 999)
113
+ pipeline.insert(0, {"$match": {"created_at": {"$lte": end_of_the_day}}})
114
+
115
+ received_messages = list(db[f'received_messages'].aggregate(pipeline))
116
+ filtered_messages = list(db[f'filtered_messages'].aggregate(pipeline))
117
+
118
+ received_messages_dic = OrderedDict()
119
+ filtered_messages_dic = OrderedDict()
120
+
121
+ for item in received_messages:
122
+ received_messages_dic[item["_id"]] = item["count"]
123
+
124
+ for item in filtered_messages:
125
+ filtered_messages_dic[item["_id"]] = item["count"]
126
+
127
+ return received_messages_dic, filtered_messages_dic
128
+
84
129
 
85
130
  def get_aggregated_user_leads(user_id: Union[ObjectId, str],
86
131
  from_date: datetime,
lgt_jobs/runner.py CHANGED
@@ -32,13 +32,15 @@ class BackgroundJobRunner:
32
32
  BackgroundJobRunner.submit_data(job_data)
33
33
 
34
34
  @staticmethod
35
- def submit_data(data: dict):
35
+ def submit_data(data: dict, topic: str = None):
36
36
  json_str = json.dumps(data, ensure_ascii=False, default=datetime_converter)
37
- BackgroundJobRunner.submit_json(json_str)
37
+ BackgroundJobRunner.submit_json(json_str, topic)
38
38
 
39
39
  @staticmethod
40
- def submit_json(json_str: str):
41
- publish_message2_pubsub(background_jobs_topic, message_json=json_str)
40
+ def submit_json(json_str: str, topic: str = None):
41
+ if not topic:
42
+ topic = background_jobs_topic
43
+ publish_message2_pubsub(topic, message_json=json_str)
42
44
 
43
45
  @staticmethod
44
46
  def schedule(jib: str, job: type, data: BaseBackgroundJobData, scheduled_at: datetime):