Forums

script runs in bash but not in scheduler

hi, I've got a script that runs well in bash, but has no return when in scheduler. What is the best way to debug this for a newbie. The input list that is parsed is 676 short text lines, for hourly updates sent by Pushover. I run it every two minutes since I want it to send a notification as close to the hour as possible. here's the script:

import requests import os import time from datetime import datetime

Set the timezone for PythonAnywhere to Tokyo

os.environ["TZ"] = "Asia/Tokyo" time.tzset()

Your Pushover API token and user key.

API_TOKEN = 'YOUR_PUSHOVER_API_TOKEN' USER_KEY = 'YOUR_PUSHOVER_USER_KEY'

def send_pushover_notification(title, message): url = "https://api.pushover.net/1/messages.json" payload = { "token": 'removed', "user": 'removed', "title": title, "message": message, } response = requests.post(url, data=payload) if response.status_code == 200: print(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')} - Notification sent: {title}") else: print(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')} - Failed to send: {title}. Status: {response.status_code}. Response: {response.text}")

def main(): print(f"Script started at: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}") while True: # This loop will cause the script to run indefinitely # Get Tokyo's current date and time without needing pytz now = datetime.now() current_date = now.strftime('%Y-%m-%d') current_time = now.strftime('%H:%M') print(f"Checking notifications at: {now.strftime('%Y-%m-%d %H:%M:%S')}")

    with open('0_list.txt', 'r', encoding='utf-8') as file:
        for line in file:
            date, notif_time, title, body = line.strip().split(',')
            if date == current_date and notif_time == current_time:
                send_pushover_notification(title, body)

    # Sleep for 2 minutes (120 seconds)
    time.sleep(120)

if name == "main": main()

There's a button to access your scheduled tasks logs in the "Actions" column