dimanche 22 octobre 2017

Condition before runnning create_and_update_worksheets() function

import socket, schedule, time

from create_and_update_xlsx_sheets import create_and_update_worksheets

REMOTE_SERVER = "www.google.com"
def is_connected():
  try:
    host = socket.gethostbyname(REMOTE_SERVER)
    s = socket.create_connection((host, 80), 2)
    return True
  except:
     pass
  return False

schedule.every().minute.do(create_and_update_worksheets())

I have the function create_and_update_worksheets() function. I want to test out the internet connection once running it. I would like to say to schedule.every().minute.do(create_and_update_worksheets()), ok, test the connection at most 5 times with is_connected(). If within that time the connection is True, then run the schedule task or otherwise pass. How could I do that?

Aucun commentaire:

Enregistrer un commentaire