LowEndBox - Cheap VPS, Hosting and Dedicated Server Deals

How to Monitor New LowEndTalk Offers with Python

In July 2020, there was a discussion on LowEndTalk about how to monitor new offers on LET.  Several solutions were posted, but I think the easiest is to parse LET’s RSS feed.  In this tutorial, we’ll show you a simple script you can use to get an email alert when new offers are posted on LowEndTalk.

Although LowEndTalk and LowEndBox are related, not all providers post on both sites so it’s worth watching both for offers!

Prerequisites

I’m running this on a Debian 9 box at home.  The system is configured for relay mail via Amazon SES, so my script can just drop mail on the localhost’s port 25.  If you need to connect directly to GMail or another mail service, you’ll need to use HTTPS, your password, etc. but the script is easy to fix up and I’ll link below.

Note that this script is written for Python 3.  If you’re using Python 2, it should probably work as-is but I have not checked.  Note that on your distro, Python 3 might appear as either /usr/bin/python3 or just /usr/bin/python.

I’m using the feedparser module, so you’ll need to:

pip3 install feedparser

The Script

#!/usr/bin/python3

import os, feedparser, smtplib, ssl
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

cache_file = os.environ['HOME'] + "/.let_offers"
sender_email = "someone@example.com"
receiver_email = "someone@example.com"

offers_seen = []
notifications = []

if ( os.path.exists(cache_file) == True ):
    with open(cache_file) as fh:
        offers_seen = [line.rstrip() for line in fh]

NewsFeed = feedparser.parse("https://www.lowendtalk.com/categories/offers.rss")
for entry in NewsFeed.entries:
    if ( entry.link not in offers_seen ):
        notifications.append(entry)
        fh = open(cache_file,"a")
        fh.write(entry.link + "\n")
        fh.close()

if ( len(notifications) > 0 ):
    message = MIMEMultipart("alternative")
    message["Subject"] = "New LET Offers!"
    message["From"] = sender_email
    message["To"] = receiver_email
    html = "<html><body>"
    html += "<h1>There are new LET offers!</h1>"
    for notification in notifications:
        html += "<br />"
        html += "<p><a href=\"" + notification.link + "\">"
        html += notification.title 
        html += "</a> from " + notification.author + "</p>"
    html += "</body></html>"
    part1 = MIMEText(html, "html")
    message.attach(part1)
    with smtplib.SMTP("localhost", 25) as server:
     server.sendmail(
         sender_email, receiver_email, message.as_string()
     )

Be aware that whitespace in Python is significant and simple copy-pasting may not work.  You may need to replace the spaces at beginnings of lines with appropriate TAB characters.

Save this in a file like /usr/local/bin/let_offer_monitor.py .  Make sure it’s executable:

chmod 755 /usr/local/bin/let_offer_monitor.py

Then add a cron job to run it every 15 minutes or however often you like and you should start getting emails.  The first email will have everything in the RSS cache but subsequent emails will only show new offers.

How It Works

The script creates a dot file in your home directory called .let_offers.  This is a cache of links it’s seen.

Then when it runs, it loads those links into the offers_seen list.  It uses the feedparser module to read LET’s RSS feed for the “offers” category and checks each one to see if it’s in the existing cache.  If it is not, it adds it to a ‘notifications’ list (this is so we can send one email instead of one email per new offer).

When it’s done examining the RSS feed, if there are notifications to send, it builds an HTML email and send them to you with the title and author.  The title is linked so you can just click on it.  Here is an example:

Modifying the Script

I took the code for sending email from this page on realpython.com.  If you need to use SSL, connect to a different port, or use a password to send email, you can easily replace my simplified code with the more full example there.

 

 

 

 

 

raindog308

1 Comment

  1. Stupid Unicorn:

    Thanks for the script!

    It actually reminded me to try reading the LowEndTalk Offers RSS in a reader. I’ll see if I actually want to receive notifications via email.

    Is there an Offers RSS link for LowEndBox?

    February 5, 2021 @ 1:05 am | Reply

Leave a Reply to Stupid Unicorn Cancel reply

Some notes on commenting on LowEndBox:

  • Do not use LowEndBox for support issues. Go to your hosting provider and issue a ticket there. Coming here saying "my VPS is down, what do I do?!" will only have your comments removed.
  • Akismet is used for spam detection. Some comments may be held temporarily for manual approval.
  • Use <pre>...</pre> to quote the output from your terminal/console, or consider using a pastebin service.

Your email address will not be published. Required fields are marked *