Commit 6f79e259 authored by anonymous2ch's avatar anonymous2ch Committed by Sébastien Helleu

url_olde.py 0.6: improve URL matching

parent 3034042d
# -*- coding: utf-8 -*-
""" """
database init code from https://weechat.org/scripts/source/triggerreply.py.html database init code from https://weechat.org/scripts/source/triggerreply.py.html
regex is from http://stackoverflow.com/questions/6883049/regex-to-find-urls-in-string-in-python regex is from http://stackoverflow.com/questions/520031/whats-the-cleanest-way-to-extract-urls-from-a-string-using-python
TODO TODO
---- ----
...@@ -11,7 +12,7 @@ TODO ...@@ -11,7 +12,7 @@ TODO
SCRIPT_NAME = "url_olde" SCRIPT_NAME = "url_olde"
SCRIPT_AUTHOR = "Charlie Allom <charlie@evilforbeginners.com" SCRIPT_AUTHOR = "Charlie Allom <charlie@evilforbeginners.com"
SCRIPT_VERSION = "0.5" SCRIPT_VERSION = "0.6"
SCRIPT_LICENSE = "GPL3" SCRIPT_LICENSE = "GPL3"
SCRIPT_DESC = "tells you how long ago a URL was first posted and by whom, for bragging rights." SCRIPT_DESC = "tells you how long ago a URL was first posted and by whom, for bragging rights."
...@@ -53,7 +54,7 @@ def search_urls_cb(data, buffer, date, tags, displayed, highlight, prefix, messa ...@@ -53,7 +54,7 @@ def search_urls_cb(data, buffer, date, tags, displayed, highlight, prefix, messa
database.text_factory = str database.text_factory = str
cursor = database.cursor() cursor = database.cursor()
nick = prefix nick = prefix
full_uri = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&#+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', message) full_uri = re.findall(r'(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@)?(?:(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:/[^\s]*)?', message)
channel = w.buffer_get_string(buffer, 'name') # current channel. channel = w.buffer_get_string(buffer, 'name') # current channel.
# w.prnt(w.current_buffer(), 'full_uri: %s ' % (full_uri)) # debug # w.prnt(w.current_buffer(), 'full_uri: %s ' % (full_uri)) # debug
for olde in full_uri: # iterate over each URI we get in the list from full_uri regex for olde in full_uri: # iterate over each URI we get in the list from full_uri regex
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment