-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
python version and change API to jisuapi
- Loading branch information
祝文博
committed
May 4, 2023
1 parent
bc6a418
commit 5b67fb2
Showing
6 changed files
with
61 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/local/bin/python3 | ||
# -*- coding: UTF-8 -*- | ||
|
||
import sys | ||
import os | ||
from CurrencyExchange import CurrencyExchange | ||
|
||
# please config app_key in Workflow Environment Variables | ||
app_key = os.getenv('app_key') | ||
# from currency | ||
original_currency = sys.argv[1] | ||
# to currency | ||
destination_currency = sys.argv[2] | ||
# alfred input amount | ||
input = sys.argv[3].replace(",", "") | ||
query = float(input) | ||
|
||
currency_exchange = CurrencyExchange(app_key) | ||
currency_exchange.calculate(original_currency, destination_currency, query) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/python3 | ||
# -*- coding: UTF-8 -*- | ||
|
||
import urllib.parse | ||
from urllib import request | ||
import json | ||
|
||
|
||
class CurrencyExchange: | ||
api = "https://api.jisuapi.com/exchange/convert" | ||
|
||
def __init__(self, app_key): | ||
self.app_key = app_key | ||
|
||
def calculate(self, original_currency, destination_currency, input_amount): | ||
param = {'from': original_currency, 'to': destination_currency, 'appkey': self.app_key, 'amount': input_amount} | ||
param_string = urllib.parse.urlencode(param) | ||
url = self.api + "?" + param_string | ||
with request.urlopen(url) as f: | ||
data = f.read() | ||
if f.status == 200: | ||
content = data.decode('utf-8') | ||
result = json.loads(content) | ||
if result['status'] == 0: | ||
exchange = result['result']['rate'] | ||
output_amount = result['result']['camount'] | ||
subtitle = str(input_amount) + " " + original_currency + " to " + destination_currency + " with exchange rate " + exchange + " = " + str( | ||
output_amount) | ||
output_dict = {'items': [{'title': output_amount, 'subtitle': subtitle, 'arg': output_amount}]} | ||
print(json.dumps(output_dict)) | ||
else: | ||
print(str(result['status']) + ':' + result['msg']) | ||
else: | ||
print('request fail') |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.