我打算做的是拥有多个JSON对象,例如:
{
"Profiles": {
"profile_0": {
"Url": "Myownwebsite.se",
"My-Note": "Helloworld",
"Email": "Stackoverflow@gmail.com"
"PersonNumber": "1234543",
"postal_code": "54123",
"given_name": "World",
"Last_name": "Hellow",
"street_address": "helloworld 123",
"city": "Stockholm",
"country": "Sweden",
"phone": "123456789",
"Color": "Red",
"house_number": "123",
"year": "2017"
},
"profile_1": {
"Url": "Myasdwfaesite.se",
"My-Note": "aasfase",
"Email": "fasfsef@gmail.com"
"PersonNumber": "5634543",
"postal_code": "123445",
"given_name": "Balling",
"Last_name": "Calling",
"street_address": "qwertr 123",
"city": "London",
"country": "UK",
"phone": "65412331",
"Color": "Blue",
"house_number": "321",
"year": "2018"
}
#Profile_2 etc etc
}
}
我的计划是让json个人资料/对象通过我的代码同时工作。
更直观的表现形式:
到目前为止我做了什么
我现在可以使用以下代码读取一个JSON对象:
with open('profileMulti.json', 'r', encoding='UTF-8') as json_data:
config = json.load(json_data)
这给了我这个输出:如果第一个Json配置文件并且它不能在Json中添加另一个配置文件,否则代码将不会重新获得它。
可以使用此
创建的代码示例 "Url": "Myownwebsite.se",
"My-Note": "Helloworld",
"Email": "Stackoverflow@gmail.com"
"PersonNumber": "1234543",
"postal_code": "54123",
"given_name": "World",
"Last_name": "Hellow",
"street_address": "helloworld 123",
"city": "Stockholm",
"country": "Sweden",
"phone": "123456789",
^这是我在下面的代码。
我期待发生的事情 ......
我期望发生或想让它发挥作用的是Json文件中的那些信息。获取这些信息 - >将它加载到代码中(下面) - 让每个json对象配置文件与每个THREAD同时工作,当每个人都完成后再退出。配置文件1和其他配置文件之间没有混合。每个配置文件都会自行运行并以相同的方式执行。
CODE
with open('profileMulti.json', 'r', encoding='UTF-8') as json_data:
config = json.load(json_data)
NameUrl = config["Url"]
myNote = config["My-Note"]
def checkoutNames(NameUrl, nameID):
#Request & other codes - Removed to recude the code
#......
#......
headers = {
'Referer': '',
'Content-Type': ''
}
payload = {
"shared": {
"challenge": {
"email": config["Email"],
"PersonNumber": config["PersonNumber"],
"postal_code": config["ZipCode"],
"given_name": config["Name"],
"Last_name": config["LastName"],
"street_address": config["Address"],
"postal_code": config["ZipCode"],
"city": config["City"],
"country": config["Country"],
"email": config["Email"],
"phone": config["Phone"],
}
def checkoutNotes(NamesUrl, NamesPost):
#Request & other codes - Removed to recude the code
#......
#......
headers = {
'Accept': 'application/json, text/javascript, /; q=0.01',
'Accept-Language': 'en-US,en;q=0.5',
'Accept-Encoding': 'gzip, deflate, br',
'Referer': NameUrl,
'Connection': 'keep-alive'
}
payloadInfo = {
"Information": {
"Color": config["Color"],
"house_number": config["houseNumber"],
"year": config["Year"]
}
}
def wipe():
os.system('cls' if os.name == 'nt' else 'clear')
def main():
time.sleep(1)
FindName(myNote)
if _name_ == '_main_':
try: {
main()
}
except KeyboardInterrupt:
wipe()
很容易说。代码中有一些功能,例如从一开始就有checkoutNames
和checkoutNotes
。基本上我们有不同的配置文件。使每个配置文件与每个线程同时工作。单独执行代码并将这些信息从Json添加到我在此处输入的代码和vioala。这就是我现在想要让它发挥作用的梦想。
所以我假设我们需要让它们通过多进程并发运行,以便每个配置文件都可以在自己的线程上运行,而不需要其他配置文件之间的iterat?