feat: faker data: identification
This commit is contained in:
35
service/faker_data.py
Normal file
35
service/faker_data.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import requests
|
||||
import threading
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
from lxml import etree
|
||||
from faker import Faker
|
||||
|
||||
executor = ThreadPoolExecutor(max_workers=10)
|
||||
faker = Faker(["zh_CN"])
|
||||
|
||||
|
||||
def faker_identification():
|
||||
identification = faker.ssn(max_age=70)
|
||||
resp = requests.get("https://shenfenzheng.bmcx.com/" + identification + "__shenfenzheng/")
|
||||
html = etree.HTML(resp.text)
|
||||
infos = html.xpath('//table[@width="100%"]//tr[position()!=2]/td[@bgcolor="#FFFFFF"]//text()')
|
||||
result = {
|
||||
'identification': infos[0],
|
||||
'originArea': infos[1],
|
||||
'sex': infos[3][0],
|
||||
'name': faker.last_name() + (faker.first_name_male() if infos[3][0] == '男' else faker.first_name_female()),
|
||||
'age': infos[4][0:-2]
|
||||
}
|
||||
return result
|
||||
|
||||
|
||||
def time(times):
|
||||
return times
|
||||
|
||||
|
||||
def faker_identifications(num: int):
|
||||
all_tasks = [executor.submit(faker_identification) for i in range(num)]
|
||||
results = []
|
||||
for future in as_completed(all_tasks):
|
||||
results.append(future.result())
|
||||
return results
|
||||
Reference in New Issue
Block a user