0

I am am trying to schedule the my task torun at a specific time. I have a function score_user that gives grades to customers as of the query running.

def score_user(msisdn):
  headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json',
  'Authorization': 'Bearer 54763|E2jmjRM7xGmfhuWdUk2pO4SyHeDauvVer9sdCzGe'
  }
  payload = json.dumps({
  "id_number": "000",
  "msisdn": f"{msisdn}",
  "amount": "1500"
  })
  url = "https://preprod.senti.co.ke/api/v5/scoring/query"
  r = requests.post(url, headers=headers,data=payload)
  print(r.text)
  return r.text

the above is the function score_user.

cur =dbconn.cursor(dictionary=True)

cur.execute(''' select c.msisdn from  azima._tmp_latest_loan a
left join _tmp_latest_grade b
on a.profile_id = b.profile_id
left join v_profiles c
on a.profile_id = c.profile_id
order by a.pay_date desc
limit 1''')

res = cur.fetchall()

for row in res:
    # print(row)
  msisdn = f"{row['msisdn']}"
  print(f"Scoring: {msisdn}")
  print(score_user(msisdn))

schedule.every().day.at("16:56").do(score_user(msisdn))
 
while True:
    schedule.run_pending()
    time.sleep(1)

please assist

cackle2
  • 1
  • 1

0 Answers0