leadguru-jobs 0.562.0__py3-none-any.whl → 0.564.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.562.0
3
+ Version: 0.564.0
4
4
  Summary: LGT jobs builds
5
5
  Author-email: developer@leadguru.co
6
6
  Classifier: Development Status :: 5 - Production/Stable
@@ -1,4 +1,4 @@
1
- lgt_jobs/__init__.py,sha256=kmM5J3qBJd-fOZa2I4gkh36IytrgN6_18gWwwpR3n6Y,2156
1
+ lgt_jobs/__init__.py,sha256=cZDNBmksAzKFe5frsPpucpYfC-3YlAhw2-cVzmMe8Oo,2335
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
@@ -16,6 +16,7 @@ lgt_jobs/jobs/bot_stats_update.py,sha256=R6mf5FxhWbyx92AYXlj0FZVjz2Tgz86mBvLHrsQ
16
16
  lgt_jobs/jobs/chat_history.py,sha256=tZ4XyOGdy1k6r4uotxSSKbXjTR_oRK6Ym0YthFYBtl8,6200
17
17
  lgt_jobs/jobs/connect_sources.py,sha256=uVO_kH-Hxn7HkYUNGNcS7Mu3jB7KlB4pU5qcdtR2hrM,4260
18
18
  lgt_jobs/jobs/inbox_leads.py,sha256=EYxdQPseNBY5ON7BK3LpnXDCgQpzHTPLRJCZmZiAAHA,5582
19
+ lgt_jobs/jobs/load_slack_people.py,sha256=az3Pl8_0nUXizShpCksH6XMHFALLkta4QpMr_MkM9Io,3199
19
20
  lgt_jobs/jobs/mass_message.py,sha256=1mFcBlL2MhzLbj5yrd_NyJc7TXDWCcROAzGDnr0miMU,2035
20
21
  lgt_jobs/jobs/send_code.py,sha256=dIlLPkG3GgGKIEqGiElyzrtdrnJNTL1Ak2V0xnE-WIQ,824
21
22
  lgt_jobs/jobs/send_slack_message.py,sha256=IuRqDGcDrz2EAZzF6nrLXO0aSA4mETB_tGOEbcMhjHE,2562
@@ -47,7 +48,7 @@ lgt_jobs/lgt_data/mongo_repository.py,sha256=wdhslZTfTU-3Ad4Gm8NVl9HZFM5aK_vgG47
47
48
  lgt_jobs/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
48
49
  lgt_jobs/services/web_client.py,sha256=GLWsJkIC8rv6xLFaLwcMm4EwBlVDu0njORwkZqBJaE4,2086
49
50
  lgt_jobs/templates/new_message.html,sha256=BD_E90akmQ1Wf07wtZAjeK_7DUKRmja5HFHVo_AKI24,6994
50
- leadguru_jobs-0.562.0.dist-info/METADATA,sha256=KoLJrkMpvPsywYTmEQy6vwxcHtLNXubHITY0VZbN4xY,1319
51
- leadguru_jobs-0.562.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
52
- leadguru_jobs-0.562.0.dist-info/top_level.txt,sha256=rIuw1DqwbnZyeoarBSC-bYeGOhv9mZBs7_afl9q4_JI,9
53
- leadguru_jobs-0.562.0.dist-info/RECORD,,
51
+ leadguru_jobs-0.564.0.dist-info/METADATA,sha256=zUJWfUtlRCENXNuDciV3gCHhSe2LYFTrKXHPgVg71as,1319
52
+ leadguru_jobs-0.564.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
53
+ leadguru_jobs-0.564.0.dist-info/top_level.txt,sha256=rIuw1DqwbnZyeoarBSC-bYeGOhv9mZBs7_afl9q4_JI,9
54
+ leadguru_jobs-0.564.0.dist-info/RECORD,,
lgt_jobs/__init__.py CHANGED
@@ -12,6 +12,7 @@ from .basejobs import (BaseBackgroundJobData, BaseBackgroundJob, InvalidJobTypeE
12
12
  from .smtp import (SendMailJob, SendMailJobData)
13
13
  from .runner import (BackgroundJobRunner)
14
14
  from .simple_job import (SimpleTestJob, SimpleTestJobData)
15
+ from .jobs.load_slack_people import (LoadSlackPeopleJob, LoadSlackPeopleJobData)
15
16
 
16
17
  jobs_map = {
17
18
  "SimpleTestJob": SimpleTestJob,
@@ -23,7 +24,8 @@ jobs_map = {
23
24
  "SendSlackMessageJob": SendSlackMessageJob,
24
25
  "UpdateUserBalanceJob": UpdateUserBalanceJob,
25
26
  "SendMassMessageSlackChannelJob": SendMassMessageSlackChannelJob,
26
- "ConnectSourceJob": ConnectSourceJob
27
+ "ConnectSourceJob": ConnectSourceJob,
28
+ "LoadSlackPeopleJob": LoadSlackPeopleJob
27
29
  }
28
30
  __all__ = [
29
31
  # Jobs
@@ -38,6 +40,7 @@ __all__ = [
38
40
  UpdateUserBalanceJob,
39
41
  SendMassMessageSlackChannelJob,
40
42
  ConnectSourceJob,
43
+ LoadSlackPeopleJob,
41
44
 
42
45
  # module classes
43
46
  BackgroundJobRunner,
@@ -54,6 +57,7 @@ __all__ = [
54
57
  UpdateUserBalanceJobData,
55
58
  SendMassMessageSlackChannelJobData,
56
59
  ConnectSourceJobData,
60
+ LoadSlackPeopleJobData,
57
61
  # mapping
58
62
  jobs_map
59
63
  ]
@@ -0,0 +1,73 @@
1
+ from abc import ABC
2
+ from lgt_jobs.lgt_common.enums.slack_errors import SlackErrors
3
+ from lgt_jobs.lgt_common.slack_client.slack_client import SlackClient
4
+ from lgt_jobs.lgt_data.model import Source, SlackMemberInformation
5
+ from lgt_jobs.lgt_data.mongo_repository import DedicatedBotRepository, SlackContactUserRepository
6
+ import logging as log
7
+ from pydantic import BaseModel
8
+ from lgt_jobs.basejobs import BaseBackgroundJobData, BaseBackgroundJob
9
+
10
+ """
11
+ Load Slack people by required bot
12
+ """
13
+
14
+
15
+ class LoadSlackPeopleJobData(BaseBackgroundJobData, BaseModel):
16
+ bot_id: str
17
+
18
+
19
+ class LoadSlackPeopleJob(BaseBackgroundJob, ABC):
20
+ @property
21
+ def job_data_type(self) -> type:
22
+ return LoadSlackPeopleJobData
23
+
24
+ def exec(self, data: LoadSlackPeopleJobData):
25
+ dedicated_bots_repo = DedicatedBotRepository()
26
+ bot = dedicated_bots_repo.get_one(id=data.bot_id)
27
+ log.info(f'Start Scraping for [{str(bot.user_id)}:{bot.source.source_id}]')
28
+
29
+ client = SlackClient(bot.token, bot.cookies)
30
+ try:
31
+ list_users_response = client.users_list()
32
+ except:
33
+ log.error(f'Error to get users [{str(bot.user_id)}:{bot.source.source_id}]')
34
+ return
35
+
36
+ members_count = 0
37
+ while True:
38
+ if not list_users_response["ok"] and list_users_response['error'] == SlackErrors.INVALID_AUTH:
39
+ bot.invalid_creds = True
40
+ dedicated_bots_repo.add_or_update(bot)
41
+ log.error(f'Error during listing [{bot.source.source_name}:{bot.source.source_id}] '
42
+ f'members: {list_users_response["error"]}')
43
+ return
44
+
45
+ if not list_users_response.get('members', []):
46
+ log.warning(f'No members in [{str(bot.user_id)}:{bot.source.source_id}]: {list_users_response}')
47
+ return
48
+
49
+ for member in list_users_response["members"]:
50
+ if not member.get("profile"):
51
+ continue
52
+
53
+ if member.get("deleted", True) or member.get("id") == 'USLACKBOT':
54
+ continue
55
+
56
+ source = Source()
57
+ source.source_id = bot.source.source_id
58
+ source.source_name = bot.source.source_name
59
+ source.source_type = bot.source.source_type
60
+ member_info: SlackMemberInformation = SlackMemberInformation.from_slack_response(member, source)
61
+ members_count += 1
62
+ member_info_dic = member_info.to_dic()
63
+ member_info_dic.pop('created_at')
64
+ SlackContactUserRepository().collection().update_one({"sender_id": member_info.sender_id,
65
+ "source.source_id": source.source_id},
66
+ {"$set": member_info_dic}, upsert=True)
67
+
68
+ next_cursor = list_users_response["response_metadata"].get("next_cursor", "")
69
+ if next_cursor == "":
70
+ log.info(f'[{str(bot.user_id)}:{bot.source.source_id}] loading done. {members_count} loaded')
71
+ break
72
+
73
+ list_users_response = client.users_list(next_cursor)