Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- ## this script loads torrentleech.org website, checks for any news (usually invites) and if there's anything new,
- ## sends alert from your gmail address. Use python3 and install lxml library via pip3 install lxml
- ## author: ramirezzRK
- from lxml import html
- from email.mime.text import MIMEText
- import requests
- import smtplib
- # initialising e-mail variables, please fill up with your information
- emailTo = "sendto@email.com" # where to send alert
- emailFrom = "your.email@gmail.com"
- emailSMTPServer = "smtp.gmail.com"
- emailUsername = "your.email@gmail.com"
- emailPassword = "yourPassword"
- newsBodyList = [] # initialising empty list of articles
- page = requests.get('https://www.torrentleech.org/') # parsing website for data
- tree = html.fromstring(page.content) # we create 2 lists, one for headlines and one for body content
- newsHeadline = tree.xpath('//*[@id="news"]/div[*]/h3/text()') # creating headlines list
- newsCount = len(newsHeadline)
- for x in range (0, newsCount): # creating body list
- # this populates newsBodyList with content. new entry for each article
- newsBody = tree.xpath('//*[@id="news"]/div[' + str(x + 1) + ']/p//text()')
- newsBodyList.append("".join(newsBody))
- # print () # uncomment to print all Headlines and Article Body to stdout (screen)
- # print (newsHeadline[x])
- # print (' ', end="")
- # for y in newsBody:
- # print (y, end="")
- # print ()
- try:
- file = open('entries.dat', 'r') # open file with previous data
- lines = file.read().splitlines() # read articles from file, split entries in list by newline
- except IOError:
- file = open('entries.dat', 'x') # create file if it doesn't exist
- lines = []
- file.close()
- if lines != newsBodyList: # if there's new articles send email
- file = open('entries.dat', 'w') # write all articles to file, just body, no headline
- file.write("\n".join(newsBodyList))
- file.close()
- for item in lines: # remove old articles from both Headline and Body lists
- index = newsBodyList.index(item)
- newsBodyList.pop(index)
- newsHeadline.pop(index)
- s = smtplib.SMTP_SSL(emailSMTPServer) # e-mail server setup
- s.login(emailUsername, emailPassword)
- for item in newsBodyList: # send e-mail with new articles
- msg = MIMEText(item)
- msg['Subject'] = newsHeadline[newsBodyList.index(item)]
- msg['From'] = emailFrom
- msg['To'] = emailTo
- s.sendmail(emailFrom, emailTo, msg.as_string())
- s.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement