Example #1
0
def test_parse_iso8601():
    """Test parsing ISO-8601 date/time strings."""
    as_string = "2016-02-05T02:52:15.030474+01:00"
    as_datetime = datetime(2016, 2, 5, 2, 52, 15, 30474, tzinfo=tzoffset(None, 3600))
    assert parse_iso8601(as_string) == as_datetime

    as_string = "2016-02-05T02:52:15"
    as_datetime = datetime(2016, 2, 5, 2, 52, 15, tzinfo=timezone.utc)
    assert parse_iso8601(as_string) == as_datetime

    with pytest.raises(ValueError) as e:
        parse_iso8601("foobar")
    assert "Unknown string format" in str(e.value)
Example #2
0
def process_tweet(raw_tweet):
    tweet = {}

    parts = raw_tweet.partition('\t')
    tweet['timestamp'] = parse_iso8601(parts[0])
    tweet['text'] = parts[2].lstrip().rstrip()
    tweet['urls'] = get_links(parts[2].lstrip().rstrip())

    return tweet
Example #3
0
def validate_created_at(ctx, param, value):
    if value:
        try:
            return parse_iso8601(value)
        except (ValueError, OverflowError) as e:
            raise click.BadParameter("{0}.".format(e))
Example #4
0
def validate_created_at(ctx, param, value):
    if value:
        try:
            return parse_iso8601(value)
        except (ValueError, OverflowError) as e:
            raise click.BadParameter("{}.".format(e))