Skip to content

Instantly share code, notes, and snippets.

@azec-pdx
Last active October 10, 2015 01:53
Show Gist options
  • Select an option

  • Save azec-pdx/d9bfdda7b88c84b11f44 to your computer and use it in GitHub Desktop.

Select an option

Save azec-pdx/d9bfdda7b88c84b11f44 to your computer and use it in GitHub Desktop.
Python cron script for e-mail notifications about Rappidgator Premium accounts on Reddit...
#!/usr/bin/env python
__author__ = 'amerzec'
"""
This script checks Reddit updates of Premium Rapidgator accounts
and sends e-mail notification with new link where you can get those accounts.
It is based on:
1. Parsing URL: https://www.reddit.com/r/rapidgator/
2. Sending e-mail with SendGrid account
"""
from urllib.request import urlopen
from urllib.error import HTTPError
from bs4 import BeautifulSoup
import sendgrid
#Constants
EMAIL_FROM = "[email protected]"
EMAIL_TO = "[email protected]"
SENDGRID_API_KEY = "REPLACE_WITH_YOUR_OWN_API_KEY"
REDDIT_RAPIDGATOR_URL = "https://www.reddit.com/r/rapidgator/"
UPDATE_FILE = "links.txt"
def getRapidGators(url):
try:
html = urlopen(url)
except HTTPError as e:
print(e.strerror)
return None
try:
bsObj = BeautifulSoup(html.read(), "html.parser")
mydivs = bsObj.findAll("a", { "tabindex" : "1" })
except AttributeError as e:
return None
return mydivs
def sendEmail(link):
sg = sendgrid.SendGridClient(SENDGRID_API_KEY)
message = sendgrid.Mail()
message.add_to(EMAIL_TO)
message.set_from(EMAIL_FROM)
message.set_subject("New Rapidgator Premiums...")
message.set_html(link)
sg.send(message)
def checkIfAlreadyExists(fileName, link):
# Open a file
f = open(fileName, 'r+')
lines = f.readlines()
exists = True
if len(lines) == 0:
exists = False
for line in lines:
if line == link:
exists = True
if not exists:
f.write(link)
f.truncate()
f.close()
return exists
#Main
myRapids = getRapidGators(REDDIT_RAPIDGATOR_URL)
if myRapids == None:
print("Rapidgators could not be found...")
else:
print(myRapids[1])
rapids = []
for x in myRapids:
rapids.append(str(x))
if checkIfAlreadyExists(UPDATE_FILE, rapids[1]):
pass
else:
sendEmail(rapids[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment