Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
humanities
gargantext
Commits
6d6d0baf
Commit
6d6d0baf
authored
Oct 23, 2017
by
sim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Little refactor of date parsing
parent
282cc8f2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
9 deletions
+5
-9
dates.py
gargantext/util/dates.py
+3
-1
_Parser.py
gargantext/util/parsers/_Parser.py
+2
-8
No files found.
gargantext/util/dates.py
View file @
6d6d0baf
...
@@ -2,6 +2,7 @@ import os
...
@@ -2,6 +2,7 @@ import os
from
gargantext.settings
import
MEDIA_ROOT
from
gargantext.settings
import
MEDIA_ROOT
from
datetime
import
MINYEAR
from
datetime
import
MINYEAR
from
dateutil.parser
import
parse
as
parse_datetime_flexible
from
django.utils.dateparse
import
parse_datetime
from
django.utils.dateparse
import
parse_datetime
from
django.utils.timezone
import
datetime
as
_datetime
,
utc
as
UTC
,
now
as
utcnow
from
django.utils.timezone
import
datetime
as
_datetime
,
utc
as
UTC
,
now
as
utcnow
...
@@ -19,7 +20,8 @@ class datetime(_datetime):
...
@@ -19,7 +20,8 @@ class datetime(_datetime):
@
staticmethod
@
staticmethod
def
parse
(
s
):
def
parse
(
s
):
dt
=
parse_datetime
(
s
)
dt
=
parse_datetime
(
s
)
or
\
parse_datetime_flexible
(
s
,
default
=
datetime
(
MINYEAR
,
1
,
1
))
return
dt
.
astimezone
(
UTC
)
if
dt
.
tzinfo
else
dt
.
replace
(
tzinfo
=
UTC
)
return
dt
.
astimezone
(
UTC
)
if
dt
.
tzinfo
else
dt
.
replace
(
tzinfo
=
UTC
)
...
...
gargantext/util/parsers/_Parser.py
View file @
6d6d0baf
...
@@ -3,10 +3,7 @@ import zipfile
...
@@ -3,10 +3,7 @@ import zipfile
import
re
import
re
import
dateparser
as
date_parser
import
dateparser
as
date_parser
from
gargantext.util.languages
import
languages
from
gargantext.util.languages
import
languages
from
gargantext.util
import
datetime
,
convert_to_datetime
,
MINYEAR
from
gargantext.util
import
datetime
,
convert_to_datetime
DEFAULT_DATE
=
datetime
(
MINYEAR
,
1
,
1
)
class
Parser
:
class
Parser
:
...
@@ -47,10 +44,7 @@ class Parser:
...
@@ -47,10 +44,7 @@ class Parser:
if
date_string
is
not
None
:
if
date_string
is
not
None
:
date_string
=
re
.
sub
(
r'\/\/+(\w*|\d*)'
,
''
,
date_string
)
date_string
=
re
.
sub
(
r'\/\/+(\w*|\d*)'
,
''
,
date_string
)
try
:
try
:
hyperdata
[
'publication_date'
]
=
dateutil
.
parser
.
parse
(
hyperdata
[
'publication_date'
]
=
datetime
.
parse
(
date_string
)
date_string
,
default
=
DEFAULT_DATE
)
except
Exception
as
error
:
except
Exception
as
error
:
print
(
error
,
'Date not parsed for:'
,
date_string
)
print
(
error
,
'Date not parsed for:'
,
date_string
)
hyperdata
[
'publication_date'
]
=
datetime
.
now
()
hyperdata
[
'publication_date'
]
=
datetime
.
now
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment