[modules/publicip] Update to new API

This commit is contained in:
tobi-wan-kenobi 2020-04-11 09:20:19 +02:00
parent 818c0edbc4
commit 22c91e352e

View file

@ -8,40 +8,40 @@ Parameters:
* publicip.service: web address that returns plaintext ip address (ex. 'http://l2.io/ip')
"""
try:
from requests import get
except ImportError:
pass
import bumblebee.output
import bumblebee.engine
import core.module
import core.widget
import core.decorators
class Module(bumblebee.engine.Module):
def __init__(self, engine, config):
super(Module, self).__init__(engine, config,
bumblebee.output.Widget(full_text=self.public_ip)
)
self._avail_regions = {'us-east':'http://checkip.amazonaws.com',
'us-central':'http://whatismyip.akamai.com',
class Module(core.module.Module):
@core.decorators.every(minutes=60)
def __init__(self, config):
super().__init__(config, core.widget.Widget(self.public_ip))
self.__avail__regions = {'us-east':'http://checkip.amazonaws.com',
'us-central':'http://checkip.amazonaws.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._service = self.parameter('service', '')
self._ip = ''
self.__region = self.parameter('region', 'us-central')
self.__service = self.parameter('service', '')
self.__ip = ''
def public_ip(self, widget):
return self._ip
return self.__ip
def update(self, widgets):
def update(self):
try:
if self._service:
self.address = self._service
if self.__service:
self.address = self.__service
else:
self.address = self._avail_regions[self._region]
self._ip = get(self.address).text.rstrip()
self.address = self.__avail__regions[self.__region]
self.__ip = get(self.address).text.rstrip()
except Exception:
self._ip = 'No Connection'
self.__ip = 'n/a'
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4