Created
April 29, 2016 16:04
-
-
Save johandahlberg/23852568c912e66b0ddabe2af4cd83f6 to your computer and use it in GitHub Desktop.
Small bot that posts the Bikupan menu of the day to
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# CC BY-SA 4.0 | |
# http://creativecommons.org/licenses/by-sa/4.0/ | |
import json | |
import time | |
import datetime | |
import requests | |
from bs4 import BeautifulSoup | |
URL_BASE = "http://www.hors.se/veckans-meny/?week_for={date}" | |
SLACK_URL = "<ADD YOUR SLACK POST URL>" | |
CHANNEL = "#random" | |
current_date = time.strftime("%Y-%m-%d") | |
current_date_url = URL_BASE.format(date=current_date) | |
day_of_the_week = datetime.datetime.today().weekday() | |
response = requests.get(current_date_url) | |
response_html = response.text | |
soup = BeautifulSoup(response_html, "html.parser") | |
table = soup.find(lambda tag: tag.name == "table" and tag.has_attr("id") and tag["id"] == "mattabellen") | |
rows = table.findAll(lambda tag: tag.name == "tr") | |
meal_of_the_day = rows[day_of_the_week+1].getText() | |
post_payload = {"channel": CHANNEL, "username": "lunchbot", "text": meal_of_the_day, "icon_emoji": ":bee:"} | |
post_response = requests.post(SLACK_URL, data=json.dumps(post_payload)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment