Skip to content

Commit

Permalink
fix getting image
Browse files Browse the repository at this point in the history
problematic: if " is used in env file it lead them in enviroment variable, so, they should be striped in python code then

checker that a valid image acliable in MAP_URL

verbosity added to black
  • Loading branch information
yurnov committed Mar 28, 2024
1 parent c5a453d commit 3cc18e1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
# - name: Lint Python code with black
# run: |
# black --check --skip-string-normalization --line-length 120 bot
# black --check --verbose --skip-string-normalization --line-length 120 bot

- name: Lint Python code
run: |
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.black
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ FROM python:3.12-slim

RUN python -m pip install requests~=2.31.0 python-dotenv~=1.0.1 pytz==2024.1 black==24.3.0 pylint==3.1.0

CMD [ "black", "--skip-string-normalization", "--line-length", "120", "bot" ]
CMD [ "black", "--skip-string-normalization", "--verbose", "--line-length", "120", "bot" ]
22 changes: 21 additions & 1 deletion bot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,29 @@
if MAP == "true" and not MAP_URL:
logger.warning("MAP_URL is not defined in .env file, using a default URL http://alerts.net.ua/alerts_map.png")
MAP_URL = "http://alerts.net.ua/alerts_map.png"
else:
MAP_URL = MAP_URL.strip('"')
# ensure that MAP_URL is a valid URL with image (based on Content-Type)
try:
resp = requests.head(MAP_URL, timeout=15)
resp.raise_for_status()
if not resp.headers.get("Content-Type") or not resp.headers.get("Content-Type").startswith("image/"):
logger.error("MAP_URL is not a valid URL with image, set MAP to false")
MAP = "false"
del resp
except requests.exceptions.RequestException as err:
logger.error(f"Error while checking MAP_URL: {err}, set MAP to false")
MAP = "false"
del err

if MAP == "true":
LOG_MAP = "MAP_URL is " + MAP_URL
else:
LOG_MAP = "MAP is false"

logger.info(f"Bot started with CHAT_ID: {CHAT_ID} and SLIENT: {SLIENT}")
logger.info(f"Bot started with CHAT_ID: {CHAT_ID}, SLIENT: {SLIENT} and {LOG_MAP}")
logger.info(f"Following regions will be monitored: {REGION_LIST}")
del LOG_MAP


def get_data():
Expand Down

0 comments on commit 3cc18e1

Please sign in to comment.