Skip to content

Commit

Permalink
add date validation
Browse files Browse the repository at this point in the history
  • Loading branch information
monperrus committed Apr 4, 2024
1 parent a5a39b6 commit 215c006
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crawler-user-agents.json
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
,
{
"pattern": "httpx",
"addition_date":" 2019/12/23",
"addition_date": "2019/12/23",
"instances": [
"python-httpx/0.16.1",
"python-httpx/0.13.0.dev1"
Expand Down Expand Up @@ -265,7 +265,7 @@
,
{
"pattern": "phpcrawl",
"addition_date": "2012-09/17",
"addition_date": "2012/09/17",
"url": "http://phpcrawl.cuab.de/",
"instances": [
"phpcrawl"
Expand Down
8 changes: 8 additions & 0 deletions validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json
import re
from collections import Counter
import datetime

from jsonschema import validate

Expand Down Expand Up @@ -59,6 +60,13 @@ def main():
for entry in json_data:
pattern = entry['pattern']

# assert that field "addition_date" has format "2019/12/23",
if 'addition_date' in entry:
if not re.match(r'\d{4}/\d{2}/\d{2}', entry['addition_date']):
raise ValueError('addition_date {!r} has invalid format'.format(entry['addition_date']))
# parse the date with datetime
datetime.datetime.strptime(entry['addition_date'], '%Y/%m/%d')

# canonicalize entry
if 'depends_on' not in entry: entry['depends_on'] = []

Expand Down

0 comments on commit 215c006

Please sign in to comment.