Commit cd265071 authored by Remi Rampin's avatar Remi Rampin

Add a validation script

parent fa860b1e
# This file is a template, and might need editing before it works on your project.
# Full project: https://gitlab.com/pages/plain-html
image: "python:2"
stages:
- test
- deploy
check:
stage: test
script:
- python checkcsv.py data/women-leaders-openness.csv
pages:
stage: deploy
script:
- mkdir .public
- cp -r * .public
- cp -r * .public/
- mv .public public
artifacts:
paths:
- public
only:
- master
\ No newline at end of file
- master
#!/usr/bin/env python
import csv
import re
import sys
def error(msg, line):
sys.stderr.write(msg)
sys.stderr.write(" line %d\n" % (line + 1))
sys.exit(1)
_twitter = re.compile(r'^(@[a-zA-Z0-9_]{1,15})?$')
_coord = re.compile(r'^-?[0-9]{1,3}\.[0-9]{1,10}$')
if __name__ == '__main__':
with open(sys.argv[1]) as fp:
cols = None
for line, row in enumerate(csv.reader(fp)):
if line == 0:
cols = len(row)
continue
if len(row) != cols:
error("Invalid number of columns", line)
if not _twitter.match(row[1]):
error("Invalid Twitter handle %r" % row[1], line)
if not _coord.match(row[3]):
error("Invalid latitude %r" % row[3], line)
if not _coord.match(row[4]):
error("Invalid longitude %r" % row[4], line)
print("Validated %d entries" % line)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment