[modules/publicip] Added region option to publicip module and switched to 'requests' package
This commit is contained in:
parent
0bfb725ae0
commit
c5a1555618
1 changed files with 15 additions and 3 deletions
|
@ -1,9 +1,14 @@
|
|||
"""Displays public IP address
|
||||
|
||||
Requires the following python packages:
|
||||
* requests
|
||||
|
||||
Parameters:
|
||||
* publicip.region: us-central (default), us-east, us-west, uk, de, pl, nl
|
||||
"""
|
||||
|
||||
try:
|
||||
from urllib2 import urlopen
|
||||
from requests import get
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
@ -15,7 +20,14 @@ class Module(bumblebee.engine.Module):
|
|||
super(Module, self).__init__(engine, config,
|
||||
bumblebee.output.Widget(full_text=self.public_ip)
|
||||
)
|
||||
|
||||
self._avail_regions = {"us-east":"http://l2.io/ip",
|
||||
"us-central":"http://whatismyip.akamai.com",
|
||||
"us-west":"http://ipv4bot.whatismyipaddress.com",
|
||||
"pl":"http://ip.42.pl/raw",
|
||||
"de":"http://myexternalip.com/raw",
|
||||
"nl":"http://tnx.nl/ip",
|
||||
"uk":"http://ident.me"}
|
||||
self._region = self.parameter("region", "us-central")
|
||||
self._ip = ""
|
||||
|
||||
|
||||
|
@ -24,7 +36,7 @@ class Module(bumblebee.engine.Module):
|
|||
|
||||
def update(self, widgets):
|
||||
try:
|
||||
self._ip = urlopen("http://ip.42.pl/raw").read()
|
||||
self._ip = get(self._avail_regions[self._region]).text.rstrip()
|
||||
except Exception:
|
||||
self._ip = "Not Connected"
|
||||
|
||||
|
|
Loading…
Reference in a new issue