{"action":"opened","issue":{"url":"https://api.github.com/repos/chrismetcalf/open-stream/issues/1","repository_url":"https://api.github.com/repos/chrismetcalf/open-stream","labels_url":"https://api.github.com/repos/chrismetcalf/open-stream/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/chrismetcalf/open-stream/issues/1/comments","events_url":"https://api.github.com/repos/chrismetcalf/open-stream/issues/1/events","html_url":"https://github.com/chrismetcalf/open-stream/issues/1","id":134203796,"number":1,"title":"Add example of converting PDR numbers to format that is sortable","user":{"login":"timothyclemansinsea","id":12617436,"avatar_url":"https://avatars.githubusercontent.com/u/12617436?v=3","gravatar_id":"","url":"https://api.github.com/users/timothyclemansinsea","html_url":"https://github.com/timothyclemansinsea","followers_url":"https://api.github.com/users/timothyclemansinsea/followers","following_url":"https://api.github.com/users/timothyclemansinsea/following{/other_user}","gists_url":"https://api.github.com/users/timothyclemansinsea/gists{/gist_id}","starred_url":"https://api.github.com/users/timothyclemansinsea/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timothyclemansinsea/subscriptions","organizations_url":"https://api.github.com/users/timothyclemansinsea/orgs","repos_url":"https://api.github.com/users/timothyclemansinsea/repos","events_url":"https://api.github.com/users/timothyclemansinsea/events{/privacy}","received_events_url":"https://api.github.com/users/timothyclemansinsea/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-02-17T07:28:26Z","updated_at":"2016-02-17T07:28:26Z","closed_at":null,"body":"I wrote a basic example where if input doesn't validate then human has to convert it otherwise it is normalized automatically. For this use case one could use the received date field to handle invalid years. \r\n\r\n```\r\nimport re\r\n\r\ndef normalize_input(s, in_regex, out_format):\r\n    m = re.search(in_regex, s)\r\n    if m:\r\n        groups = m.groups()\r\n        return out_format.format(*m.groups())\r\n    else:\r\n        return raw_input('manual fix for %s:' % (s))\r\nnormalize_input('P2014-1', 'P(?P<year>\\d+)\\-(?P<num>\\d+)', 'P{}-{:0>5}')\r\nimport requests\r\nnormalized_pdr_numbers = [normalize_input(row['pdr_number'], '[pP](?P<year>\\d{4})\\-(?P<num>\\d+)', 'P{}-{:0>5}') for row in requests.get('https://data.seattle.gov/resource/a4j2-uu8v.json?$select=pdr_number&$limit=30000').json()]\r\nprint normalized_pdr_numbers\r\n```"}}