Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export const getCurrentLogs = functions.https.onRequest((req, response) => {
- const ref = scheduleRef.get()
- .then((snapshot) => {
- snapshot.docs.forEach((doc) => {
- const scheduleGame = doc.data()
- const boxScoreUrl = scheduleGame.boxScoreURL
- updatePlayerLogs("https://" + boxScoreUrl + "/");
- });
- })
- .catch(err => {
- console.log('Error getting schedule', err);
- });
- function updatePlayerLogs (url){
- console.log(url)
- const options = {
- uri: url,
- Connection: 'keep-alive',
- transform: function (body) {
- return cheerio.load(body);
- }
- };
- request(options)
- .then(($) => {
- $('.stats-rows').find('tbody').children('tr').each(function(i, element){
- const playerPage = $(element).children('td').eq(0).find('a').attr('href');
- const pts = replaceDash($(element).children('td').eq(1).text());
- const reb = replaceDash($(element).children('td').eq(2).text());
- const ast = replaceDash($(element).children('td').eq(3).text());
- const fg = replaceDash($(element).children('td').eq(4).text());
- const _3pt = replaceDash($(element).children('td').eq(5).text());
- const stl = replaceDash($(element).children('td').eq(9).text());
- const blk = replaceDash($(element).children('td').eq(10).text());
- const to = replaceDash($(element).children('td').eq(11).text());
- const currentLog = {
- 'pts': + pts,
- 'reb': + reb,
- 'ast': + ast,
- 'fg': fgPer,
- '3pt': + _3ptMade,
- 'stl': + stl,
- 'blk': + blk,
- 'to': + to
- }
- playersRef.doc(playerDocRef).update({'currentLog': currentLog})
- .catch(error =>
- console.error("Error adding document: ", error + " : " + url)
- );
- });
- })
- .catch((err) => {
- console.log(err);
- });
- };
- response.send("finished writing logs")
- });
Add Comment
Please, Sign In to add comment