[Tutor] checking connection to internet until success

Pi guest0x013 at gmail.com
Mon Jan 1 16:38:39 EST 2018


Hi Tutor,

with this code i am getting actual date from internet. I need correct 
date, because i am not sure this set on computer is right.


import requests, time

try:
     OnLineDate = requests.get("http://just-the-time.appspot.com").text[:10]
     OffLineDate = time.strftime("%Y-%m-%d")

     if OnLineDate == OffLineDate:

         do_something

     else:

         do_something_else


except requests.ConnectionError:
     print("Can not connect.")


But this code is run once. And i am stuck. Tries with while loop doesnt 
took any advance. I was thinking about something like after method used 
in tkinter, but still i cant figure out how do this. Can You guide me, 
how check connection to internet to check for every lets say 30 seconds 
until success?


Best regards



More information about the Tutor mailing list