Commit b38c5469 authored by Cian Butler's avatar Cian Butler Committed by Sébastien Helleu

shortenurl.py 0.6.5: make script compatible with Python 3

parent d23fed85
......@@ -14,6 +14,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# History
# 2019-10-01, Cian Butler <[email protected]>
# version 0.6.5: make script compatible with Python 3
# 2019-02-20, Jochen Saalfeld <[email protected]>
# version 0.6.4: Fix is.gd URL pulling
# (fix displaying of shortened URL for is.gd)
......@@ -46,12 +48,16 @@
import re
import weechat
from urllib import urlencode
import urllib2
try:
from urllib.parse import urlencode
from urllib.request import build_opener
except ImportError:
from urllib import urlencode
from urllib2 import build_opener
SCRIPT_NAME = "shortenurl"
SCRIPT_AUTHOR = "John Anderson <[email protected]>"
SCRIPT_VERSION = "0.6.4"
SCRIPT_VERSION = "0.6.5"
SCRIPT_LICENSE = "GPL3"
SCRIPT_DESC = "Shorten long incoming and outgoing URLs"
......@@ -89,7 +95,7 @@ urlRe = re.compile(
if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
SCRIPT_DESC, "", ""):
for option, default_value in settings.iteritems():
for option, default_value in settings.items():
if weechat.config_get_plugin(option) == "":
weechat.config_set_plugin(option, default_value)
......@@ -153,7 +159,7 @@ def get_shortened_url(url):
if shortener == 'tinyurl':
url = TINYURL % urlencode({'url': url})
try:
opener = urllib2.build_opener()
opener = build_opener()
opener.addheaders = [('User-Agent', 'weechat')]
return opener.open(url).read()
except:
......
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