Skip to main content

货币汇率转换

Project description

The Money Converter

Python汇率转换工具类,数据来源于themoneyconverter

快速入门

安装

pip install themoneyconverter

使用

from the_money_converter import MoneyConverter, Currency


if __name__ == '__main__':
    # 获取1元人民币转换其它货币的汇率
    moneyConverter = MoneyConverter(Currency.CNY.name)
    moneyConverter.refresh()
    rate = moneyConverter.get_rate(Currency.ARS.name)
    print(Currency.ARS.value, rate)

执行结果示例

Connected to pydev debugger (build 203.7717.81)
Hi, PyCharm
结果:5.471575446150859 比例0.8023283317948717
阿根廷比索 30.9827

Process finished with exit code 0

代码说明

class MoneyConverter:
    URL_TEMPLATE = 'https://themoneyconverter.com/zh-CN/{source}/{target}?amount=1.00'

    def __init__(self, source='CNY', target='CNY'):
        self.rate = {}
        self.source = source
        self.target = target
        self.updateTime = None

source是转出货币,target是转入货币,比如说moneyConverter = MoneyConverter(Currency.CNY.name)是1元人民币转换其它货币的汇率,target用默认值即可,目前没什么用

支持以下货币汇率互相转换

  • AED = 阿联酋迪拉姆
  • JPY = 日元
  • ARS = 阿根廷比索
  • KRW = 韩元
  • AUD = 澳元
  • MAD = 摩洛哥迪拉姆
  • BRL = 巴西雷亚尔
  • MXN = 墨西哥比索
  • CAD = 加元
  • NOK = 挪威克朗
  • CHF = 瑞士法郎
  • NZD = 新西兰元
  • CNY = 人民币
  • PHP = 菲律宾比索
  • CZK = 捷克克朗
  • PLN = 波兰兹罗提
  • DKK = 丹麦克朗
  • RUB = 俄罗斯卢布
  • EUR = 欧元
  • SEK = 瑞典克朗
  • GBP = 英镑
  • SGD = 新加坡元
  • HKD = 港元
  • THB = 泰铢
  • HUF = 匈牙利福林
  • TRY = 土耳其里拉
  • ILS = 以色列谢克尔
  • USD = 美元
  • INR = 印度卢比
  • ZAR = 南非南特

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

the-money-converter-1.0.0.tar.gz (4.1 kB view details)

Uploaded Source

File details

Details for the file the-money-converter-1.0.0.tar.gz.

File metadata

  • Download URL: the-money-converter-1.0.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.7

File hashes

Hashes for the-money-converter-1.0.0.tar.gz
Algorithm Hash digest
SHA256 77654cd64e46db8a5c75240ae160bb20585c67f2e207d7cde2c367fd7d3c13a8
MD5 e4e95e28999ee2b6facd97f5f325546c
BLAKE2b-256 1f235c6c553e362c8ac2d617777240fec1324a67baf11e3c5e08d1fcf127a8ca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page