[modules/publicip] Update to new API
This commit is contained in:
parent
818c0edbc4
commit
22c91e352e
1 changed files with 23 additions and 23 deletions
|
@ -8,40 +8,40 @@ Parameters:
|
||||||
* publicip.service: web address that returns plaintext ip address (ex. 'http://l2.io/ip')
|
* publicip.service: web address that returns plaintext ip address (ex. 'http://l2.io/ip')
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
from requests import get
|
||||||
from requests import get
|
|
||||||
except ImportError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
import bumblebee.output
|
import core.module
|
||||||
import bumblebee.engine
|
import core.widget
|
||||||
|
import core.decorators
|
||||||
|
|
||||||
class Module(bumblebee.engine.Module):
|
class Module(core.module.Module):
|
||||||
def __init__(self, engine, config):
|
@core.decorators.every(minutes=60)
|
||||||
super(Module, self).__init__(engine, config,
|
def __init__(self, config):
|
||||||
bumblebee.output.Widget(full_text=self.public_ip)
|
super().__init__(config, core.widget.Widget(self.public_ip))
|
||||||
)
|
|
||||||
self._avail_regions = {'us-east':'http://checkip.amazonaws.com',
|
self.__avail__regions = {'us-east':'http://checkip.amazonaws.com',
|
||||||
'us-central':'http://whatismyip.akamai.com',
|
'us-central':'http://checkip.amazonaws.com',
|
||||||
'us-west':'http://ipv4bot.whatismyipaddress.com',
|
'us-west':'http://ipv4bot.whatismyipaddress.com',
|
||||||
'pl':'http://ip.42.pl/raw',
|
'pl':'http://ip.42.pl/raw',
|
||||||
'de':'http://myexternalip.com/raw',
|
'de':'http://myexternalip.com/raw',
|
||||||
'nl':'http://tnx.nl/ip',
|
'nl':'http://tnx.nl/ip',
|
||||||
'uk':'http://ident.me'}
|
'uk':'http://ident.me'}
|
||||||
self._region = self.parameter('region', 'us-central')
|
self.__region = self.parameter('region', 'us-central')
|
||||||
self._service = self.parameter('service', '')
|
self.__service = self.parameter('service', '')
|
||||||
self._ip = ''
|
self.__ip = ''
|
||||||
|
|
||||||
|
|
||||||
def public_ip(self, widget):
|
def public_ip(self, widget):
|
||||||
return self._ip
|
return self.__ip
|
||||||
|
|
||||||
def update(self, widgets):
|
def update(self):
|
||||||
try:
|
try:
|
||||||
if self._service:
|
if self.__service:
|
||||||
self.address = self._service
|
self.address = self.__service
|
||||||
else:
|
else:
|
||||||
self.address = self._avail_regions[self._region]
|
self.address = self.__avail__regions[self.__region]
|
||||||
self._ip = get(self.address).text.rstrip()
|
self.__ip = get(self.address).text.rstrip()
|
||||||
except Exception:
|
except Exception:
|
||||||
self._ip = 'No Connection'
|
self.__ip = 'n/a'
|
||||||
|
|
||||||
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
Loading…
Reference in a new issue