Skip to content

Commit

Permalink
feat: красивая строка
Browse files Browse the repository at this point in the history
  • Loading branch information
wandeder committed Oct 4, 2023
1 parent bd90da6 commit 2311666
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions spend_bot/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def get_location_reply(location):
"format": "json",
}
result = {
"Страна": "",
"Валюта": "",
"Код валюты": "",
"Страна: ": "",
"Валюта: ": "",
"Код валюты: ": "",
"10 USD = ": 0,
"1000 RUB = ": 0,
}
Expand All @@ -34,23 +34,24 @@ def get_location_reply(location):

)
if country.get("Components")[0].get("kind") == "country":
result["Страна"] = country.get("Components")[0].get("name")
result["Страна: "] = country.get("Components")[0].get("name")

dadata = Dadata(os.getenv("DADATA_KEY"))
currency = dadata.suggest("currency", result["Страна"])[0]
currency = dadata.suggest("currency", result["Страна: "])[0]

if currency.get("data").get("name"):
result["Валюта"] = currency.get("data").get("name")
result["Код валюты"] = currency.get("data").get("strcode")
result["Валюта: "] = currency.get("data").get("name")
result["Код валюты: "] = currency.get("data").get("strcode")

fixer_url = "https://openexchangerates.org/api/latest.json"
fixer_query = {
"app_id": os.getenv("FIXER_KEY"),
"base": "USD",
}
usd_convert_list = requests.get(fixer_url, params=fixer_query).json()
usd_rates = usd_convert_list.get("rates").get(result["Код валюты"])
result["10 USD = "] = round(10 * usd_rates, 2)
result["1000 RUB = "] = round((1000 / usd_convert_list.get("rates").get("RUB")) * usd_rates, 2)
usd_rates = usd_convert_list.get("rates").get(result["Код валюты: "])
result["10 USD = "] = round(10 * usd_rates, 0)
result["1000 RUB = "] = round((1000 / usd_convert_list.get("rates").get("RUB")) * usd_rates, 0)

return result
res_str = [f"{key}{result[key]}\n" for key in result]
return "".join(res_str)

0 comments on commit 2311666

Please sign in to comment.