Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from lxml import html
- import requests
- page1 = requests.get( ' https://www.youtube.com/watch?v=duGqrYw4usE ' )
- tree1 = html.fromstring(page1.content)
- #This will create a list of the view count:
- hits1 = tree1.xpath( '//*[@id="watch7-views-info"]/div[1]/text() ' )
- # "/text()" IS NEEDED.
- #needs to have comma removed and no spaces added, and convert to no comma int or float below
- str1= ' '.join(hits1)
- # print (str1)
- hits3 = str1.translate({ord(c): None for c in ',abcdefghijklmnopqrstuvwxyz'})
- oldviewnum = int(hits3)
- # print(hits3)
- oldhits = oldviewnum - 1
- print (oldhits)
- import time
- time.sleep(400)
- page2 = requests.get( ' https://www.youtube.com/watch?v=duGqrYw4usE ' )
- tree2 = html.fromstring(page2.content)
- #This will create a list of the view count:
- hits2 = tree2.xpath( '//*[@id="watch7-views-info"]/div[1]/text() ' )
- # "/text()" IS NEEDED.
- #needs to have comma removed and no spaces added, and convert to no comma int or float below
- str2= ' '.join(hits2)
- # print (str2)
- hits4 = str1.translate({ord(c): None for c in ',abcdefghijklmnopqrstuvwxyz'})
- currentviewnum = int(hits4)
- # print(hits4)
- currenthits = currentviewnum - 1
- print (currenthits)
- if currentviewnum - oldviewnum > 9:
- print ("+10 views!")
- #Send Notification Email
- # import smtplib
- # mailServer = smtplib.SMTP('smtp.gmail.com' , 587)
- # mailServer.starttls()
- # mailServer.login("example@gmail.com" , "password")
- # msg = "+ 10 Views on Youtube Video"
- # mailServer.sendmail("example@gmail.com" , "example@gmail.com" , msg)
- # mailServer.quit()
- print ("email sent")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement