0

I have two files with different information that I want to execute simultaneously each line of both files in a loop until it finishes, but the "name" is stuck in the first lines and the "id" executes normally.

def get_data(account_id,key):
    name_entity = open('C:/Graphiql/Alerts/Update Alerts Policy/map/name','r')
    id_alerts = open('C:/Graphiql/Alerts/Update Alerts Policy/map/id_alerts','r')

    for entity in name_entity:
        name = entity.strip('\n')
        for alerts in id_alerts:
            id = alerts.strip('\n')
            endpoint = "https://api.newrelic.com/graphql"
            head = {"Content-type": "application/json", 'api-Key': f'{key}'}
            payload = 'mutation {alertsNrqlConditionStaticUpdate(accountId: ' + str(account_id) + ', condition: {nrql: {query: "SELECT average(memoryFreeBytes) FROM SystemSample where hostname = \u0027' + str(name) + '\u0027"}}, id: ' + str(id) + ') {id}}'

I've already changed the order and changed the functions but that doesn't work.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • 2
    If they are parallel, you can say `for entity, alerts in zip(name_entity, id_alerts):`. – Tim Roberts Dec 12 '22 at 23:04
  • @TimRoberts Incredible, I tested it and it worked, thanks a lot for the help... I had tried ''for entity, alerts'' but I hadn't used the zip, I didn't know it, I'll look it up. thank you again – Dennis Ricci Dec 12 '22 at 23:09

0 Answers0