I tried to make a 2channel post notification application with Python

2channel post notification function has been added to the previously created * I made a net news notification app with Python *.

Thing you want to do

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) スクリーンショット 2015-01-28 21.38.45.png

・ Stocked without noticing the notification スクリーンショット 2015-01-28 21.39.22.png

Referenced materials

Get a list of breaking news (dislike) threads in Python.

Creation procedure

Created in all 2 processes

  1. Repair mdfmonitor ・ Repair location Net news article acquisition process   Added the post acquisition process of 2channel to the article acquisition process of net news.

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.")
  1. Call newsmoniter.py newsmoniter.py has the following two modifications. ・ Addition of notification target URL ・ Dynamically change the title of Notification Center by URL

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)

What I want to do in the future

Port this tool to pepper and display new articles on your chest tablet. Also, let pepper speak the message.

Operation check environment

・ OS X Mavericks 10.9.5 -Python 2.7.5 ・ Terminal-notifier 1.6.1

Recommended Posts

I tried to make a 2channel post notification application with Python
I tried to make a todo application using bottle with python
I tried to make a simple mail sending application with tkinter of Python
[5th] I tried to make a certain authenticator-like tool with python
[2nd] I tried to make a certain authenticator-like tool with python
[3rd] I tried to make a certain authenticator-like tool with python
I tried to make a periodical process with Selenium and Python
[4th] I tried to make a certain authenticator-like tool with python
[1st] I tried to make a certain authenticator-like tool with python
Python: I tried to make a flat / flat_map just right with a generator
I tried to make a traffic light-like with Raspberry Pi 4 (Python edition)
I tried to discriminate a 6-digit number with a number discrimination application made with python
I tried to draw a route map with Python
I tried to automatically generate a password with Python3
I tried to make an OCR application with PySimpleGUI
I tried to make a periodical process with CentOS7, Selenium, Python and Chrome
[Patent analysis] I tried to make a patent map with Python without spending money
[ES Lab] I tried to develop a WEB application with Python and Flask ②
I tried to make a stopwatch using tkinter in python
I tried to make GUI tic-tac-toe with Python and Tkinter
I tried to make a real-time sound source separation mock with Python machine learning
I tried to make a Web API
Rubyist tried to make a simple API with Python + bottle + MySQL
I tried to make a regular expression of "amount" using Python
[Python] I tried to implement stable sorting, so make a note
I tried to make a regular expression of "time" using Python
[Python] A memo that I tried to get started with asyncio
I tried to create a list of prime numbers with python
I tried to make a regular expression of "date" using Python
[Introduction] I want to make a Mastodon Bot with Python! 【Beginners】
I tried to make a strange quote for Jojo with LSTM
I tried to make an image similarity function with Python + OpenCV
I tried to make a mechanism of exclusive control with Go
[Python] I tried to make an application that calculates salary according to working hours with tkinter
[1 hour challenge] I tried to make a fortune-telling site that is too suitable with Python
I tried to make a generator that generates a C # container class from CSV with Python
I made a GUI application with Python + PyQt5
I tried to get CloudWatch data with Python
Try to make a "cryptanalysis" cipher with Python
I tried to output LLVM IR with Python
I tried to automate sushi making with python
Try to make a dihedral group with Python
I want to write to a file with Python
I tried to make a ○ ✕ game using TensorFlow
I tried to communicate with a remote server by Socket communication with Python.
I tried to create a program to convert hexadecimal numbers to decimal numbers with python
I tried to make a calculator with Tkinter so I will write it
I tried to make "Sakurai-san" a LINE BOT with API Gateway + Lambda
[AWS] [GCP] I tried to make cloud services easy to use with Python
[Streamlit] I hate JavaScript, so I make a web application only with Python
[Outlook] I tried to automatically create a daily report email with Python
I tried to build a Mac Python development environment with pythonz + direnv
[Zaif] I tried to make it easy to trade virtual currencies with Python
I tried to make a url shortening service serverless with AWS CDK
I want to make a web application using React and Python flask
I tried fp-growth with python
I tried to make a "fucking big literary converter"
I tried scraping with Python
[Python] When I tried to make a decompression tool with a zip file I just knew, I was addicted to sys.exit ()
Try to make a command standby tool with python
I tried to implement Minesweeper on terminal with python