Bot-CQBOT/python-apiproject/NOTAPI/get_user_tel_by_qq/mycode_many.py

87 lines
2.1 KiB
Python
Raw Permalink Normal View History

2024-07-06 01:47:19 +00:00
# 多线程
import json
import time
from multiprocessing.dummy import Pool
import pandas as pd
import package_info as obj
import pymongo
myclient = pymongo.MongoClient('localhost', 27017) # 连接MongoDB
db = myclient['temp_user_info']
DataYuan = db['qqandtel']
DataResult = db["result"]
def loadData():
# 将这一千条数据添加到Mongodb
result = pd.read_excel("D:\softwareData\OneDriver\OneDrive\桌面\API\第二批.xlsx",sheet_name="Sheet1",header=0)["QQ号"]
print(result)
for i in result:
DataYuan.insert_one({"QQ号":i})
# 从MongoDB读取数据
def getinfo(qq):
result = obj.API_FromQQtoALl(qq)
code = result["code"]
data = result["data"]
if code == -1:
# DataYuan.insert({"QQ号":qq}) # 没有删除,因此也无需添加
pass
else:
DataResult.insert_one(
{"QQ": data['qq'], "手机号码": data['tel'], '手机归属地': data['address'], '微博ID': data['id']})
DataYuan.delete_one({"QQ号": qq})
time.sleep(1)
def run(data):
pool = Pool(5) # 多线程
pool.map(getinfo, data)
print("================Eed One Batch==============")
while DataYuan.find().count()>0:
data = []
for i in DataYuan.find():
data.append(i["QQ号"])
run(data)
# result = pd.read_excel("第一批.xlsx",0)
# datas = result["QQ号"].tolist()
# # print(datas)
# # for i in range(0,len(result['QQ号'])):
# result_all=[]
# i = 0
# for qq in datas:
# result = obj.API_FromQQtoALl(qq)
# code = result["code"]
# data = result["data"]
# if code==-1:
# datas.append(qq)
# print("[" + str(i) + "]", qq, "获取失败")
# else:
# result_all.append({"QQ":data['qq'],"手机号码":data['tel'],'手机归属地':data['address'],'微博ID':data['id']})
# print("[" + str(i) + "]", qq, "获取完成")
# i=i+1
#
# # print(result_all)
# td = pd.DataFrame(columns=["QQ","手机号码",'手机归属地','微博ID'],data=result_all)
# # td = pd.read_json(result_all)
# # print(td)
# td.to_excel('result.xlsx',encoding='utf-8')
# print("完毕!")
# # #
#