nagbot.py 741 B

1234567891011121314151617181920212223242526272829303132
  1. import requests
  2. import json
  3. import sys
  4. import time
  5. import config
  6. def send_msg(msg):
  7. new_status = {'body': msg}
  8. headers = {'Authorization': f'Bearer {config.auth_bearer}'}
  9. response = requests.post(f'{config.api_url}/api/integrations/chat/send', data=json.dumps(new_status),
  10. headers=headers)
  11. return response.json()
  12. def main():
  13. for nag in config.nags:
  14. print(f'Sending \"{nag}\"...')
  15. send_msg(nag)
  16. time.sleep(config.interval) # Wait between messages
  17. try:
  18. while True:
  19. main()
  20. time.sleep(config.interval)
  21. except KeyboardInterrupt:
  22. print('\nExiting program...')
  23. sys.exit()
  24. except Exception as error:
  25. print(f'\n{error}\n')
  26. sys.exit()