home · contact · privacy
Improve mobile twitter URL pattern matching.
[plomlombot-irc.git] / plomlombot.py
index 0f738f0003e5c8dca674e97b2df0bde7c9b9c460..e1ec06a4abf82f51a6a60a3a70c3673fe5bf53c5 100755 (executable)
@@ -110,18 +110,19 @@ def lineparser_loop(io, nickname):
 
         def url_check(msg):
 
-            def handle_url(url):
+            def handle_url(url, show_url=False):
 
                 def mobile_twitter_hack(url):
                     re1 = 'https?://(mobile.twitter.com/)[^/]+(/status/)'
-                    re2 = 'https?://mobile.twitter.com/([^/]+)/status/([^\?]+)'
+                    re2 = 'https?://mobile.twitter.com/([^/]+)/status/' \
+                        + '([^\?/]+)'
                     m = re.search(re1, url)
                     if m and m.group(1) == 'mobile.twitter.com/' \
                             and m.group(2) == '/status/':
                         m = re.search(re2, url)
                         url = 'https://twitter.com/' + m.group(1) + '/status/' \
                                 + m.group(2)
-                        handle_url(url)
+                        handle_url(url, True)
                         return True
 
                 try:
@@ -136,7 +137,10 @@ def lineparser_loop(io, nickname):
                     return
                 title = bs4.BeautifulSoup(r.text).title
                 if title:
-                    notice("PAGE TITLE: " + title.string.strip())
+                    prefix = "PAGE TITLE: "
+                    if show_url:
+                        prefix = "PAGE TITLE FOR <" + url + ">: "
+                    notice(prefix + title.string.strip())
                 else:
                     notice("PAGE HAS NO TITLE TAG")