def test_format(self): """Test when.format()""" now = when.now() today = when.today() current_time = now.time() for format_string in ( "%a", "%A", "%b", "%B", "%c", "%d", "%f", "%H", "%I", "%j", "%m", "%M", "%p", "%S", "%U", "%w", "%W", "%x", "%X", "%y", "%Y", "%z", "%Z", "%A, %B %d, %Y %I:%M %p", ): # Test date objects builtin_date = now.strftime(format_string) result_date = when.format(now, format_string) self.assertEqual(builtin_date, result_date) # Test datetime objects builtin_datetime = today.strftime(format_string) result_datetime = when.format(today, format_string) self.assertEqual(builtin_datetime, result_datetime) # Test time objects builtin_time = current_time.strftime(format_string) result_time = when.format(current_time, format_string) self.assertEqual(builtin_time, result_time)
def test_format(self): """Test when.format()""" now = when.now() today = when.today() current_time = now.time() for format_string in ('%a', '%A', '%b', '%B', '%c', '%d', '%f', '%H', '%I', '%j', '%m', '%M', '%p', '%S', '%U', '%w', '%W', '%x', '%X', '%y', '%Y', '%z', '%Z', '%A, %B %d, %Y %I:%M %p'): # Test date objects builtin_date = now.strftime(format_string) result_date = when.format(now, format_string) self.assertEqual(builtin_date, result_date) # Test datetime objects builtin_datetime = today.strftime(format_string) result_datetime = when.format(today, format_string) self.assertEqual(builtin_datetime, result_datetime) # Test time objects builtin_time = current_time.strftime(format_string) result_time = when.format(current_time, format_string) self.assertEqual(builtin_time, result_time)
def forecast(lat=None, lng=None): """ Returns the weather for a specific location""" if not lat or not lng: abort(400) root = app.config.get('FORECASTIO_ROOT') key = app.config.get('FORECASTIO_API_KEY') timestamp = when.format(when.now(), '%Y-%m-%dT%H:%M:%S') url = root + key + "/" + lat + ", " + lng + ", " + timestamp r = requests.get(url) return jsonify(r.json() if r.ok else {})
def gen_no(prefix=''): no = prefix + when.format(when.now(), '%Y%m%d%H%M%S') + str( random.randint(10000, 99999)) return no