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
a83006e4
Commit
a83006e4
authored
Nov 10, 2015
by
delanoe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FIX] dates for Europresse parser: ok.
parent
2fac6579
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
15 deletions
+20
-15
EuropressFileParser.py
parsing/FileParsers/EuropressFileParser.py
+18
-13
FileParser.py
parsing/FileParsers/FileParser.py
+2
-2
No files found.
parsing/FileParsers/EuropressFileParser.py
View file @
a83006e4
...
@@ -29,9 +29,9 @@ class EuropressFileParser(FileParser):
...
@@ -29,9 +29,9 @@ class EuropressFileParser(FileParser):
format_date
=
re
.
compile
(
'.*
\
d{4}.*'
,
re
.
UNICODE
)
format_date
=
re
.
compile
(
'.*
\
d{4}.*'
,
re
.
UNICODE
)
if
isinstance
(
file
,
str
):
if
isinstance
(
file
,
str
):
file
_open
=
open
(
file
,
'rb'
)
file
=
open
(
file
,
'rb'
)
contents
=
file
_open
.
read
()
contents
=
file
.
read
()
encoding
=
self
.
detect_encoding
(
contents
)
encoding
=
self
.
detect_encoding
(
contents
)
if
encoding
!=
"utf-8"
:
if
encoding
!=
"utf-8"
:
...
@@ -91,19 +91,27 @@ class EuropressFileParser(FileParser):
...
@@ -91,19 +91,27 @@ class EuropressFileParser(FileParser):
header
=
header
.
split
(
', '
)
header
=
header
.
split
(
', '
)
if
format_date
.
match
(
header
[
0
]):
if
format_date
.
match
(
header
[
0
]):
date
=
header
[
0
]
date
=
header
[
0
]
el
se
:
el
if
format_date
.
match
(
header
[
1
])
:
hyperdata
[
'rubrique'
]
=
header
[
0
]
hyperdata
[
'rubrique'
]
=
header
[
0
]
date
=
header
[
1
]
date
=
header
[
1
]
try
:
try
:
hyperdata
[
'page'
]
=
header
[
2
]
.
split
(
' '
)[
1
]
hyperdata
[
'page'
]
=
header
[
2
]
.
split
(
' '
)[
1
]
except
:
except
:
pass
pass
else
:
date
=
header
[
2
]
try
:
try
:
hyperdata
[
'publication_date'
]
=
dateparser
.
parse
(
date
,
languages
=
[
'fr'
,
'en'
])
hyperdata
[
'publication_date'
]
=
dateparser
.
parse
(
date
.
strip
(),
languages
=
[
'fr'
,
'en'
])
except
:
except
:
hyperdata
[
'publication_date'
]
=
timezone
.
now
()
hyperdata
[
'publication_date'
]
=
timezone
.
now
()
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
hyperdata
[
'publication_year'
]
=
hyperdata
[
'publication_date'
]
.
strftime
(
'
%
Y'
)
hyperdata
[
'publication_month'
]
=
hyperdata
[
'publication_date'
]
.
strftime
(
'
%
m'
)
hyperdata
[
'publication_day'
]
=
hyperdata
[
'publication_date'
]
.
strftime
(
'
%
d'
)
#print(hyperdata['publication_date'])
try
:
try
:
title
=
paragraph_list
(
html_article
.
xpath
(
title_xpath
))
title
=
paragraph_list
(
html_article
.
xpath
(
title_xpath
))
hyperdata
[
'title'
]
=
title
[
0
]
hyperdata
[
'title'
]
=
title
[
0
]
...
@@ -118,8 +126,6 @@ class EuropressFileParser(FileParser):
...
@@ -118,8 +126,6 @@ class EuropressFileParser(FileParser):
yield
hyperdata
yield
hyperdata
file_open
.
close
()
except
:
except
:
PrintException
()
PrintException
()
pass
pass
...
@@ -133,4 +139,3 @@ if __name__ == "__main__":
...
@@ -133,4 +139,3 @@ if __name__ == "__main__":
except
:
except
:
pass
pass
parsing/FileParsers/FileParser.py
View file @
a83006e4
...
@@ -126,7 +126,7 @@ class FileParser:
...
@@ -126,7 +126,7 @@ class FileParser:
# initialize the list of hyperdata
# initialize the list of hyperdata
hyperdata_list
=
[]
hyperdata_list
=
[]
if
zipfile
.
is_zipfile
(
file
):
if
zipfile
.
is_zipfile
(
file
):
print
(
file
,
"# is the file is a ZIP archive, recurse on each of its files..."
)
#
print(file, "# is the file is a ZIP archive, recurse on each of its files...")
zipArchive
=
zipfile
.
ZipFile
(
file
)
zipArchive
=
zipfile
.
ZipFile
(
file
)
for
filename
in
zipArchive
.
namelist
():
for
filename
in
zipArchive
.
namelist
():
try
:
try
:
...
@@ -137,7 +137,7 @@ class FileParser:
...
@@ -137,7 +137,7 @@ class FileParser:
print
(
error
)
print
(
error
)
# ...otherwise, let's parse it directly!
# ...otherwise, let's parse it directly!
else
:
else
:
print
(
file
,
"it is not a zip file"
)
#
print(file, "it is not a zip file")
try
:
try
:
for
hyperdata
in
self
.
_parse
(
file
):
for
hyperdata
in
self
.
_parse
(
file
):
hyperdata_list
.
append
(
self
.
format_hyperdata
(
hyperdata
))
hyperdata_list
.
append
(
self
.
format_hyperdata
(
hyperdata
))
...
...
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