-
Notifications
You must be signed in to change notification settings - Fork 3
/
product_user.py
80 lines (64 loc) · 1.83 KB
/
product_user.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@File : product_user.py
@Time : 2023/10/09 19:31:53
@Author : lvguanjun
@Desc : product_user.py
"""
import json
from queue import Queue
from custom_log import logger
def error_handler(func):
def wrapper(line):
try:
return func(line)
except Exception as e:
logger.error(f"{line=}\n{e=}")
return iter([])
return wrapper
@error_handler
def deal_json(line):
line = json.loads(line)
return ((item["username"], item["password"]) for item in line)
@error_handler
def deal_4_line(line):
user, password = line.split("----", 1)
return iter([(user, password)])
@error_handler
def deal_2_equal(line):
user, password = line.split("==", 1)
return iter([(user, password)])
def product_user(file: str, q: Queue):
processed = set()
with open(file, "r") as f:
for line in f:
line = line.strip()
if not line:
continue
if "----" in line:
for item in deal_4_line(line):
if item in processed:
continue
q.put(item)
processed.add(item)
elif "==" in line:
for item in deal_2_equal(line):
if item in processed:
continue
q.put(item)
processed.add(item)
else:
for item in deal_json(line):
if item in processed:
continue
q.put(item)
processed.add(item)
q.put(None)
logger.info("queue add None, end")
if __name__ == "__main__":
file = "origin.txt"
q = Queue()
product_user(file, q)
print(q.get())
print(q.qsize())