def check_time(self, s): """ checks the current time in any part of the globe. -- Examples: check time in Manchester (UK) """ timeIn.main(self._jarvis, s)
def test_timeIn(self): """ test the timeIn.main function against time.ctime """ # call timeIn.main and redirect stdout to a StringIO object timeIn.main(self, "time in Greenwich, UK") sys.stdout.seek(0) output = sys.stdout.read() # What is ctime in your current locale? time_here = datetime.datetime.now() # Create a datetime object for the api call output_list = output.split(' ') result = datetime.datetime.strptime(' '.join([output_list[-2], output_list[-1][0:8]]), '%Y-%m-%d %H:%M:%S') # Create a timedelta object to adjust for your locale's timezone # print self.dst delta_tz = datetime.timedelta( hours=((time.timezone)/3600.0+int(self.dst))) result -= (delta_tz) # Create another timedelta object to give the API call a margin # of error since the HTTP request may have latency delta_delay = datetime.timedelta(seconds=5) self.assertAlmostEqual(result, time_here, delta=delta_delay)
def test_timeIn(self): """ test the timeIn.main function against time.ctime """ # call timeIn.main and redirect stdout to a StringIO object timeIn.main(self, "time in Greenwich, UK") sys.stdout.seek(0) output = sys.stdout.read() # What is ctime in you current local? time_here = time.ctime(time.time()).split(' ') # fix indices if the day of month is one or two digits long if '' in time_here: index = time_here.index('') time_here = time_here[0:index] + time_here[index + 1:] time_here = time_here[3] # Adjust 'result' variable for your current local's timezone result = output.split(' ')[10][0:8] adjustment = time.timezone / 3600 result_list = result.split(':') hour = (int(result_list[0]) - adjustment) % 24 result = ':'.join([str(hour), result_list[1], result_list[2]]) self.assertEqual(result, time_here)
def do_check(self, s): """Checks your system's RAM stats.""" # if s == "ram": if "ram" in s: system("free -lm") # if s == "time" if "time" in s: timeIn.main(self, s) # if s == "weather" if "weather" in s: weatherIn.main(self, s)
def do_check(self, s): """Checks your system's RAM stats.""" # if s == "ram": if "ram" in s: system("free -lm") # if s == "time" elif "time" in s: timeIn.main(self, s) elif "forecast" in s: forecast.main(self, s) # if s == "weather" elif "weather" in s: try: weatherIn.main(self, s) except ConnectionError: print(CONNECTION_ERROR_MSG)