Bottom Page

Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Python - Make Json objects to work concurrently through Threads?
#1
What I was planning to do is to have a multiple JSON objects, for example:

    {
        "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
        }
    }
and my plan is to make the json profile/objects to work concurrently through my code.

1. Use the profiles, between 0 - x
2. concurrently it with my code
3. When finished - exit

A more visual representation:
İmage


*What I have done so far*

I can read one JSON object at this moment with this code:

    with open('profileMulti.json', 'r', encoding='UTF-8') as json_data:
        config = json.load(json_data
)

Which gives me this output: If the first Json profile and it cant be a added another profile inside the Json else the code will not recoinze it.

An example for code that can be made out of this
    			"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",
^ This is from my code on below.

*What I expect to happened*...

What I expect to happened or want to make it to work is that with those information inside the Json file. To take those information --> Load it into the code (Below) - Make each json object profile to work concurrently with each THREAD and when everybody is done then exit pretty much. No mix between profile 1 and other or so. Every profile run for itself and execute the same way.


**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()
So easy to say. There is functions in the code such as from the beginning, checkoutNames and checkoutNotes. Basically we have different profiles. Make each profile to work concurrently with each thread for itself. Execute the code by itself and add those information from Json to the code I have entered here and vioala. That's pretty much what I dream at this moment to get it to work.

So I assume we need to make them running concurrently by multiprocess for every profile to run on their own thread without iterat between other profiles?
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How do objects work? pyThon_ 12 499 Oct-25-2019, 03:59 PM
Last Post: jefsummers
  How do integer objects work? pyThon_ 2 284 Oct-22-2019, 01:36 AM
Last Post: wavic
  How to serialize custom class objects in JSON? Exsul1 4 381 Sep-23-2019, 08:27 AM
Last Post: wavic
  if, or, in, else in 1 line - how to make it work? zarize 2 183 Sep-10-2019, 04:51 PM
Last Post: zarize
  How to get a count of -Python- threads from the outside (or via code instrumentation) dstromberg 0 262 Jul-15-2019, 06:58 PM
Last Post: dstromberg
  Python threads and aircrack-ng adam2020 2 873 Apr-01-2019, 08:54 PM
Last Post: adam2020
  To make an algorithm work faster pianistseb 3 526 Apr-01-2019, 08:42 AM
Last Post: Gribouillis
  Watching for inputs from multiple sources concurrently anakaine 4 460 Mar-03-2019, 07:38 PM
Last Post: woooee
  Rewrite a function to make it work with 'bottle-pymysql' nikos 1 332 Feb-26-2019, 02:59 PM
Last Post: nikos
  Make a table from a json output carstenlp 13 2,046 Jan-12-2019, 09:06 PM
Last Post: carstenlp

Forum Jump:


Users browsing this thread: 1 Guest(s)