import datetime import time import traceback import json import requests def send_whatsapp(phone_number): try: url = 'https://backend.aisensy.com/campaign/t1/api' payload = { "apiKey": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjYzODk3MDRlMDYyYTQ3NzIwZWMzYjc2NCIsIm5hbWUiOiJGYXJtb25hdXQgVGVjaG5vbG9naWVzIFB2dC4gTHRkLiIsImFwcE5hbWUiOiJBaVNlbnN5IiwiY2xpZW50SWQiOiI2Mzg5NzA0ZTA2MmE0NzcyMGVjM2I3NWYiLCJhY3RpdmVQbGFuIjoiQkFTSUNfVFJJQUwiLCJpYXQiOjE2Njk5NTE1NjZ9.sm6bFj27KhdOPL7t_aAbLIJW7Il4pMSnLIQ7unVzenM", "campaignName": "Pilot Broadcast 3", "destination": phone_number, "userName": "Farmer", "media": {"url": "https://farmonaut.com/Images/wa_broadcast3.jpg", "filename": "Advisory.jpg"}, } headers = { "Content-Type": "application/json" } response = requests.post(url, data=json.dumps(payload), headers=headers) # if response.status_code == 200: # print(response.json()) # else: # print("Error:", response.status_code, response.text) except: print(traceback.format_exc()) #temp = temp.replace(" ","_") return "done" file_names = ['Downloads/usersf.json','Downloads/usersk.json'] count = 0 iter_max = 150 for file_name in file_names: with open(file_name, 'r') as json_file: data = json.load(json_file) users_arr = data["users"] for single_user in users_arr: phoneNumber = single_user.get("phoneNumber",None) if phoneNumber is not None: if phoneNumber.find("+91")!=-1: count = count + 1 if count > 1150 and count <=1250: #count = count send_whatsapp(phoneNumber) time.sleep(2) #send_whatsapp("+9") print(count)