Last active
December 11, 2018 20:51
-
-
Save fredtux/f17ad980ec60e397ccc9d99dfbae680c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import feedparser | |
| import time | |
| import re | |
| import smtplib | |
| from datetime import datetime | |
| import urllib2 | |
| def internet_on(): | |
| try: | |
| urllib2.urlopen('http://216.58.192.142', timeout=1) | |
| return True | |
| except urllib2.URLError as err: | |
| return False | |
| def sendEmail(list): | |
| server = smtplib.SMTP("smtp.gmail.com", 587) | |
| server.ehlo() | |
| server.starttls() | |
| server.ehlo() | |
| server.login("", "") | |
| subject = 'Tuts - ' + datetime.now().strftime('%Y-%m-%d %H:%M:%S') | |
| message = "\n".join(list) | |
| server.sendmail("", "", 'Subject: {}\n\n{}'.format(subject, message)) | |
| if __name__ == "__main__": | |
| while internet_on() == False: | |
| time.sleep(10) | |
| first = True | |
| last = 0 | |
| with open("last", "r+") as f: | |
| last = f.read() | |
| newList = [] | |
| while True: | |
| # Get tuts feed | |
| tuts = feedparser.parse("https://tutsgalaxy.com/feed/") | |
| # Loop through articles | |
| for article in tuts["entries"]: | |
| reg = re.compile("\?p\=(.*)") | |
| lastCandidate = reg.search(article["id"].encode("utf-8")).group(1) | |
| if lastCandidate > last: | |
| last = lastCandidate | |
| elif first == False: | |
| break | |
| with open("links", "a+") as f: | |
| f.write(' => '.join([article["title"].encode("utf-8"), article["id"].encode("utf-8")])) | |
| f.write("\n") | |
| newList.append(' => '.join([article["title"].encode("utf-8"), article["id"].encode("utf-8")])) | |
| # Make first run false | |
| first = False | |
| # Write last value to file | |
| with open("last", "w") as f: | |
| f.write(last) | |
| if len(newList) > 5: | |
| sendEmail(newList) | |
| newList = [] | |
| time.sleep(60) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment