1_foundations / push_utils.py
ravishankarj's picture
Upload folder using huggingface_hub
1a20058 verified
Raw History Blame Contribute Delete
1.52 kB
import os
import requests
from dotenv import load_dotenv
# Load environment variables
load_dotenv(override=True)
# Get Pushover credentials
pushover_user = os.getenv("PUSHOVER_USER")
pushover_token = os.getenv("PUSHOVER_TOKEN")
pushover_url = "https://api.pushover.net/1/messages.json"
def push(message):
"""
Send a push notification using Pushover.
Returns True if successful, False otherwise.
"""
try:
print(f"Push: {message}")
payload = {"user": pushover_user, "token": pushover_token, "message": message}
response = requests.post(pushover_url, data=payload)
print(f"Status Code: {response.status_code}")
print(f"Response: {response.text}")
if response.status_code != 200:
print(f"Error sending push notification: {response.text}")
return response.status_code == 200
except Exception as e:
print(f"Error in push notification: {str(e)}")
return False
def record_user_details(email, name="Name not provided", notes="not provided"):
"""Record user details and send a push notification"""
success = push(f"Recording interest from {name} with email {email} and notes {notes}")
return {"recorded": "ok" if success else "failed"}
def record_unknown_question(question):
"""Record an unknown question and send a push notification"""
success = push(f"Recording {question} asked that I couldn't answer")
return {"recorded": "ok" if success else "failed"}