[modules] Use central location libary instead of individual
This commit is contained in:
parent
74c25ba2ee
commit
8bb47c14aa
4 changed files with 15 additions and 43 deletions
|
@ -30,6 +30,7 @@ import core.widget
|
|||
import core.decorators
|
||||
|
||||
import util.format
|
||||
import util.location
|
||||
|
||||
SYMBOL = {
|
||||
'GBP': u'£', 'EUR': u'€', 'USD': u'$', 'JPY': u'¥', 'KRW': u'₩'
|
||||
|
@ -38,12 +39,6 @@ DEFAULT_DEST = 'USD,EUR,auto'
|
|||
DEFAULT_SRC = 'GBP'
|
||||
|
||||
API_URL = 'https://markets.ft.com/data/currencies/ajax/conversion?baseCurrency={}&comparison={}'
|
||||
LOCATION_URL = 'https://ipvigilante.com/'
|
||||
|
||||
def get_local_country():
|
||||
r = requests.get(LOCATION_URL)
|
||||
location = r.json()
|
||||
return location['data']['country_name']
|
||||
|
||||
def load_country_to_currency():
|
||||
return [
|
||||
|
@ -1079,7 +1074,7 @@ class Module(core.module.Module):
|
|||
def find_local_currency(self):
|
||||
"""Use geolocation lookup to find local currency"""
|
||||
try:
|
||||
country = get_local_country()
|
||||
country = util.location.country()
|
||||
currency_map = load_country_to_currency()
|
||||
return currency_map.get(country, DEFAULT_SRC)
|
||||
except:
|
||||
|
|
|
@ -1,33 +1,17 @@
|
|||
"""Displays public IP address
|
||||
|
||||
Requires the following python packages:
|
||||
* requests
|
||||
|
||||
Parameters:
|
||||
* publicip.region: us-central (default), us-east, us-west, uk, de, pl, nl
|
||||
* publicip.service: web address that returns plaintext ip address (ex. 'http://l2.io/ip')
|
||||
"""
|
||||
|
||||
from requests import get
|
||||
|
||||
import core.module
|
||||
import core.widget
|
||||
import core.decorators
|
||||
|
||||
import util.location
|
||||
|
||||
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 = ''
|
||||
|
||||
|
||||
|
@ -36,11 +20,7 @@ class Module(core.module.Module):
|
|||
|
||||
def update(self):
|
||||
try:
|
||||
if self.__service:
|
||||
self.address = self.__service
|
||||
else:
|
||||
self.address = self.__avail__regions[self.__region]
|
||||
self.__ip = get(self.address).text.rstrip()
|
||||
self.__ip = util.location.public_ip()
|
||||
except Exception:
|
||||
self.__ip = 'n/a'
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ Requires the following python packages:
|
|||
* requests
|
||||
|
||||
Parameters:
|
||||
* weather.location: Set location, defaults to 'auto' for getting location from http://ipinfo.io
|
||||
* weather.location: Set location, defaults to 'auto' for getting location automatically from a web service
|
||||
If set to a comma-separated list, left-click and right-click can be used to rotate the locations.
|
||||
Locations should be city names or city ids.
|
||||
* weather.unit: metric (default), kelvin, imperial
|
||||
|
@ -21,6 +21,7 @@ import core.widget
|
|||
import core.input
|
||||
|
||||
import util.format
|
||||
import util.location
|
||||
|
||||
import re
|
||||
|
||||
|
@ -101,10 +102,7 @@ class Module(core.module.Module):
|
|||
weather_url = 'http://api.openweathermap.org/data/2.5/weather?appid={}'.format(self.__apikey)
|
||||
weather_url = '{}&units={}'.format(weather_url, self.__unit)
|
||||
if self.__location[self.__index] == 'auto':
|
||||
# TODO: make that a general "provider"
|
||||
location_url = 'http://ipinfo.io/json'
|
||||
location = requests.get(location_url).json()
|
||||
coord = location['loc'].split(',')
|
||||
coord = util.location.coordinates()
|
||||
weather_url = '{url}&lat={lat}&lon={lon}'.format(url=weather_url, lat=coord[0], lon=coord[1])
|
||||
elif self.__location[self.__index].isdigit():
|
||||
weather_url = '{url}&id={id}'.format(url=weather_url, id=self.__location[self.__index])
|
||||
|
|
|
@ -7,7 +7,7 @@ Requires the following executable:
|
|||
|
||||
Parameters:
|
||||
* redshift.location : location provider, either of 'auto' (default), 'geoclue2',
|
||||
'ipinfo' (requires the requests package), or 'manual'
|
||||
'ipinfo' or 'manual'
|
||||
'auto' uses whatever redshift is configured to do
|
||||
* redshift.lat : latitude if location is set to 'manual'
|
||||
* redshift.lon : longitude if location is set to 'manual'
|
||||
|
@ -15,7 +15,6 @@ Parameters:
|
|||
|
||||
import re
|
||||
import threading
|
||||
import requests
|
||||
|
||||
import core.module
|
||||
import core.widget
|
||||
|
@ -23,6 +22,7 @@ import core.input
|
|||
import core.decorators
|
||||
|
||||
import util.cli
|
||||
import util.location
|
||||
|
||||
def get_redshift_value(module):
|
||||
widget = module.widget()
|
||||
|
@ -75,14 +75,13 @@ class Module(core.module.Module):
|
|||
if self.parameter('location', '') == 'ipinfo':
|
||||
# override lon/lat with ipinfo
|
||||
try:
|
||||
location_url = 'http://ipinfo.io/json'
|
||||
location = requests.get(location_url).json()
|
||||
self.parameter('lat', location['loc'].split(',')[0])
|
||||
self.parameter('lon', location['loc'].split(',')[1])
|
||||
self.parameter('location', 'manual')
|
||||
location = util.location.coordinates()
|
||||
self.set('lat', location[0])
|
||||
self.set('lon', location[1])
|
||||
self.set('location', 'manual')
|
||||
except Exception:
|
||||
# Fall back to geoclue2.
|
||||
self.parameter('location', 'geoclue2')
|
||||
self.set('location', 'geoclue2')
|
||||
|
||||
self._text = ''
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue