PySPlus 0.1__tar.gz → 0.2__tar.gz

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,8 +1,8 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PySPlus
3
- Version: 0.1
3
+ Version: 0.2
4
4
  Summary: the library SPlus platform for bots.
5
- Home-page: https://github.com/OandONE/PySPlus
5
+ Home-page: https://github.com/OandONE/SPlus
6
6
  Author: seyyed mohamad hosein moosavi raja(01)
7
7
  Author-email: mohamadhosein159159@gmail.com
8
8
  License: MIT
@@ -10,6 +10,7 @@ Requires-Python: >=3.8
10
10
  Description-Content-Type: text/markdown
11
11
  Requires-Dist: selenium==4.29.0
12
12
  Requires-Dist: webdriver_manager==4.0.2
13
+ Requires-Dist: bs4==0.0.2
13
14
  Dynamic: author
14
15
  Dynamic: author-email
15
16
  Dynamic: description
@@ -33,4 +34,5 @@ This Python library is for SPlus platform bots and is currently being updated.
33
34
  ## install :
34
35
 
35
36
  ```bash
36
- pip install https://ParsSource.ir/PySPlus/PySPlus-0.1.tar.gz
37
+ pip install https://ParsSource.ir/PySPlus/PySPlus-0.2.tar.gz
38
+ ```
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PySPlus
3
- Version: 0.1
3
+ Version: 0.2
4
4
  Summary: the library SPlus platform for bots.
5
- Home-page: https://github.com/OandONE/PySPlus
5
+ Home-page: https://github.com/OandONE/SPlus
6
6
  Author: seyyed mohamad hosein moosavi raja(01)
7
7
  Author-email: mohamadhosein159159@gmail.com
8
8
  License: MIT
@@ -10,6 +10,7 @@ Requires-Python: >=3.8
10
10
  Description-Content-Type: text/markdown
11
11
  Requires-Dist: selenium==4.29.0
12
12
  Requires-Dist: webdriver_manager==4.0.2
13
+ Requires-Dist: bs4==0.0.2
13
14
  Dynamic: author
14
15
  Dynamic: author-email
15
16
  Dynamic: description
@@ -33,4 +34,5 @@ This Python library is for SPlus platform bots and is currently being updated.
33
34
  ## install :
34
35
 
35
36
  ```bash
36
- pip install https://ParsSource.ir/PySPlus/PySPlus-0.1.tar.gz
37
+ pip install https://ParsSource.ir/PySPlus/PySPlus-0.2.tar.gz
38
+ ```
@@ -7,5 +7,4 @@ PySPlus.egg-info/requires.txt
7
7
  PySPlus.egg-info/top_level.txt
8
8
  pysplus/Client.py
9
9
  pysplus/__init__.py
10
- pysplus/colors.py
11
- pysplus/test.py
10
+ pysplus/colors.py
@@ -1,2 +1,3 @@
1
1
  selenium==4.29.0
2
2
  webdriver_manager==4.0.2
3
+ bs4==0.0.2
@@ -11,4 +11,5 @@ This Python library is for SPlus platform bots and is currently being updated.
11
11
  ## install :
12
12
 
13
13
  ```bash
14
- pip install https://ParsSource.ir/PySPlus/PySPlus-0.1.tar.gz
14
+ pip install https://ParsSource.ir/PySPlus/PySPlus-0.2.tar.gz
15
+ ```
@@ -5,6 +5,7 @@ from selenium.webdriver.support import expected_conditions as EC
5
5
  from selenium.webdriver.chrome.service import Service
6
6
  from selenium.webdriver.chrome.options import Options
7
7
  from webdriver_manager.chrome import ChromeDriverManager
8
+ from bs4 import BeautifulSoup
8
9
  from .colors import *
9
10
  from typing import Optional
10
11
  import time,os,json,asyncio,logging,pickle
@@ -76,7 +77,8 @@ class Client:
76
77
  if not number.startswith("9"):
77
78
  return False
78
79
  return True
79
- async def login(self):
80
+ async def login(self) -> bool:
81
+ """لاگین / login"""
80
82
  chrome_options = Options()
81
83
  chrome_options.add_argument("--start-maximized")
82
84
  chrome_options.add_argument("--disable-notifications")
@@ -84,6 +86,7 @@ class Client:
84
86
  chrome_options.add_experimental_option("detach", True)
85
87
  service = Service(ChromeDriverManager().install())
86
88
  driver = webdriver.Chrome(service=service, options=chrome_options)
89
+ self.driver = webdriver.Chrome(service=service, options=chrome_options)
87
90
  wait = WebDriverWait(driver, 15)
88
91
  try:
89
92
  driver.get("https://web.splus.ir")
@@ -120,17 +123,62 @@ class Client:
120
123
  code_input = wait.until(
121
124
  EC.presence_of_element_located((By.CSS_SELECTOR, "input#sign-in-code"))
122
125
  )
126
+ self.code_html = driver.page_source
123
127
  code_input.clear()
124
128
  code_input.send_keys(verification_code)
125
- verify_button = wait.until(
126
- EC.element_to_be_clickable((By.XPATH, "//button[contains(text(), 'تأیید') or contains(text(), 'Verify')]"))
127
- )
128
- verify_button.click()
129
129
  time.sleep(5)
130
+ self.code_html = driver.page_source
131
+ messages = await self.get_chat_ids()
132
+ while not messages:
133
+ time.sleep(1)
134
+ self.code_html = driver.page_source
135
+ messages = await self.get_chat_ids()
130
136
  with open(self.name_cookies, 'wb') as file:
131
137
  pickle.dump(driver.get_cookies(), file)
132
138
  return True
133
139
  except Exception as e:
134
140
  driver.save_screenshot("error_screenshot.png")
141
+ print("ERROR :")
135
142
  print(e)
143
+ print("ERROR SAVED : error_screenshot.png")
144
+ return False
145
+ async def get_chat_ids(self) -> list:
146
+ """گرفتن چت آیدی ها / getting chat ids"""
147
+ soup = BeautifulSoup(self.code_html, "html.parser")
148
+ root = soup.select_one(
149
+ "body > #UiLoader > div.Transition.full-height > "
150
+ "#Main.left-column-shown.left-column-open > "
151
+ "#LeftColumn > #LeftColumn-main > div.Transition > "
152
+ "div.ChatFolders.not-open.not-shown > div.Transition > "
153
+ "div.chat-list.custom-scroll > div[style*='position: relative']"
154
+ )
155
+ chats = []
156
+ if root:
157
+ divs = root.find_all("div", recursive=True)
158
+ for div in divs:
159
+ anchors = div.find_all("a", href=True)
160
+ for a in anchors:
161
+ if a!=None:
162
+ chat = str(a["href"]).replace("#","")
163
+ chats.append(chat)
164
+ else:
165
+ print("❌ تگ ریشه پیدا نشد!")
166
+ return chats
167
+ async def send_text(self,chat_id:str,text:str) -> bool:
168
+ """ارسال متن / sending text"""
169
+ try:
170
+ self.driver.get(f"https://web.splus.ir/#{chat_id}")
171
+ time.sleep(3)
172
+ input_box = WebDriverWait(self.driver, 15).until(
173
+ EC.presence_of_element_located((By.CSS_SELECTOR, "div.input-message-input"))
174
+ )
175
+ input_box.click()
176
+ input_box.send_keys(text)
177
+ send_button = WebDriverWait(self.driver, 15).until(
178
+ EC.element_to_be_clickable((By.CSS_SELECTOR, "button.Button.send"))
179
+ )
180
+ send_button.click()
181
+ return True
182
+ except Exception as e:
183
+ print("Error in send_text:", e)
136
184
  return False
@@ -2,15 +2,15 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="PySPlus",
5
- version="0.1",
5
+ version="0.2",
6
6
  author="seyyed mohamad hosein moosavi raja(01)",
7
7
  author_email="mohamadhosein159159@gmail.com",
8
8
  description="the library SPlus platform for bots.",
9
9
  long_description=open("README.md").read(),
10
10
  long_description_content_type="text/markdown",
11
- url="https://github.com/OandONE/PySPlus",
11
+ url="https://github.com/OandONE/SPlus",
12
12
  packages=find_packages(),
13
13
  python_requires='>=3.8',
14
- install_requires=["selenium==4.29.0","webdriver_manager==4.0.2"],
14
+ install_requires=["selenium==4.29.0","webdriver_manager==4.0.2","bs4==0.0.2"],
15
15
  license="MIT"
16
16
  )
@@ -1,8 +0,0 @@
1
- from pysplus import Client
2
-
3
- bot = Client("test",number_phone="9017760881")
4
-
5
- async def m():
6
- await bot.login()
7
- import asyncio
8
- asyncio.run(m())
File without changes
File without changes
File without changes