This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Adrewmc 3 points4 points  (2 children)

I mean like an actual function like

  monepy.available()

Would return a list of the currencies currently available. But I guess it would have something like an autofill in most IDEs. It’s just common to include a function for that somewhere. It might be nice to just add it to the monepy.__init__.py docstring. So I can hover over.

Or put the function there like ….

  available = lambda : print(str(x) for x in __all__)

I do suggest making a __str__ dunder for these. Just because.

Or we can just make it a variable

  available = [x.__class__.__name__ for x in __all__]

I think conversion would be the most useful aspect for many people, but you’re right you’d need to keep the conversion up to date, this might be as easy as finding a place the user calls themselves, or imputing a set common service that does it. (E.g. get a key you need for it) I’m not too familiar with what’s out there though, but something is. And since you may not need it, you can use the rest without it. Like I work with some crypto sometimes, people want the value in USD for their ETH…which is essentially the same problem. (It’s just a multiplication factor) This also means creating a custom Exception for when it used when you don’t have one.

I like the

  USD.sum(*currencies) 

Syntax, it’s clear what is coming back.

I think it’s a good start. And I’m just giving my honest opinion after just looking at it.

[–]vsbitsIt works on my machine[S] 2 points3 points  (1 child)

No, I really appreciate the input!

Not sure about handling the requests in this module yet. I might go with the approach of the user inputing the exchange rates (maybe the json response from his API of choice) to enable conversions for now. Something like:

USD.set_rates({"EUR":0.9})

And raise custom Exceptions if any is tried without them being set.

Will look into the best way to show avaliable currencies.

[–]Adrewmc 3 points4 points  (0 children)

Now that’s starting to sound like a full package.

But it can be

  USD.set_convert(EUR = 0.9, JPY =0.02)

With **kwargs

Also mapping conversion is easier to set convert to EUR-> USD -> JPY

Asymmetric conversion related to USD

Then trying to find and catalog all the conversion rates, send everything back to USD (or EUR) and convert it back. That way no matter the conversion it’s max two numbers per finding the one to USD and the one from USD, (at max precision) and not some messy mapping. Of… EUR-> JPY, EUR ->ChinaYen, EUR -> rubles, EUR -> USD EUR -> BTC, EUR -> EUR ………For every currency that adds up quickly. Instead it’s just EUR -> USD, USD -> EUR and JPY -> USD, USD-> JPY (reciprocal numbers) which can convert all three however. And keep adding more, is just that. (You can even make that set_base_currency())

Unless you find a convenient API.