advio 0.0.1__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.
advio/__init__.py ADDED
@@ -0,0 +1,11 @@
1
+
2
+ from .config import Settings,logger
3
+ from .version import __version__
4
+ from .tg import AdvioTG
5
+
6
+
7
+ from .utils import banner
8
+
9
+ banner()
10
+
11
+
advio/cli.py ADDED
@@ -0,0 +1,5 @@
1
+
2
+ def main():
3
+ from .tg import AdvioTG
4
+
5
+
advio/config.py ADDED
@@ -0,0 +1,103 @@
1
+
2
+
3
+ from loguru import logger
4
+ import sys,json
5
+ from pathlib import Path
6
+ from typing import Optional
7
+
8
+
9
+ logger.remove()
10
+ logger.add(sink = sys.stdout, format = '<c><b>{time:YYYY-MM-DD HH:mm:ss}</b></c> | <level>{level: <8}</level> | <white><b>{message}</b></white>')
11
+ logger = logger.opt(colors = True)
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+ class Settings:
20
+ def __init__(
21
+ self,
22
+ sessions_path: Optional[str] = None,
23
+ join_list: Optional[str] = None,
24
+ sleep_time: Optional[int] = None,
25
+ telegram: Optional[str] = None,
26
+ last_index: Optional[int] = None
27
+ ):
28
+ """
29
+ Initialize the Settings object
30
+
31
+ Parameters
32
+ ----------
33
+ sessions_path : str, optional
34
+ Path to the sessions file. Default is 'sessions.ses'.
35
+ join_list : str, optional
36
+ Path to the join list file. Default is 'join_list.txt'.
37
+ sleep_time : int, optional
38
+ Time in seconds to sleep between joins. Default is 1.
39
+ telegram : str, optional
40
+ Telegram client type. Default is 'A'.
41
+ - 'A' => Android
42
+ - 'X' => AndroidX
43
+ - 'W' => Windows
44
+ - 'I' => iOS
45
+ - 'L' => Linux
46
+ - 'M' => macOS
47
+ - 'MD'=> macOS Desktop
48
+ last_index : int, optional
49
+ Last index of the join list. Default is 0.
50
+ """
51
+ self.SETTINGS_JSON = self._resolve_path('settings.json')
52
+ data = self._load()
53
+
54
+ self.sessions_path = sessions_path or data.get('sessions_path', 'sessions.ses')
55
+ self.join_list = join_list or data.get('join_list', 'join_list.txt')
56
+ self.sleep_time = sleep_time if sleep_time is not None else data.get('sleep_time', 1)
57
+ self.telegram = self._telegram(telegram, data)
58
+ self.last_index = last_index if last_index is not None else data.get('last_index', 0)
59
+
60
+ self._save()
61
+
62
+ def _resolve_path(self, filename: str) -> str:
63
+ path = Path(filename)
64
+ if not path.is_absolute():
65
+ path = Path.cwd() / path
66
+ path.parent.mkdir(parents=True, exist_ok=True)
67
+ return str(path)
68
+
69
+ @staticmethod
70
+ def _telegram(current_value: Optional[str], data: dict[str, str]) -> str:
71
+ allowed_values = ['A', 'X', 'W', 'I', 'L', 'M', 'MD']
72
+ value = current_value or data.get('telegram', 'A')
73
+ value = value.upper()
74
+ return value if value in allowed_values else 'A'
75
+
76
+ def _load(self) -> dict:
77
+ try:
78
+ with open(self.SETTINGS_JSON, encoding='utf8') as f:
79
+ return json.load(f)
80
+ except (FileNotFoundError, json.JSONDecodeError):
81
+ return {}
82
+
83
+ def _save(self) -> None:
84
+ data = {
85
+ "sessions_path": self.sessions_path,
86
+ "join_list": self.join_list,
87
+ "sleep_time": self.sleep_time,
88
+ "telegram": self.telegram,
89
+ "last_index": self.last_index
90
+ }
91
+ with open(self.SETTINGS_JSON, 'w', encoding='utf8') as f:
92
+ json.dump(data, f, indent=4, ensure_ascii=False)
93
+
94
+ def _update(self, key: str, value) -> None:
95
+ setattr(self, key, value)
96
+ data = self._load()
97
+ data[key] = value
98
+ self._save()
99
+
100
+ def next_index(self) -> int:
101
+ self.last_index += 1
102
+ self._update('last_index', self.last_index)
103
+ return self.last_index
advio/tg.py ADDED
@@ -0,0 +1,131 @@
1
+ from .config import logger
2
+ from teloxi import TeloxiClient,Storage,Account,Device
3
+ from dbflux import Sqlite
4
+ from itertools import cycle
5
+ from .config import Settings
6
+ import asyncio
7
+ from typing import Tuple,Dict
8
+ from .utils import parse_phone
9
+
10
+ class AdvioTG:
11
+
12
+ def __init__(self,settings:Settings=None,proxy:Tuple|Dict=None):
13
+
14
+ self.settings = Settings() if not settings else settings
15
+ self.sessions = Storage(Sqlite(self.settings._resolve_path(self.settings.sessions_path)))
16
+ self.proxy = proxy
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+ async def register(self):
25
+
26
+ devices={
27
+ 'A':Device.TelegramAndroid,
28
+ 'X':Device.TelegramAndroidX,
29
+ 'W':Device.TelegramWindows,
30
+ 'I':Device.TelegramIOS,
31
+ 'L':Device.TelegramLinux,
32
+ 'M':Device.TelegramMacOS,
33
+ 'MD':Device.TelegramMacosDesktop
34
+ }
35
+ device=lambda t: devices.get(t,Device.TelegramAndroid).Generate()
36
+
37
+ try:
38
+ while True:
39
+ phone=input("Enter a valid phone number (or 'END' to cancel): ")
40
+ if not phone :
41
+ continue
42
+ if phone.upper()=='END':
43
+ break
44
+
45
+ if not parse_phone(phone):
46
+ print("Invalid phone number format. Please try again.")
47
+ continue
48
+ self.sessions.delete(conditions= [Account.session_id==phone, Account.status=='INACTIVE'])
49
+ client=TeloxiClient(session_id=phone,device=device(self.settings.telegram), database=self.sessions,proxy=self.proxy)
50
+ try:
51
+ await client.start(phone=phone)
52
+ except Exception as e:
53
+ logger.error(f"<r>{e.__class__.__name__}: {e}</r>")
54
+
55
+
56
+ except KeyboardInterrupt:
57
+ print("\nRegistration cancelled by user.")
58
+
59
+
60
+
61
+ async def get_login_code(self):
62
+ def callback(message, code):
63
+
64
+ if code:
65
+
66
+ logger.success(f"<g>login code: {message}</g>")
67
+ else:
68
+ logger.info(f"<y>{message}</y>")
69
+
70
+
71
+ try:
72
+ while True:
73
+ phone=input("Enter a valid phone number (or 'END' to cancel): ")
74
+ if not phone :
75
+ continue
76
+ if phone.upper()=='END':
77
+ break
78
+
79
+ if not parse_phone(phone):
80
+ print("Invalid phone number format. Please try again.")
81
+ continue
82
+ accounts:list[Account]=self.sessions.get(conditions=[Account.session_id==phone, Account.status=='ACTIVE'])
83
+ if not accounts:
84
+ logger.error('<r>Account not found OR account is not active</r>')
85
+ continue
86
+ account=accounts[0]
87
+ try:
88
+ client=TeloxiClient(session_id=account.session_id, database=self.sessions,proxy=self.proxy)
89
+ await client.connect()
90
+ if not await client.is_user_authorized():
91
+ logger.error("<r>Account not authorized</r>")
92
+ continue
93
+
94
+ await client.get_login_code(callback=callback)
95
+ except Exception as e:
96
+ logger.error(f"<r>{e.__class__.__name__}: {e}</r>")
97
+ finally:
98
+ await client.disconnect()
99
+
100
+ except KeyboardInterrupt:
101
+ print("\nGet login code cancelled by user.")
102
+
103
+ async def join_chats(self):
104
+ pass
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+
advio/utils.py ADDED
@@ -0,0 +1,52 @@
1
+ from colored import fg, attr
2
+ from itertools import cycle
3
+ from .version import __version__
4
+ from telethon.utils import parse_phone
5
+
6
+ def banner():
7
+ banner_txt = '''\
8
+ █████╗ ██████╗ ██╗ ██╗██╗ ██████╗
9
+ ██╔══██╗██╔══██╗██║ ██║██║██╔═══██╗
10
+ ███████║██║ ██║██║ ██║██║██║ ██║
11
+ ██╔══██║██║ ██║╚██╗ ██╔╝██║██║ ██║
12
+ ██║ ██║██████╔╝ ╚████╔╝ ██║╚██████╔╝
13
+ ╚═╝ ╚═╝╚═════╝ ╚═══╝ ╚═╝ ╚═════╝
14
+ '''
15
+ border_color=fg(124)
16
+ colors=cycle([129,128,127,126,125,124])
17
+ border='{}║{}'.format(border_color,fg(0))
18
+
19
+ text=''
20
+ first_line=''
21
+ end_line=''
22
+ max_length=0
23
+ for line in banner_txt.split("\n"):
24
+ if line.strip():
25
+ if not first_line:
26
+ length=len(line)
27
+ if length > max_length:
28
+ max_length=length
29
+
30
+ c=next(colors)
31
+ line=f"{fg(c)}{line:<{max_length}}{fg(0)}"
32
+ text+=f"{border} {line} {border}\n"
33
+
34
+ first_line ='{}╔{}╗{}\n'.format(border_color,"═"*(max_length+2),fg(0))
35
+ end_line ='{}╚{}╝{}\n'.format(border_color,"═"*(max_length+2),fg(0))
36
+ logo= f"{first_line}{text}{end_line}"
37
+
38
+ _name=f'Advio {__version__}'
39
+
40
+ logo+="{}{}{}\n".format(border_color,"▄"*(max_length+4),fg(0))
41
+ logo+=f"{border_color}▌{fg(14)}{_name:<{max_length-14}}{border_color}▐{fg(48)} ABBAS BACHARI {border_color}▐\n"
42
+ logo+="{}{}{}\n".format(border_color,"▀"*(max_length+4),fg(0))
43
+
44
+
45
+ logo+=f" {attr('bold')+fg(70)}{'Support Channel':<{max_length-15}}{fg(1)}:{attr(0)+attr('bold')+fg(80)} @COIN98{attr(0)}"
46
+ logo+="\n\n"
47
+
48
+
49
+ print(logo)
50
+ return logo
51
+
52
+
advio/version.py ADDED
@@ -0,0 +1 @@
1
+ __version__='0.0.1'
@@ -0,0 +1,107 @@
1
+ Metadata-Version: 2.4
2
+ Name: advio
3
+ Version: 0.0.1
4
+ Summary: Smart tool for sending automated
5
+ Author-email: Abbas Bachari <abbas-bachari@hotmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/abbas-bachari/advio
8
+ Project-URL: Documentation, https://github.com/abbas-bachari/advio#readme
9
+ Project-URL: Source, https://github.com/abbas-bachari/advio
10
+ Keywords: advertising,automation,marketing,bot,telegram
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Operating System :: OS Independent
17
+ Requires-Python: >=3.10
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: teloxi>=1.0.1
21
+ Requires-Dist: dbflux>=1.0.2
22
+ Requires-Dist: loguru>=0.7.3
23
+ Requires-Dist: colored>=2.3.0
24
+ Dynamic: license-file
25
+
26
+
27
+ <h1 align="center">🚀 Advio: Smart Advertising Tool</h1>
28
+ <p align="center">
29
+ <!-- PyPI Version -->
30
+ <a href="https://pypi.org/project/advio/">
31
+ <img src="https://img.shields.io/pypi/v/advio?style=plastic" alt="PyPI - Version">
32
+ </a>
33
+ <!-- Python Versions -->
34
+ <a href="https://pypi.org/project/advio/">
35
+ <img src="https://img.shields.io/pypi/pyversions/advio?style=plastic" alt="Python Versions">
36
+ </a>
37
+ <!-- License -->
38
+ <a href="https://pypi.org/project/advio/">
39
+ <img src="https://img.shields.io/pypi/l/advio?style=plastic" alt="License">
40
+ </a>
41
+ <!-- Downloads -->
42
+ <a href="https://pepy.tech/project/advio">
43
+ <img src="https://pepy.tech/badge/advio?style=flat-plastic" alt="Downloads">
44
+ </a>
45
+ <!-- Issues -->
46
+ <a href="https://github.com/abbas-bachari/advio/issues">
47
+ <img src="https://img.shields.io/github/issues/abbas-bachari/advio?style=plastic" alt="GitHub Issues">
48
+ </a>
49
+ </p>
50
+
51
+ ---
52
+
53
+ ## **Advio** is a smart tool for sending automated advertisements
54
+
55
+ ### 🛠️ Version: 0.0.1
56
+
57
+ ---
58
+
59
+ ## 📥 Installation
60
+
61
+ ```bash
62
+ pip install advio
63
+ ```
64
+
65
+ ## 💡 Quick Start
66
+
67
+ ```python
68
+ from advio import AdvioTG,Settings
69
+ ```
70
+
71
+ ---
72
+
73
+ ## 🧑‍💻 Usage
74
+
75
+ ```python
76
+ from advio import AdvioTG,Settings
77
+ ```
78
+
79
+ ---
80
+
81
+ ## ⚙️ Configuration
82
+
83
+ ```python
84
+ from advio import AdvioTG,Settings
85
+
86
+ telegram_proxy=['http','127.0.0.1', 10808]
87
+ settings = Settings(sessions_path='sessions.ses', join_list='join_list.txt', sleep_time=1, telegram='A', last_index=0)
88
+ advio = AdvioTG(settings=settings,proxy=telegram_proxy)
89
+
90
+ ```
91
+
92
+
93
+ ## **Links**
94
+
95
+ - [PyPI](https://pypi.org/project/advio/)
96
+ - [GitHub](https://github.com/abbas-bachari/advio)
97
+
98
+ ## **License**
99
+
100
+ Advio is released under the MIT License.
101
+
102
+ ## 👤 About the Author
103
+
104
+ **Abbas Bachari / عباس بچاری** – Developer & Maintainer of **Advio**
105
+
106
+ - 📧 Telegram: [@abbas_bachari](https://t.me/abbas_bachari)
107
+ - 🌐 GitHub: [github.com/abbas-bachari](https://github.com/abbas-bachari)
@@ -0,0 +1,12 @@
1
+ advio/__init__.py,sha256=IGkNHLu2l4qb5_5wT5OxNwhOoCla2PYRHGbWZ2PD2xo,145
2
+ advio/cli.py,sha256=V-zFDlIzZ6wSHDZNPpiUxCA1RFYjIf5t0epqyY09rEE,53
3
+ advio/config.py,sha256=WAUeJ8EjkYxlIXQ1AJbtNp7crPkmmi3lf0Uc61eY7TA,3456
4
+ advio/tg.py,sha256=5LC2vcP02kyy3J8Iz1yROt3o9cvsFbZVV3XR19d1y78,4181
5
+ advio/utils.py,sha256=HoRdOHwsU066bIJv0w7lTmW0FkW2C6tswS87xaPbp8U,2064
6
+ advio/version.py,sha256=9qOVvDFyV7XnDRnLUDmjB7jNR6W3OQM0jPjt7XLAOsY,19
7
+ advio-0.0.1.dist-info/licenses/LICENSE,sha256=4gy6qRGewuG4RwIBJn5PRCxoWt1Ohlk9uCImEopfyMY,1089
8
+ advio-0.0.1.dist-info/METADATA,sha256=dihxIZbyRJ6QAAjlenU7ETSDIaQg4vMscpXDTw7UnR0,3036
9
+ advio-0.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
10
+ advio-0.0.1.dist-info/entry_points.txt,sha256=yWqRBB6Ug7Dk_jwl721joXJ2Tzu-2DpGnfd1VwQfMNg,41
11
+ advio-0.0.1.dist-info/top_level.txt,sha256=iakfOfgcgy4I6Xx6-ze47eMLq7GHcLn6XRxQzVQIwRk,6
12
+ advio-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ advio = advio.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Abbas bachari
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ advio