2channel post notification function has been added to the previously created * I made a net news notification app with Python *.
Add a function to notify the posting of 2channel thread to the net news notification application created last time. Target threads that aren't posted often, but you want to check. The notification layout is the same as the net news notification.
・ Appearance at notification (click the icon to jump to the target thread)
・ Stocked without noticing the notification
Get a list of breaking news (dislike) threads in Python.
Created in all 2 processes
mdfmonitor.py
def _get_text(self, url):
try:
l=[]
if (url.find("blog.esuteru") >= 0):
title = urladrs = icon = []
for line in requests.get(url).iter_lines():
# get title
if line.find("<h2>") >= 0:
title = re.sub(".*html\">", "", line)
title = re.sub("</a>.*", "", title)
# get url
if line.find("<h2>") >= 0:
urladrs = re.sub(".*href=\"", "", line)
urladrs = re.sub("\">.*", "", urladrs)
# get icon
if re.search("<img src=.* class=\"pict.*\"", line):
icon = re.sub("\s.*<a.*img src=\"", "", line)
icon = re.sub("\" width.*", "", icon)
if title and urladrs and icon:
l.append([title, urladrs, icon])
title = urladrs = icon = []
elif (url.find("2ch.sc") >= 0):
for line in requests.get(url).iter_lines():
if re.search("<dt>.*<br>", line):
comment = re.sub("<dt>.*<dd>", "", line)
comment = re.sub(" <br> ", " ", comment)
comment = re.sub("<br><br>", "", comment)
comment = re.sub("<a href=.*gt;", ">>", comment)
comment = re.sub("</a>", "", comment)
comment = unicode(comment, "cp932", 'ignore')
comment = comment.encode('utf-8')
l.append([comment, url, "http://www.2ch.sc/img/2ch-logo-fix.gif"])
return l
except requests.exceptions.ConnectionError:
raise ConnectionError("Monitor can't connect the server of url you added.")
newsmoniter.py
tmp $ diff -u org/newsmoniter.py new/newsmoniter.py
--- org/newsmoniter.py 2015-01-28 22:14:51.000000000 +0900
+++ new/newsmoniter.py 2015-01-28 22:14:32.000000000 +0900
@@ -9,10 +9,15 @@
# append file to mdfmonitor instance
monitor.add_url("http://blog.esuteru.com")
+monitor.add_url("http://nozomi.2ch.sc/test/read.cgi/pcqa/1419898591/l50")
for mdf in monitor.monitor():
for title, urladrs, icon in mdf.diff:
- cmd = "/usr/local/bin/terminal-notifier -title new! -message \"{0}\" -open {1} -sound Submarine -appIcon {2}".format(title, urladrs, icon)
+ if (mdf.url.find("2ch.sc") >= 0):
+ sitename = "2channel"
+ else:
+ sitename = "Draft Hachima"
+ cmd = "/usr/local/bin/terminal-notifier -title {0} -message \"{1}\" -open {2} -sound Submarine -appIcon {3}".format(sitename, title, urladrs, icon)
f2 = open("/usr/local/bin/news_cmd.sh", "w")
f2.write(cmd)
os.chmod("/usr/local/bin/news_cmd.sh", 0777)
Port this tool to pepper and display new articles on your chest tablet. Also, let pepper speak the message.
・ OS X Mavericks 10.9.5 -Python 2.7.5 ・ Terminal-notifier 1.6.1
Recommended Posts