Guest User

Untitled

a guest
Jan 15th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. export const getCurrentLogs = functions.https.onRequest((req, response) => {
  2.  
  3. const ref = scheduleRef.get()
  4.  
  5. .then((snapshot) => {
  6.  
  7. snapshot.docs.forEach((doc) => {
  8.  
  9. const scheduleGame = doc.data()
  10. const boxScoreUrl = scheduleGame.boxScoreURL
  11.  
  12. updatePlayerLogs("https://" + boxScoreUrl + "/");
  13.  
  14.  
  15. });
  16.  
  17. })
  18.  
  19. .catch(err => {
  20. console.log('Error getting schedule', err);
  21. });
  22.  
  23.  
  24. function updatePlayerLogs (url){
  25.  
  26. console.log(url)
  27.  
  28. const options = {
  29. uri: url,
  30. Connection: 'keep-alive',
  31. transform: function (body) {
  32. return cheerio.load(body);
  33. }
  34. };
  35.  
  36. request(options)
  37.  
  38. .then(($) => {
  39.  
  40. $('.stats-rows').find('tbody').children('tr').each(function(i, element){
  41.  
  42.  
  43. const playerPage = $(element).children('td').eq(0).find('a').attr('href');
  44.  
  45.  
  46. const pts = replaceDash($(element).children('td').eq(1).text());
  47. const reb = replaceDash($(element).children('td').eq(2).text());
  48. const ast = replaceDash($(element).children('td').eq(3).text());
  49. const fg = replaceDash($(element).children('td').eq(4).text());
  50. const _3pt = replaceDash($(element).children('td').eq(5).text());
  51. const stl = replaceDash($(element).children('td').eq(9).text());
  52. const blk = replaceDash($(element).children('td').eq(10).text());
  53. const to = replaceDash($(element).children('td').eq(11).text());
  54.  
  55.  
  56. const currentLog = {
  57. 'pts': + pts,
  58. 'reb': + reb,
  59. 'ast': + ast,
  60. 'fg': fgPer,
  61. '3pt': + _3ptMade,
  62. 'stl': + stl,
  63. 'blk': + blk,
  64. 'to': + to
  65. }
  66. playersRef.doc(playerDocRef).update({'currentLog': currentLog})
  67. .catch(error =>
  68. console.error("Error adding document: ", error + " : " + url)
  69. );
  70. });
  71.  
  72.  
  73.  
  74. })
  75.  
  76. .catch((err) => {
  77.  
  78.  
  79. console.log(err);
  80.  
  81.  
  82.  
  83. });
  84.  
  85. };
  86.  
  87. response.send("finished writing logs")
  88.  
  89.  
  90. });
Add Comment
Please, Sign In to add comment