Skip to content

Commit 54a269d

Browse files
committed
release
1 parent 44a827c commit 54a269d

File tree

4 files changed

+57
-27
lines changed

4 files changed

+57
-27
lines changed

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
# Coin bot
2-
Bot for click on telegram
2+
Async bot for click on telegram bots @Dogecoin_click_bot and etc.
33

4+
The bot works simultaneously with many accounts, makes requests from different proxy servers received automatically.
45

56
## Required
67

78
python 3.7 >=
89

9-
`pip install -r requirements.txt`
10+
`pip install -r requirements.txt`
11+
12+
## Running
13+
14+
1) Configurate your `config.json` file
15+
16+
2) Run command
17+
18+
```
19+
$ python -u .\main.py -c .\config.json
20+
```

main.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,14 @@ async def main():
6767
for cfg in config_data['clients']
6868
]
6969

70-
proxy_manager = ProxyManager()
70+
proxy_manager = ProxyManager('https://api.telegram.org')
7171

7272
while True:
7373
run_tasks = []
7474

75-
await proxy_manager.load_proxys()
76-
7775
print('run init bots')
7876
for bot in bots:
79-
proxy = await proxy_manager.get_proxy('https://api.telegram.org')
77+
proxy = await proxy_manager.get_proxy()
8078
await bot.client_init(proxy)
8179
run_tasks.append(bot.run())
8280

proxy.py

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
from aiohttp_socks import ProxyType, ProxyConnector, ChainProxyConnector
99

1010

11+
RE_PROXY = r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{2,6}'
12+
13+
1114
class ProxyObject:
1215
def __init__(self, ip, port):
1316
self.ip = ip
@@ -26,7 +29,7 @@ async def check_url(self, url):
2629
try:
2730
connector = ProxyConnector.from_url(self.get_str())
2831
async with aiohttp.ClientSession(connector=connector) as _sess:
29-
response = await _sess.get(url, timeout=2)
32+
response = await _sess.get(url, timeout=1)
3033
if response.status == 200:
3134
return True
3235
except Exception as e:
@@ -37,9 +40,19 @@ async def check_url(self, url):
3740

3841

3942
class ProxyManager:
40-
def __init__(self):
41-
self.biffer_proxys = []
42-
self.proxys = []
43+
def __init__(self, test_url):
44+
self.test_url = test_url
45+
self.queue_proxys = asyncio.Queue()
46+
47+
loop = asyncio.get_event_loop()
48+
loop.create_task(self.load_loop())
49+
50+
async def load_loop(self):
51+
while True:
52+
if self.queue_proxys.empty():
53+
await self.load_proxys()
54+
55+
await asyncio.sleep(10)
4356

4457
async def load_proxys(self):
4558
print("run load proxy")
@@ -60,25 +73,32 @@ async def load_proxys(self):
6073
raise Exception(f'Failed request to "{url}" url')
6174

6275
text = await response.text()
63-
x = re.findall(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{2,6}', text)
6476

65-
pxs = [x.split(':') for x in text.split('\n')]
66-
self.biffer_proxys = [ProxyObject(x[0], x[1]) for x in pxs if len(x) == 2]
67-
print(f'load {len(self.proxys)} proxys')
77+
proxys = []
6878

69-
async def get_proxy(self, test_url):
70-
print('getting proxy')
71-
count_try = 0
72-
while count_try < 10:
73-
if len(self.proxys) == 0:
74-
await self.load_proxys()
79+
for line in re.findall(RE_PROXY, text):
80+
sp = line.split(':')
81+
if len(sp) != 2:
82+
continue
83+
proxy = ProxyObject(sp[0], sp[1])
84+
proxys.append(proxy)
85+
86+
print(f'find {len(proxys)} proxys')
87+
88+
while len(proxys) > 0:
89+
batch_proxys = proxys[:20]
90+
proxys = proxys[20:]
7591

76-
proxy = self.proxys.pop()
92+
checked = await asyncio.gather(*[
93+
proxy.check_url(self.test_url)
94+
for proxy in batch_proxys
95+
])
7796

78-
if await proxy.check_url(test_url):
79-
print(f"Proxy {proxy} find success")
80-
return proxy
97+
print(f'checked {len(checked)} proxys')
8198

82-
await asyncio.sleep(1)
99+
for i, proxy in enumerate(batch_proxys):
100+
if checked[i]:
101+
self.queue_proxys.put_nowait(proxy)
83102

84-
raise Exception("Max count trys getting proxy =(")
103+
async def get_proxy(self):
104+
return await self.queue_proxys.get()

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
telethon
22
pysocks
3-
aiohttp
3+
aiohttp
4+
aiohttp_socks

0 commit comments

Comments
 (0)