Skip to content

Commit

Permalink
A minor code refactor, regex to look for the date incase of invalid t…
Browse files Browse the repository at this point in the history
…imezone

Should fix #5
  • Loading branch information
lnxg33k committed Apr 2, 2018
1 parent a048304 commit 2888aff
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ target/

#Ipython Notebook
.ipynb_checkpoints

virt/
20 changes: 16 additions & 4 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ def duration(seconds, _maxweeks=99999999999):
return dict(duration=duration)


def dateParser(line):
try:
r = dateutil.parser.parse(line, fuzzy=True).timetuple()

# if the fuzzy parser failed to parse the line due to
# incorrect timezone information issue #5 GitHub
except ValueError:
r = re.findall('^(.*?)\s*\(', line)
if r:
r = dateutil.parser.parse(r[0]).timetuple()
return time.mktime(r)


@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
Expand Down Expand Up @@ -87,13 +100,12 @@ def index():
next_line = map(lambda x: x.replace('\r\n', ''), next_line)
except IndexError:
next_line = None
org_time = time.mktime(
dateutil.parser.parse(line[1], fuzzy=True).timetuple())

org_time = dateParser(line[1])
if not next_line:
next_time = org_time
else:
next_time = time.mktime(dateutil.parser.parse(
next_line[1], fuzzy=True).timetuple())
next_time = dateParser(next_line[1])

if line[0].startswith('from'):
data = re.findall(
Expand Down
Binary file modified static/data/GeoLite2-Country.mmdb
Binary file not shown.

0 comments on commit 2888aff

Please sign in to comment.