Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
deanishe committed May 6, 2019
2 parents 585d9fa + ad17f94 commit 25925f2
Show file tree
Hide file tree
Showing 49 changed files with 3,040 additions and 984 deletions.
Binary file removed Convert-3.5.2.alfredworkflow
Binary file not shown.
Binary file added Convert-3.6.0.alfredworkflow
Binary file not shown.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ Usage
-----

- `conv <quantity> <from unit> [<to unit>]` — Perform a conversion
- `` — Copy the result to the pasteboard
- `⌘C` — Copy result to pasteboard without thousands separator
- `` — Copy result without thousands separator to pasteboard
- `⌘C` — Copy result with thousands separator to pasteboard
- `⌘↩` — Add/remove destination unit as default for this dimensionality
- `⌘L` — Show result in Alfred's Large Type window
- `convinfo` — View help file and information about the workflow, or edit custom units and active currencies
Expand Down
9 changes: 2 additions & 7 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@
import os
import shutil

# ----------------------------------------------------------------------
# Keywords assigned to Alfred Keywords/Script Filters
# ----------------------------------------------------------------------
KEYWORD_CONVERT = 'conv'
KEYWORD_SETTINGS = 'convinfo'

# ----------------------------------------------------------------------
# Result display
# ----------------------------------------------------------------------
Expand All @@ -43,7 +37,8 @@
CURRENCY_CACHE_NAME = 'exchange_rates'
REFERENCE_CURRENCY = 'USD'
OPENX_API_URL = 'https://openexchangerates.org/api/latest.json?app_id={}'
CRYPTO_COMPARE_BASE_URL = 'https://min-api.cryptocompare.com/data/price?fsym={}&tsyms={}'
CRYPTO_COMPARE_BASE_URL = (
'https://min-api.cryptocompare.com/data/price?fsym={}&tsyms={}')
SYMBOLS_PER_REQUEST = 20
USER_AGENT = 'Alfred Convert/{}'.format(os.getenv('alfred_workflow_version'))
NOKEY_FILENAME = 'nokey'
Expand Down
22 changes: 14 additions & 8 deletions src/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,14 @@ class NoToUnits(Exception):
class Input(object):
"""Parsed user query."""

def __init__(self, number, dimensionality, from_unit, to_unit=None):
def __init__(self, number, dimensionality, from_unit,
to_unit=None, context=None):
"""Create new ``Input``."""
self.number = number
self.dimensionality = dimensionality
self.from_unit = from_unit
self.to_unit = to_unit
self.context = context

@property
def is_currency(self):
Expand Down Expand Up @@ -178,6 +181,7 @@ def _decimal_places(self, n):
Returns:
int: Number of decimal places for result.
"""
log.debug('DYNAMIC_DECIMALS: %s', ('off', 'on')[self.dynamic_decimals])

Expand Down Expand Up @@ -384,7 +388,7 @@ def parse(self, query):
if to_unit:
tu = unicode(to_unit.units)
i = Input(from_unit.magnitude, unicode(from_unit.dimensionality),
unicode(from_unit.units), tu)
unicode(from_unit.units), tu, ctx)

log.debug('[parser] %s', i)

Expand Down Expand Up @@ -590,11 +594,11 @@ def convert(query):
DYNAMIC_DECIMALS)
wf.setvar('query', query)
for conv in results:
value = arg = f.formatted(conv.to_number, conv.to_unit)
copytext = f.formatted_no_thousands(conv.to_number, conv.to_unit)
value = copytext = f.formatted(conv.to_number, conv.to_unit)
arg = f.formatted_no_thousands(conv.to_number, conv.to_unit)
if not COPY_UNIT:
arg = f.formatted(conv.to_number)
copytext = f.formatted_no_thousands(conv.to_number)
copytext = f.formatted(conv.to_number)
arg = f.formatted_no_thousands(conv.to_number)

it = wf.add_item(value,
valid=True,
Expand All @@ -609,8 +613,10 @@ def convert(query):
action = 'delete'
name = 'Remove'

mod = it.add_modifier('cmd', u'{} {} as default unit for {}'.format(
name, conv.to_unit, conv.dimensionality))
mod = it.add_modifier(
'cmd',
u'{} {} as default unit for {}'.format(
name, conv.to_unit, conv.dimensionality))
mod.setvar('action', action)
mod.setvar('unit', conv.to_unit)
mod.setvar('dimensionality', conv.dimensionality)
Expand Down
16 changes: 0 additions & 16 deletions src/currency.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,6 @@ def grouper(n, iterable):
return groups


# def interleave(*iterables):
# """Interleave elements of ``iterables``.

# Args:
# *iterables: Iterables to interleave

# Returns:
# list: Elements of ``iterables`` interleaved

# """
# sentinel = object()
# it = izip_longest(*iterables, fillvalue=sentinel)
# c = chain.from_iterable(it)
# return list(filter(lambda v: v is not sentinel, c))


def load_cryptocurrency_rates(symbols):
"""Return dict of exchange rates from CryptoCompare.com.
Expand Down
Loading

0 comments on commit 25925f2

Please sign in to comment.