Skip to content

Commit 14e4083

Browse files
authored
improve[servers]: add sarfe toman price (#23)
1 parent 3ccaf67 commit 14e4083

5 files changed

Lines changed: 596 additions & 4 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ dependencies = [
1616
"eiogram==2.0.1",
1717
"hcloud==2.5.4",
1818
"apscheduler>=3.11.0",
19+
"aiohttp>=3.13.2",
1920
]

src/handlers/servers/info.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from src.lang import Dialogs
99
from src.keys import BotKB, BotCB, AreaType, TaskType
1010
from src.utils.depends import GetHetzner, ClearState
11+
from src.utils.euro import get_euro
1112

1213
router = Router()
1314

@@ -28,8 +29,15 @@ async def servers_info(callback_query: CallbackQuery, callback_data: BotCB, hetz
2829
price_hourly = "➖"
2930
price_monthly = "➖"
3031
if prices:
31-
price_hourly = f"{float(prices[0]['price_hourly']['gross']):.4f}"
32-
price_monthly = f"{float(prices[0]['price_monthly']['gross']):.2f}"
32+
hourly = float(prices[0]["price_hourly"]["gross"])
33+
monthly = float(prices[0]["price_monthly"]["gross"])
34+
try:
35+
euro_rate = await get_euro()
36+
price_hourly = f"{hourly:.4f}€ [{hourly * euro_rate:,.0f}T]"
37+
price_monthly = f"{monthly:.2f}€ [{monthly * euro_rate:,.0f}T]"
38+
except Exception:
39+
price_hourly = f"{hourly:.4f}€"
40+
price_monthly = f"{monthly:.2f}€"
3341

3442
update = await callback_query.message.edit(
3543
text=Dialogs.SERVERS_INFO.format(

src/lang/_dialog.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ class Dialogs(StrEnum):
4646
• Used: <code>{traffic_used_percent}% [Out/Included traffic]</code>
4747
• Billable: <code>{traffic_billable} GB</code>
4848
<b>💰 Price:</b>
49-
• Hourly: <code>{price_hourly}</code>
50-
• Monthly: <code>{price_monthly}</code>
49+
• Hourly: <code>{price_hourly}</code>
50+
• Monthly: <code>{price_monthly}</code>
5151
<b>📅 Created:</b> <code>{created}</code> [<code>{created_day} days ago</code>]
5252
"""
5353
SERVERS_REBUILD_CONFIRM = "<b>⚠️ Are you sure you want to rebuild the server?</b>\n🧹 This action will erase all data on the server.\n🖼️ Please select an image to proceed."

src/utils/euro.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import aiohttp
2+
3+
4+
async def get_euro() -> int:
5+
async with aiohttp.ClientSession() as session:
6+
async with session.get(url="https://sarfe.erfjab.com/api/prices") as res:
7+
res.raise_for_status()
8+
data = await res.json()
9+
return int(data["eur1"])

0 commit comments

Comments
 (0)