90 lines
2.9 KiB
Python
90 lines
2.9 KiB
Python
#!/usr/bin/env python3
|
|
# chat.co авторег, ленты: farm2.py <count> <lane> <lanes>
|
|
import json, os, re, sys, time, imaplib, email, hashlib
|
|
import requests
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
from farm import API, CLIENT, H, SCOPES, UA, ts_token, wait_otp, reg_one, IMAP # noqa
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
POOL = os.path.join(HERE, 'pool.jsonl')
|
|
USED = os.path.join(HERE, 'used_emails.txt')
|
|
RES = os.path.join(HERE, 'reserved')
|
|
MAILFILE = 'C:/Users/User/tmp/mail66k/LIVE/live_all.txt'
|
|
os.makedirs(RES, exist_ok=True)
|
|
|
|
|
|
def log(*a):
|
|
print(time.strftime('%H:%M:%S'), *a, flush=True)
|
|
|
|
|
|
def claim(m):
|
|
key = hashlib.sha1(m.lower().strip().encode()).hexdigest()[:20]
|
|
try:
|
|
fd = os.open(os.path.join(RES, key), os.O_CREAT | os.O_EXCL | os.O_WRONLY)
|
|
os.write(fd, m.encode())
|
|
os.close(fd)
|
|
return True
|
|
except FileExistsError:
|
|
return False
|
|
|
|
|
|
def load_used():
|
|
s = set()
|
|
if os.path.exists(USED):
|
|
for l in open(USED, encoding='utf-8', errors='ignore'):
|
|
l = l.strip()
|
|
if l: s.add(l)
|
|
if os.path.exists(POOL):
|
|
for l in open(POOL, encoding='utf-8'):
|
|
try: s.add(json.loads(l)['email'])
|
|
except Exception: pass
|
|
if os.path.isdir(RES):
|
|
for f in os.listdir(RES):
|
|
try:
|
|
v = open(os.path.join(RES, f), encoding='utf-8', errors='ignore').read().strip()
|
|
if v: s.add(v)
|
|
except Exception:
|
|
pass
|
|
return s
|
|
|
|
|
|
def main():
|
|
n = int(sys.argv[1]); lane = int(sys.argv[2]); lanes = int(sys.argv[3])
|
|
used = load_used()
|
|
cand = []
|
|
idx = -1
|
|
for line in open(MAILFILE, encoding='utf-8', errors='ignore'):
|
|
line = line.strip()
|
|
if not line or ':' not in line: continue
|
|
m, p = line.rsplit(':', 1)
|
|
dom = m.split('@')[-1].lower()
|
|
if dom not in IMAP or dom == 'rediffmail.com': continue
|
|
idx += 1
|
|
if idx % lanes != lane: continue
|
|
if m in used: continue
|
|
cand.append((m, p))
|
|
if len(cand) >= n * 4: break
|
|
log('lane %d/%d candidates %d' % (lane, lanes, len(cand)))
|
|
ok = 0
|
|
for m, p in cand:
|
|
if ok >= n: break
|
|
if not claim(m):
|
|
log('SKIP ' + m + ' (reserved by other lane)')
|
|
continue
|
|
try:
|
|
res = reg_one(m, p); res['pw'] = p
|
|
except Exception as e:
|
|
res = {'email': m, 'ok': False, 'stage': 'exc', 'body': str(e)[:160]}
|
|
with open(POOL, 'a', encoding='utf-8') as f:
|
|
f.write(json.dumps(res, ensure_ascii=False) + '\n')
|
|
with open(USED, 'a', encoding='utf-8') as f:
|
|
f.write(m + '\n')
|
|
log(('OK ' if res.get('ok') else 'FAIL ') + m + ' ' + str(res.get('stage', '')) + ' ' + str(res.get('code', '')))
|
|
if res.get('ok'): ok += 1
|
|
time.sleep(2)
|
|
log('lane %d done ok=%d' % (lane, ok))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main() |