We need a way to store the results of a scraping and a crawling process, and then retrieving them. We need this so we can see the current state of the available data in local database
Proposed Solution
Add support for local storage using our SqliteManager implementarion of BasePersistencyManager so the result of a scraping and a crawling process is directly stored to local storage.
Add a list command to the CLI client, so you can ask for data stored locally
Changes
Updated crawl & scrape commands to work with SQLite storage
Added folder for application files, for now in $HOME/.c4v. SQLite file is stored there
Added tabular library to print data in a human readable manner in the terminal
Updated scrape command so it can scrape urls directly from DB
Removed flags that makes no sense with local storage
Added useful flags to list command so you have a bit more control over the retrieved data
Relevant files
c4v/c4v_cli.py - Main changes, the new command and the modified ones
How to test it
run poetry install in root folder
run c4v crawl primicia --loud, this command will start a crawling process over primicia urls, and then print new urls to terminal. Expected output:
run c4v scrape --up-to 10 --loud to scrape 10 measurements and print them as they come. Expected result
row author categories content date last_scraped title url
----- ---------------------- ----------------------------------------------------- ----------------------------------------------------- ---------------------- -------------------------------- ----------------------------------------------------- -----------------------------------------------------
1 Carlos Eduardo Vargas ['DIsturbios', 'Heridos', 'Muertos', 'Protestas', ... Las manifestaciones desarrolladas en distintos sec... viernes, 25 enero 2019 2021-07-22 22:05:39.455796+00:00 Un muerto y cuatro heridos durante protestas https://primicia.com.ve/sucesos/un-muerto-y-cuatro...
2 Karla Benitez ['Deportes', 'Tenis', 'Torneo', 'venalum'] Este viernes comienza el I Estadal de tenis 12 y 1... viernes, 25 enero 2019 2021-07-22 22:05:39.890012+00:00 Abre Estadal en el Polideportivo https://primicia.com.ve/deportes/abre-estadal-en-e...
3 Redacción PRIMICIA/CNN ['Crisis', 'Enfermedades', 'Estudio', 'Mortalidad'... Más bebés mueren antes de su primer cumpleaños en ... viernes, 25 enero 2019 2021-07-22 22:05:40.076178+00:00 The Lancet Global Health: Aumentan muertes infanti... https://primicia.com.ve/mas/salud/the-lancet-globa...
4 Redacción PRIMICIA/AVN ['Brasil', 'Nación', 'Plan', 'Regreso', 'Venezolan... Este viernes retornaron al país 79 venezolanos, lu... viernes, 25 enero 2019 2021-07-22 22:05:40.195818+00:00 Regresan 79 venezolanos desde Brasil con el Plan V... https://primicia.com.ve/nacion/regresan-79-venezol...
5 Karla Benitez ['Ciclismo', 'Deportes', 'Torneo', 'Válida'] La temporada del ciclismo todo terreno comenzará e... viernes, 25 enero 2019 2021-07-22 22:05:40.738184+00:00 I Válida de ciclismo arranca el 17/2 https://primicia.com.ve/deportes/i-valida-de-cicli...
6 Carlos Berroterán ['Actriz', 'Lazo', 'Mimi', 'Placeres'] La actriz venezolana, Mimí Lazo, no se quedó atrás... viernes, 25 enero 2019 2021-07-22 22:05:41.227119+00:00 Critican a Mimí Lazo por «chavista» https://primicia.com.ve/placeres/critican-a-mimi-l...
7 Rossany Mattey ['Coalición', 'Partido', 'Política', 'UPP89'] El equipo político regional de UPP89 en el estado ... viernes, 25 enero 2019 2021-07-22 22:05:41.805716+00:00 UPP89 insta a la coalición https://primicia.com.ve/politica/upp89-insta-a-la-...
8 Rossany Mattey ['Corpal', 'Empresa', 'Trabajadores', 'Trabajo'] Trabajadores de Corpal denuncian que los directivo... viernes, 25 enero 2019 2021-07-22 22:05:42.569825+00:00 Denuncian a gerente de Corpal https://primicia.com.ve/trabajo/denuncian-a-gerent...
9 Carlos Berroterán ['Ciudad', 'Comercios', 'Guayana', 'Saqueos', 'Ten... Por segundo día consecutivo se reportaron saqueos ... viernes, 25 enero 2019 2021-07-22 22:05:42.835665+00:00 Guayana vivió segundo día de saqueos y angustia https://primicia.com.ve/guayana/ciudad/guayana-viv...
10 Redacción PRIMICIA ['Caracas', 'Desalojo', 'Diplomáticos', 'EEUU', 'E... El personal no esencial de la embajada de los Esta... viernes, 25 enero 2019 2021-07-22 22:05:43.138017+00:00 Personal no esencial de la embajada de EEUU abando... https://primicia.com.ve/nacion/personal-no-esencia...
run c4v list --scraped-only true --limit 10 to get 10 scraped rows, including possibly recently added ones:
row author categories content date last_scraped title url
----- -------------------------------------------- ----------------------------------------------------- ----------------------------------------------------- ---------------------------- -------------------------------- ----------------------------------------------------- -----------------------------------------------------
1 Yojana Mata Rodríguez ['Bolívar', 'Candidata', 'Reina del Cacao Venezola... Giorlys Marín es una hermosa trigueña de ojos clar... jueves, 03 septiembre 2020 2021-07-21 21:50:37.515152+00:00 ¡Bolívar ya tiene candidata para la “Reina del Cac... https://primicia.com.ve/placeres/bolivar-ya-tiene-...
2 Unión Radio ['Onda Tropical', 'lluvias dispersas', 'originará'... El Instituto Nacional de Meteorología e Hidrología... jueves, 03 septiembre 2020 2021-07-21 21:50:38.539895+00:00 Onda tropical N°40 originará lluvias dispersas en ... https://primicia.com.ve/nacion/onda-tropical-n40-o...
3 Verónica Millán ['AD', 'AN', 'Acción Democrática', 'Asamblea Nacio... Partidos de oposición en Bolívar reaccionaron ante... jueves, 03 septiembre 2020 2021-07-21 21:50:39.129356+00:00 Dirigentes políticos opositores en Bolívar llaman ... https://primicia.com.ve/politica/dirigentes-politi...
4 AP ['Alemania', 'Deportes', 'España', 'Liga de Nacion... Un gol postrero de José Luis Gayá rescató para Esp... jueves, 03 septiembre 2020 2021-07-21 21:50:39.610047+00:00 España empata sobre la hora con Alemania en la Lig... https://primicia.com.ve/deportes/espana-empata-sob...
5 Karla Benitez ['Alemania', 'Christian Santos', 'Deportes', 'Fich... El delantero guayanés Christian Santos firmó contr... viernes, 04 septiembre 2020 2021-07-21 21:50:39.929568+00:00 Christian Santos vuelve a Alemania con VfL Osnabrü... https://primicia.com.ve/deportes/christian-santos-...
6 Karla Benitez ['Atletismo', 'Deportes', 'España', 'Salto triple'... Yulimar Rojas competirá en un tope de control de s... viernes, 04 septiembre 2020 2021-07-21 21:50:40.249104+00:00 Yulimar Rojas irá a un tope de control en Castelló... https://primicia.com.ve/deportes/yulimar-rojas-ira...
7 Redacción PRIMICIA ['Escritorio Tinoco Travieso Planchart & Núñez', '... Los socios, asociados y personal del Escritorio Ti... viernes, 04 septiembre 2020 2021-07-21 21:50:40.548564+00:00 Escritorio Tinoco, Travieso, Planchart & Núñez lam... https://primicia.com.ve/guayana/ciudad/escritorio-...
8 Prensa Trasnocho Cultural ['Estreno', 'Innovación', 'Mundial', 'Volver a Cor... En un parque de Caracas, una joven profesora de li... viernes, 04 septiembre 2020 2021-07-21 21:50:41.031649+00:00 Estreno mundial e innovación teatral en “Volver a ... https://primicia.com.ve/placeres/estreno-mundial-e...
9 Ok Diario ['Beneficios', 'Diurético', 'El Yerberito', 'Fruta... La piña es una planta tropical originaria de Améri... viernes, 04 septiembre 2020 2021-07-21 21:50:45.509681+00:00 Conoce los 7 beneficios de la piña https://primicia.com.ve/especiales/yerberito/conoc...
10 AVN ['Arreaza', 'Desertores', 'Duque', 'Mercenarios', ... El ministro para Relaciones Exteriores, Jorge Arre... jueves, 03 septiembre 2020 2021-07-21 21:50:46.268812+00:00 Arreaza: Duque traiciona a mercenarios desertores ... https://primicia.com.ve/nacion/arreaza-duque-traic...
Further work
move default folder setting to a more sophisticated configuration scheme, currently it is hardcoded to be $HOME/.c4v
Problem
We need a way to store the results of a scraping and a crawling process, and then retrieving them. We need this so we can see the current state of the available data in local database
Proposed Solution
SqliteManager
implementarion ofBasePersistencyManager
so the result of a scraping and a crawling process is directly stored to local storage.list
command to the CLI client, so you can ask for data stored locallyChanges
tabular
library to print data in a human readable manner in the terminallist
command so you have a bit more control over the retrieved dataRelevant files
c4v/c4v_cli.py
- Main changes, the new command and the modified onesHow to test it
run
poetry install
in root folderrun
c4v crawl primicia --loud
, this command will start a crawling process over primicia urls, and then print new urls to terminal. Expected output:It won't stop until it has scraped as much as it can, you can stop it with
ctrl + c
run
c4v list
, this command will print available data in local storage:run
c4v scrape --up-to 10 --loud
to scrape 10 measurements and print them as they come. Expected resultrun
c4v list --scraped-only true --limit 10
to get 10 scraped rows, including possibly recently added ones:Further work
move default folder setting to a more sophisticated configuration scheme, currently it is hardcoded to be $HOME/.c4v
add more useful flags, any suggestions?