5 changed files with 80 additions and 82 deletions
@ -0,0 +1,21 @@
|
||||
import fetch from 'node-fetch'; |
||||
import { unix, get_credentials } from '../util.mjs'; |
||||
|
||||
export const update_last_scraped = async (place, prod = false) => { |
||||
const { api, token } = get_credentials(prod); |
||||
let res = await fetch(`${api}/places/${place.id}/?token=${token}`, { |
||||
method: 'PATCH', |
||||
body: JSON.stringify({ |
||||
last_scraped: unix(new Date()) |
||||
}), |
||||
headers: { 'Content-Type': 'application/json' } |
||||
}); |
||||
if (res.ok) { |
||||
console.log(res.status, `Last scrape at ${place.name} updated.`); |
||||
} else { |
||||
console.log( |
||||
res.status, |
||||
`Last scrape at ${place.name} failed to update last update..` |
||||
); |
||||
} |
||||
}; |
||||
@ -0,0 +1,36 @@
|
||||
export const get_credentials = (prod = false) => { |
||||
let api, token; |
||||
if (prod) { |
||||
api = 'http://10.0.0.210:8484'; |
||||
token = '831411806230c7e950c4eeb226499ef92bb6bdc4157797929a0e16d133dc13a8'; |
||||
} else { |
||||
api = 'http://localhost:3333'; |
||||
token = '1234567812345678123456781234567812345678123456781234567812345678'; |
||||
} |
||||
return { api, token }; |
||||
}; |
||||
export const sleep = (ms) => { |
||||
return new Promise((res) => setTimeout(res, ms)); |
||||
}; |
||||
export const unix = (a) => { |
||||
return parseInt(new Date(a).valueOf() / 1000, 10); |
||||
}; |
||||
export const updated = (oldEvent, scrapedEvent) => { |
||||
let keys = [ |
||||
'canceled', |
||||
'end', |
||||
'start', |
||||
'draft', |
||||
'facebook_id', |
||||
'place_id', |
||||
'name', |
||||
'ticket_url' |
||||
]; |
||||
for (let key of keys) { |
||||
if (oldEvent[key] != scrapedEvent[key]) { |
||||
console.log(124, key, oldEvent[key], '!=', scrapedEvent[key]); |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
}; |
||||
Loading…
Reference in new issue