The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Create a bot that logs coffee breaks

Here’s a simple Python bot that logs coffee breaks. It uses a local file to store each coffee break with a timestamp and allows starting, viewing, and exporting logs.

Features:

  • Log a coffee break with timestamp

  • View recent coffee breaks

  • Export logs to CSV

python
import datetime import csv import os LOG_FILE = "coffee_breaks.log" def log_coffee_break(): timestamp = datetime.datetime.now() with open(LOG_FILE, "a") as f: f.write(f"{timestamp.isoformat()}n") print(f"Coffee break logged at {timestamp.strftime('%Y-%m-%d %H:%M:%S')}") def view_coffee_breaks(): if not os.path.exists(LOG_FILE): print("No coffee breaks logged yet.") return with open(LOG_FILE, "r") as f: lines = f.readlines() if not lines: print("No coffee breaks found.") else: print("Coffee break log:") for line in lines: print(f" - {line.strip()}") def export_to_csv(filename="coffee_breaks.csv"): if not os.path.exists(LOG_FILE): print("No coffee breaks to export.") return with open(LOG_FILE, "r") as log_file, open(filename, "w", newline='') as csv_file: writer = csv.writer(csv_file) writer.writerow(["Coffee Break Timestamp"]) for line in log_file: writer.writerow([line.strip()]) print(f"Coffee breaks exported to {filename}") def menu(): while True: print("nCoffee Break Logger") print("1. Log a coffee break") print("2. View coffee breaks") print("3. Export to CSV") print("4. Exit") choice = input("Select an option: ").strip() if choice == '1': log_coffee_break() elif choice == '2': view_coffee_breaks() elif choice == '3': export_to_csv() elif choice == '4': print("Exiting Coffee Break Logger.") break else: print("Invalid choice, please select again.") if __name__ == "__main__": menu()

How to Use:

  1. Save the script as coffee_bot.py.

  2. Run it using python coffee_bot.py.

  3. Use the menu to log and manage your coffee breaks.

Would you like this bot to work as a Slack bot, a web app, or with scheduling capabilities? I can help extend it.

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About