Skip to content

Instantly share code, notes, and snippets.

@takeshixx
Last active December 5, 2018 14:20
Show Gist options
  • Save takeshixx/fd3e4a05fac434eace42a6f8c6712cf2 to your computer and use it in GitHub Desktop.
Save takeshixx/fd3e4a05fac434eace42a6f8c6712cf2 to your computer and use it in GitHub Desktop.
Poll CS:GO blog for new blog posts.
#!/usr/bin/env python3
import sys
import time
import requests
import smtplib
import email.message
from lxml import html
SMTP_HOST = 'localhost'
SMTP_PORT = 25
SMTP_FROM = '[email protected]'
SMTP_TO = SMTP_FROM
def sendinfo(title, url):
mail = email.message.EmailMessage()
mail.set_content('New CS:GO Blogpost: ' + url)
mail['Subject'] = title
mail['From'] = SMTP_FROM
mail['To'] = SMTP_TO
smtp = smtplib.SMTP(SMTP_HOST, SMTP_PORT)
smtp.send_message(mail)
smtp.quit()
if __name__ == '__main__':
res = requests.get('http://blog.counter-strike.net/')
doc = html.fromstring(res.text)
for i, container in enumerate(doc.find_class('inner_post')):
post = container.getchildren()[0]
title = post.getchildren()[0].text_content()
url = post.getchildren()[0].get("href")
if i is 0 and title != 'Blue Skies':
print('[' + time.asctime() + '] NEW BLOGPOST RELEASED:', title)
sendinfo(title, url)
sys.exit(0)
print('[' + time.asctime() + '] Nothing changed, yet...')
sys.exit(1)
while true;do /tmp/csgoblog.py && break;sleep 600;done
*/10 * * * * /tmp/csgoblog.py | tee -a /tmp/csgoblog.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment