Skip to content

Commit

Permalink
Merge pull request #29 from guerda/feat_day_of_week
Browse files Browse the repository at this point in the history
feat: include day of week in the post text
  • Loading branch information
guerda authored Jan 1, 2025
2 parents a82e4bd + b755425 commit e36866e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions euemastobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import requests
import asyncio
from playwright.async_api import async_playwright
import locale

threshold = 100
mastodon = None
Expand Down Expand Up @@ -44,7 +45,7 @@ def get_slots_from_forecast(forecast):
# If the threshold was exceeded at the end, has it been added to the array yet?
if not added:
start_text = datetime.fromtimestamp(start).strftime("%H:%M")
end_text = "0:00"
end_text = "00:00"
slots.append((start_text, end_text))
return slots

Expand Down Expand Up @@ -78,12 +79,14 @@ def get_mastodon_client():

def post_timeslots_to_mastodon(time_slots, attach_screenshot=False, media_id=None):
mastodon = get_mastodon_client()
day_of_week = datetime.today().strftime("%A")
slot_text = ", ".join(["{} - {}".format(slot[0], slot[1]) for slot in time_slots])
status_text = """Der Anteil der erneuerbaren Energien in Deutschland liegt voraussichtlich heute zwischen {} über {}%.
status_text = """Am heutigen {} liegt zwischen zwischen {} der Anteil der erneuerbaren Energien in Deutschland voraussichtlich über {}%.
Daten via https://energy-charts.info/charts/consumption_advice/chart.htm""".format(
slot_text, threshold
day_of_week, slot_text, threshold
)
logger.debug(status_text)
status = mastodon.status_post(status_text, language="de", media_ids=media_id)
logger.info("Posted status #{} ({})".format(status["id"], status["created_at"]))
return status["url"]
Expand Down Expand Up @@ -116,9 +119,11 @@ async def create_screenshot_of_traffic_light():
if __name__ == "__main__":
FORMAT = "%(asctime)s [%(levelname)s] %(name)s - %(message)s"
date_format = "%d.%m. %H:%M:%S"
logging.basicConfig(level=logging.INFO, format=FORMAT, datefmt=date_format)
logging.basicConfig(level=logging.DEBUG, format=FORMAT, datefmt=date_format)
logger = logging.getLogger("euemastobot")

locale.setlocale(locale.LC_TIME, "de_DE")

time_slots = None
try:
time_slots = get_time_slots()
Expand Down

0 comments on commit e36866e

Please sign in to comment.