Skip to content

Commit

Permalink
Add support for Telegram
Browse files Browse the repository at this point in the history
  • Loading branch information
MattKobayashi committed Apr 27, 2023
1 parent 81e4780 commit 31e7cc0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 16 deletions.
53 changes: 39 additions & 14 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python3

import requests
import json
import os
Expand Down Expand Up @@ -26,7 +28,7 @@
file.close()

# Get current price data from the API and parse the JSON
apiResponse = requests.post(apiURL, headers={"User-Agent": "FuelHook v2.3.2"})
apiResponse = requests.post(apiURL, headers={"User-Agent": "FuelHook v2.4.0"})
priceDataAPI = json.loads(apiResponse.text)

# Get the last updated time from the API
Expand Down Expand Up @@ -59,18 +61,35 @@
# Add alert to content on price change
if price != float(priceDataFile[type]):
if price > float(priceDataFile[type]):
content += ":arrow_up:\t\t"
if os.environ.get("WEBHOOK_TYPE") == "Discord":
content += ":arrow_up:\t\t"
if os.environ.get("WEBHOOK_TYPE") == "Telegram":
content += "⬆️\t\t"
else:
content += ":arrow_down:\t\t"
content += (
":fuelpump: "
+ str(type)
+ "\t\t:dollar: "
+ str(price)
+ "\t\t:map: "
+ str(loc)
+ "\n\n"
)
if os.environ.get("WEBHOOK_TYPE") == "Discord":
content += ":arrow_down:\t\t"
if os.environ.get("WEBHOOK_TYPE") == "Telegram":
content += "⬇️\t\t"
if os.environ.get("WEBHOOK_TYPE") == "Discord":
content += (
":fuelpump: "
+ str(type)
+ "\t\t:dollar: "
+ str(price)
+ "\t\t:map: "
+ str(loc)
+ "\n\n"
)
if os.environ.get("WEBHOOK_TYPE") == "Telegram":
content += (
"⛽️ "
+ str(type)
+ "\t\t💵 "
+ str(price)
+ "\t\t🗺️ "
+ str(loc)
+ "\n\n"
)

# Add price from API to price data file
priceDataFile[type] = price
Expand All @@ -80,9 +99,15 @@
content += (
"Prices are correct as of "
+ strftime("%a %d %b %Y %H:%M:%S", localtime(lastUpdated))
+ "\n@everyone"
)
requests.post(webhookURL, data={"content": content})
if os.environ.get("WEBHOOK_TYPE") == "Discord":
content += "\n@everyone"
requests.post(webhookURL, data={"content": content})
if os.environ.get("WEBHOOK_TYPE") == "Telegram":
requests.post(webhookURL, params={
"chat_id": int(os.environ.get("TELEGRAM_CHAT_ID")),
"text": str(content)
})

# Write the current price to the JSON file
with open("data/priceData.json", "w") as file:
Expand Down
5 changes: 3 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
version: "3.8"

---
services:
fuelhook:
build:
Expand All @@ -12,7 +11,9 @@ services:
- "TZ=UTC"
- "REGION=All"
- "FUEL_TYPES=[\"E10\", \"U91\", \"U95\", \"U98\", \"Diesel\", \"LPG\"]"
- "WEBHOOK_TYPE="
- "WEBHOOK_URL="
- "TELEGRAM_CHAT_ID="
volumes:
- type: volume
source: fuelhook_data
Expand Down

0 comments on commit 31e7cc0

Please sign in to comment.