예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
파일: test_when.py 프로젝트: MVReddy/WhenPy
    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)
예제 #4
0
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 {})
예제 #5
0
def gen_no(prefix=''):
    no = prefix + when.format(when.now(), '%Y%m%d%H%M%S') + str(
        random.randint(10000, 99999))
    return no