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
  Passing List of Objects in Command Line Python usman 7 239 Sep-27-2020, 03:45 PM
Last Post: ndc85430
  How to create and define in one line a 2D list of class objects in Python T2ioTD 1 151 Aug-14-2020, 12:37 PM
Last Post: Yoriz
  Parse JSON multiple objects larkin_L 8 504 May-27-2020, 11:18 AM
Last Post: nuffink
  Cannot Make the python Code work ErnestTBass 4 502 Apr-23-2020, 02:42 PM
Last Post: snippsat
  difficulties to chage json data structure using json module in python Sibdar 1 410 Apr-03-2020, 06:47 PM
Last Post: micseydel
  How do objects work? pyThon_ 12 961 Oct-25-2019, 03:59 PM
Last Post: jefsummers
  How do integer objects work? pyThon_ 2 471 Oct-22-2019, 01:36 AM
Last Post: wavic
  How to serialize custom class objects in JSON? Exsul1 4 764 Sep-23-2019, 08:27 AM
Last Post: wavic
  if, or, in, else in 1 line - how to make it work? zarize 2 367 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 460 Jul-15-2019, 06:58 PM
Last Post: dstromberg

Forum Jump:


Users browsing this thread: 1 Guest(s)