Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
crawlersNoticias
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
4
Issues
4
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
m3
crawlersNoticias
Commits
bf32b4c9
Commit
bf32b4c9
authored
Dec 18, 2017
by
Renán Sosa Guillen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
crawl rss
parent
20632ff9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
42 deletions
+36
-42
crawl_rss.py
crawler_script/crawl_rss.py
+36
-42
No files found.
crawler_script/crawl_rss.py
View file @
bf32b4c9
...
...
@@ -10,7 +10,6 @@ today = datetime.datetime.now()
baseDir
=
"/home/geoint/virtualHDD/m3/noticias/"
scrapyDir
=
"/home/geoint/crawlersNoticias/"
row
=
{}
urlSet
=
set
()
with
open
(
sys
.
argv
[
1
])
as
data_file
:
siteList
=
json
.
load
(
data_file
)
os
.
chdir
(
baseDir
)
...
...
@@ -77,15 +76,14 @@ with open(sys.argv[1]) as data_file:
f1
=
mydir
+
'/'
+
filename
f2
=
filename
f3
=
baseDir
+
media
+
'/'
+
filename
with
open
(
f1
)
as
infile1
,
open
(
f2
)
as
infile2
,
open
(
f3
,
'a'
)
as
infile3
:
counter
=
0
slave
=
json
.
load
(
infile2
)
infile3
.
write
(
'['
)
try
:
try
:
with
open
(
f1
)
as
infile1
,
open
(
f2
)
as
infile2
,
open
(
f3
,
'a'
)
as
infile3
:
master
=
json
.
load
(
infile1
)
slave
=
json
.
load
(
infile2
)
urlSet
=
set
([
line
[
'url'
]
for
line
in
master
])
counter
=
0
infile3
.
write
(
'['
)
for
line
in
master
:
counter
+=
1
...
...
@@ -114,46 +112,42 @@ with open(sys.argv[1]) as data_file:
infile3
.
write
(
json
.
dumps
(
row
))
elif
counter
>
1
:
infile3
.
write
(
',
\n
'
+
json
.
dumps
(
row
))
except
IOError
:
pass
for
line
in
slave
:
if
not
line
[
'url'
]
in
urlSet
:
lineDate
=
datetime
.
datetime
.
strptime
(
line
[
'date'
][:
10
],
'
%
Y-
%
m-
%
d'
)
if
lineDate
==
currentDate
:
counter
+=
1
if
media
==
'elFinanciero'
:
row
=
OrderedDict
([
(
'date'
,
line
[
'date'
]),
(
'topic'
,
line
[
'topic'
]),
(
'title'
,
line
[
'title'
]),
(
'author'
,
line
[
'author'
]),
(
'url'
,
line
[
'url'
]),
(
'text'
,
line
[
'text'
])
])
elif
media
==
'elUniversal'
:
row
=
OrderedDict
([
(
'date'
,
line
[
'date'
]),
(
'topic'
,
line
[
'topic'
]),
(
'title'
,
line
[
'title'
]),
(
'author'
,
line
[
'author'
]),
(
'location'
,
line
[
'location'
]),
(
'url'
,
line
[
'url'
]),
(
'text'
,
line
[
'text'
])
])
for
line
in
slave
:
if
not
line
[
'url'
]
in
urlSet
:
lineDate
=
datetime
.
datetime
.
strptime
(
line
[
'date'
][:
10
],
'
%
Y-
%
m-
%
d'
)
if
lineDate
==
currentDate
:
if
media
==
'elFinanciero'
:
row
=
OrderedDict
([
(
'date'
,
line
[
'date'
]),
(
'topic'
,
line
[
'topic'
]),
(
'title'
,
line
[
'title'
]),
(
'author'
,
line
[
'author'
]),
(
'url'
,
line
[
'url'
]),
(
'text'
,
line
[
'text'
])
])
elif
media
==
'elUniversal'
:
row
=
OrderedDict
([
(
'date'
,
line
[
'date'
]),
(
'topic'
,
line
[
'topic'
]),
(
'title'
,
line
[
'title'
]),
(
'author'
,
line
[
'author'
]),
(
'location'
,
line
[
'location'
]),
(
'url'
,
line
[
'url'
]),
(
'text'
,
line
[
'text'
])
])
if
counter
==
1
:
infile3
.
write
(
json
.
dumps
(
row
))
elif
counter
>
1
:
infile3
.
write
(
',
\n
'
+
json
.
dumps
(
row
))
elif
(
currentDate
-
lineDate
)
.
days
==
1
:
YESTERDAY
=
True
elif
(
currentDate
-
lineDate
)
.
days
==
1
:
YESTERDAY
=
True
infile3
.
write
(
']'
)
infile3
.
write
(
']'
)
os
.
system
(
"mv "
+
f3
+
" "
+
mydir
)
# os.system("rm " + f2)
os
.
system
(
"mv "
+
f3
+
" "
+
mydir
)
# os.system("rm " + f2)
except
:
os
.
system
(
"cp "
+
f2
+
" "
+
mydir
)
if
YESTERDAY
:
currentDate
-=
datetime
.
timedelta
(
days
=
1
)
...
...
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