Skip to content
Snippets Groups Projects
Commit 288be81c authored by Yoan VALLET's avatar Yoan VALLET
Browse files

clean old data comming for scraping

parent ea688ba6
No related branches found
No related tags found
1 merge request!20Update master branch
...@@ -133,28 +133,37 @@ async function getData(token, idPCE) { ...@@ -133,28 +133,37 @@ async function getData(token, idPCE) {
* Return the list of daily data * Return the list of daily data
*/ */
async function cleanOldData() { async function cleanOldData() {
if(moment() > moment("26/11/2020", "DD/MM/YYYY")){ if(moment().isAfter("2020-11-26")){
log('debug', 'No cleaning to do') log('debug', 'No cleaning to do')
return false return false
} else { } else {
log('debug', 'Start cleaning old data') log('debug', 'Start cleaning old data')
const documents = await cozyClient.data.findAll('com.grandlyon.grdf.day') const documents = await cozyClient.data.findAll('com.grandlyon.grdf.day')
if (documents && documents.length > 0) { if (documents && documents.length > 0) {
const result = []
for (const doc of documents) { for (const doc of documents) {
await cozyClient.data.delete('com.grandlyon.grdf.day', doc) const deleteResult = await cozyClient.data.delete('com.grandlyon.grdf.day', doc)
result.push(deleteResult)
} }
log("debug", "NB OF DELETED OLD DAY DATA : " + result.length)
} }
const documents = await cozyClient.data.findAll('com.grandlyon.grdf.month') const documents = await cozyClient.data.findAll('com.grandlyon.grdf.month')
if (documents && documents.length > 0) { if (documents && documents.length > 0) {
const result = []
for (const doc of documents) { for (const doc of documents) {
await cozyClient.data.delete('com.grandlyon.grdf.month', doc) const deleteResult = await cozyClient.data.delete('com.grandlyon.grdf.month', doc)
result.push(deleteResult)
} }
log("debug", "NB OF DELETED OLD MONTH DATA : " + result.length)
} }
const documents = await cozyClient.data.findAll('com.grandlyon.grdf.year') const documents = await cozyClient.data.findAll('com.grandlyon.grdf.year')
if (documents && documents.length > 0) { if (documents && documents.length > 0) {
const result = []
for (const doc of documents) { for (const doc of documents) {
await cozyClient.data.delete('com.grandlyon.grdf.year', doc) await cozyClient.data.delete('com.grandlyon.grdf.year', doc)
result.push(deleteResult)
} }
log("debug", "NB OF DELETED OLD YEAR DATA : " + result.length)
} }
return true return true
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment