Skip to content

Instantly share code, notes, and snippets.

@coconut49
Last active April 22, 2016 00:31
Show Gist options
  • Save coconut49/5a06e69118e85b6af9416b090f577f31 to your computer and use it in GitHub Desktop.
Save coconut49/5a06e69118e85b6af9416b090f577f31 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import requests
import re
import time
def get_xml():
try:
global l
doc = requests.get("http://bbsrss.mirrors.cqupt.edu.cn/bbs/forum.php?mod=rss&fid=68&auth=0").text
l = [[x, y] for x, y in zip(re.findall(re.compile(r'<title>(.*?)</title>'), doc)[2:],
re.findall(re.compile(r'<\!\[CDATA\[([\s\S]*?)\]\]>', flags=re.M), doc))]
print("[INFO] "+time.strftime("%Y-%m-%d-%H:%m:%S")+" "+str(len(l))+" "+str(l[0][0]))
except Exception as e:
print("[ERROR] " + time.strftime("%Y-%m-%d-%H:%m:%S") + " " + str(e))
def send_simple_message():
try:
requests.post(
"https://api.mailgun.net/v3/mg.49.gs/messages",
auth=("api", "key-xxxxxxxxxxxxxxxxx"),
data={"from": "Excited User <[email protected]>",
"to": ["[email protected]"],
"subject": l[0][0],
"text": l[0][1]})
print("[INFO] " + time.strftime("%Y-%m-%d-%H:%m:%S") + "Email Sent subject:" + str(l[0][0]))
except Exception as e:
print("[ERROR] " + time.strftime("%Y-%m-%d-%H:%m:%S") + " " + str(e))
f = None
while True:
try:
get_xml()
if f == None:
f = l[0][0]
if f == l[0][0]:
print("[INFO] " + time.strftime("%Y-%m-%d-%H:%m:%S") + " (´ ・ω・`) ╮(๑╹◡╹๑)╭ ㄟ( ▔,▔ )ㄏ")
else:
f = l[0][0]
if "出租" in l[0][0]:
send_simple_message()
time.sleep(30)
except Exception as e:
print("[ERROR] " + time.strftime("%Y-%m-%d-%H:%m:%S") + " " + str(e))
time.sleep(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment