<commit_before>#!/usr/bin/python3
from gpiopins import GPIOSoda
import w1
import logging
import telebot
import datetime

with open('api_key.txt') as key_file:
    API_KEY = key_file.readline().strip()

print('API Key: ', API_KEY)

# Bot setup
bot = telebot.TeleBot(API_KEY)
telebot.logger.setLevel(logging.DEBUG)

# Startup GPIO pins
gpio = GPIOSoda()

logging.basicConfig(format='[%(levelname)s:%(threadName)s:%(name)s:%(funcName)s] %(message)s', level=logging.DEBUG)
log = logging.getLogger(__name__)

commands = { # Command description in help text
    'getsodastatus': 'zeigt den Füllzustand meiner Fächer',
    'gettemp': 'zeigt die Temperatur im Inneren'
}

@bot.message_handler(commands=['help', 'start'])
def handle_help(message):
    name = message.chat.first_name or "zusammen"
    msg = "Hi " + name + ",\n" \
          "ich bin der BStone Getränkeautomat aus Haus 4.\n" \
          "Wenn du wissen willst, wie es mir gerade geht, probier doch mal folgendes:\n\n"
    # Add all commands with description
    for cmd, desc in commands.items():
        msg += "/"+cmd + " - " + desc + "\n"

    bot.reply_to(message, msg)

@bot.message_handler(commands=['getsodastatus'])
def handle_soda_status(message):
    msg = "Füllstand der Getränkefächer:\n"

    for tray, status in gpio.get_status_all().items():
        if status == 0:
            msg += "✅ "
        else:
            msg += "⚠ "

        msg += tray + "\n"

    bot.reply_to(message, msg)

@bot.message_handler(commands=['gettemp'])
def handle_temp_status(message):
    msg = ''
    try:
        temp = w1.read_therm_sensor()
        msg = "Im Innenraum hat es gerade " + str(temp) + "°C."

    except IOError as e:
        log.error("W1 sensor not connected properly. Please check.")
        msg = "Ups, das weiß ich gerade auch nicht so genau. Mein Sensor ist offline. ".encode() \
          + b'\xF0\x9F\x98\x88'

    bot.reply_to(message, msg)

@bot.message_handler(commands=['gettime'])
def handle_get_time(message):
    msg = "Bei mir ists jetzt " + str(datetime.datetime.now().hour) + ":" + str(datetime.datetime.now().minute)
    bot.reply_to(message, msg)

def handle_bier(message):
    msg = ""
    if datetime.datetime.now().hour > 7 and datetime.datetime.now().hour < 16:
        msg += "Kein Bier vor vier!!!"
    else:
        msg += "Prost!"
    return msg<commit_msg>Show current time when beer is not allowed<commit_after>#!/usr/bin/python3
from gpiopins import GPIOSoda
import w1
import logging
import telebot
import datetime

with open('api_key.txt') as key_file:
    API_KEY = key_file.readline().strip()

print('API Key: ', API_KEY)

# Bot setup
bot = telebot.TeleBot(API_KEY)
telebot.logger.setLevel(logging.DEBUG)

# Startup GPIO pins
gpio = GPIOSoda()

logging.basicConfig(format='[%(levelname)s:%(threadName)s:%(name)s:%(funcName)s] %(message)s', level=logging.DEBUG)
log = logging.getLogger(__name__)

commands = { # Command description in help text
    'getsodastatus': 'zeigt den Füllzustand meiner Fächer',
    'gettemp': 'zeigt die Temperatur im Inneren'
}

@bot.message_handler(commands=['help', 'start'])
def handle_help(message):
    name = message.chat.first_name or "zusammen"
    msg = "Hi " + name + ",\n" \
          "ich bin der BStone Getränkeautomat aus Haus 4.\n" \
          "Wenn du wissen willst, wie es mir gerade geht, probier doch mal folgendes:\n\n"
    # Add all commands with description
    for cmd, desc in commands.items():
        msg += "/"+cmd + " - " + desc + "\n"

    bot.reply_to(message, msg)

@bot.message_handler(commands=['getsodastatus'])
def handle_soda_status(message):
    msg = "Füllstand der Getränkefächer:\n"

    for tray, status in gpio.get_status_all().items():
        if status == 0:
            msg += "✅ "
        else:
            msg += "⚠ "

        msg += tray + "\n"

    bot.reply_to(message, msg)

@bot.message_handler(commands=['gettemp'])
def handle_temp_status(message):
    msg = ''
    try:
        temp = w1.read_therm_sensor()
        msg = "Im Innenraum hat es gerade " + str(temp) + "°C."

    except IOError as e:
        log.error("W1 sensor not connected properly. Please check.")
        msg = "Ups, das weiß ich gerade auch nicht so genau. Mein Sensor ist offline. ".encode() \
          + b'\xF0\x9F\x98\x88'

    bot.reply_to(message, msg)

def handle_bier(message):
    msg = ""
    time = datetime.datetime.now()
    if time.hour > 7 and time.hour < 16:
        msg += "Kein Bier vor vier!!!\n"
        msg += "Bei mir ists jetzt " + time.strftime("%H:%M")
    else:
        msg += "Prost ð» !"

    return msg
{'fraction_non_alphanumeric': 0.1410200523103749, 'fraction_numerical': 0.006538796861377506, 'mean_word_length': 3.119389587073609, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3126980', 'n_tokens_mistral': 1618, 'n_tokens_neox': 1598, 'n_words': 411}