-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbsc_newcoin_finder.py
184 lines (152 loc) · 6.69 KB
/
bsc_newcoin_finder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import json
import os
import traceback
import webbrowser
from itertools import cycle
from random import choice, uniform
from time import sleep
import requests
from pydash import get as _
from selectolax.parser import HTMLParser
MIN_HOLDERS = 10
MAX_HOLDERS = 100
USER_AGENTS = [
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.2 Safari/605.1.15',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36',
'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36',
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36'
]
def random_ua():
return choice(USER_AGENTS)
def file2list(filename):
result = []
if os.path.isfile(filename):
with open(filename, encoding='utf-8') as f:
return f.read().splitlines()
return []
def load_proxy():
proxies = set()
if os.path.exists('./proxy.txt'):
with open('./proxy.txt', 'r') as f:
for line in f:
px = line.strip().split(':')
proxies.add(f'http://{px[2]}:{px[3]}@{px[0]}:{px[1]}')
return proxies
proxies = cycle(load_proxy())
coins = set(file2list('coins.txt'))
def get_text(selector: str, soup: HTMLParser):
try:
t = (soup.css_first(selector) if selector else soup).text(
separator=' ', strip=True).replace('\xa0', ' ').replace(
'\t', ' ').replace('\r', ' ').replace('\n', ' ').strip()
while ' ' in t:
t = t.replace(' ', ' ')
return t
except:
return ''
def rand_sleep(start, end):
sleep(uniform(start, end))
def to_int(s):
try:
return int(s.replace(',', '').replace(' ', '').strip())
except:
return 0
def sync_fetch(url: str, session=None, headers=None):
tried = 0
while tried < 5:
try:
proxy = next(proxies, None)
print(f'Getting {url}')
return (session or requests).get(
url,
headers=headers if headers else {'User-Agent': random_ua()},
timeout=30,
proxies={
'http': proxy,
'https': proxy
} if proxy else None)
except KeyboardInterrupt:
raise KeyboardInterrupt('Abort')
except:
traceback.print_exc()
tried += 1
sleep(1)
def get_next_elements(selector: str, next_selector, text, soup: HTMLParser):
try:
elements = []
for el in soup.css(selector):
t = el.text().replace('\xa0', ' ').strip()
if text == t:
start = False
for cnode in el.parent.iter():
if cnode == el:
start = True
elif start:
elements.append(cnode)
return elements
except:
return None
def get_attr(selector: str, attr: str, soup: HTMLParser):
try:
return (soup.css_first(selector) if selector else soup).attributes.get(
attr, '').replace('\xa0', ' ').strip()
except:
return ''
def sync_bs(url: str, session=None):
r = sync_fetch(url, session)
soup = HTMLParser(r.text if r else '')
return soup
def main():
while True:
try:
soup = sync_bs('https://bscscan.com/tokentxns')
for el in soup.css('#content td a'):
href = get_attr(None, 'href', el)
if '/token/' in href and '/images/main/empty-token.png' in get_attr(
'img', 'src', el):
url = f'https://bscscan.com{href}'
poocoin_url = f'http://poocoin.app/tokens/{href.split("/token/")[-1]}'
if url not in coins:
s = sync_bs(url)
t = get_text(None, s)
if 'LPs' in t or '-LP' in t or 'BLP' in t:
continue
els = get_next_elements('div', 'div', 'Holders:', s)
if els:
for node in els:
text = get_text(None, node)
if 'addresses' in text:
holders = to_int(
text.split('addresses')[0])
print(holders, text)
if MIN_HOLDERS < holders < MAX_HOLDERS:
webbrowser.open(url)
webbrowser.open(poocoin_url)
break
if holders > MIN_HOLDERS:
coins.add(url)
rand_sleep(1, 3)
except KeyboardInterrupt:
return
except:
traceback.print_exc()
sleep(1)
if __name__ == '__main__':
try:
main()
finally:
with open('coins.txt', 'w', encoding='utf-8') as f:
f.write('\n'.join(coins))