Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. from lxml import html
  2. import requests
  3. page1 = requests.get( ' https://www.youtube.com/watch?v=duGqrYw4usE ' )
  4. tree1 = html.fromstring(page1.content)
  5. #This will create a list of the view count:
  6. hits1 = tree1.xpath( '//*[@id="watch7-views-info"]/div[1]/text() ' )
  7. # "/text()" IS NEEDED.
  8. #needs to have comma removed and no spaces added, and convert to no comma int or float below
  9. str1= ' '.join(hits1)
  10. # print (str1)
  11. hits3 = str1.translate({ord(c): None for c in ',abcdefghijklmnopqrstuvwxyz'})
  12. oldviewnum = int(hits3)
  13. # print(hits3)
  14. oldhits = oldviewnum - 1
  15. print (oldhits)
  16.  
  17. import time
  18. time.sleep(400)
  19.  
  20. page2 = requests.get( ' https://www.youtube.com/watch?v=duGqrYw4usE ' )
  21. tree2 = html.fromstring(page2.content)
  22. #This will create a list of the view count:
  23. hits2 = tree2.xpath( '//*[@id="watch7-views-info"]/div[1]/text() ' )
  24. # "/text()" IS NEEDED.
  25. #needs to have comma removed and no spaces added, and convert to no comma int or float below
  26. str2= ' '.join(hits2)
  27. # print (str2)
  28. hits4 = str1.translate({ord(c): None for c in ',abcdefghijklmnopqrstuvwxyz'})
  29. currentviewnum = int(hits4)
  30. # print(hits4)
  31. currenthits = currentviewnum - 1
  32. print (currenthits)
  33.  
  34. if currentviewnum - oldviewnum > 9:
  35. print ("+10 views!")
  36. #Send Notification Email
  37. # import smtplib
  38. # mailServer = smtplib.SMTP('smtp.gmail.com' , 587)
  39. # mailServer.starttls()
  40. # mailServer.login("example@gmail.com" , "password")
  41. # msg = "+ 10 Views on Youtube Video"
  42. # mailServer.sendmail("example@gmail.com" , "example@gmail.com" , msg)
  43. # mailServer.quit()
  44. print ("email sent")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement