Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete Rewrite #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
URL=
VERIFICATION_TOKEN=
SLACK_BOT_TOKEN=
CHANNEL=
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
auth.py
auth_long.py
.env

2 changes: 0 additions & 2 deletions auth.py.example

This file was deleted.

4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
python-dotenv==0.10.5
requests==2.22.0
slackclient==2.5.0

52 changes: 52 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import glob
import os
from datetime import datetime
from sys import argv

import requests
from dotenv import load_dotenv
from slack import WebClient

load_dotenv()

URL = os.getenv('URL')
VERIFICATION_TOKEN = os.getenv('VERIFICATION_TOKEN')
SLACK_TOKEN = os.getenv('SLACK_BOT_TOKEN')
CHANNEL = os.getenv('SLACK_CHANNEL')

d = datetime.now()


def uploadaudio():
list_of_files = glob.glob('audio/*.mp3')
latest_file = max(list_of_files, key=os.path.getctime)
wc = WebClient(token=SLACK_TOKEN)
wc.files_upload(
channels=CHANNEL,
file=latest_file
)


if __name__ == "__main__":
try:
message = ""
type_ = ""
if len(argv) < 2 or argv[1].lower() == 'normal':
type_ = 'normal'
message = "TONES RECEIVED. Stand by for text message dispatch."
if d.weekday() == 0 and d.hour == 18 and 0 <= d.minute <= 10:
message = "TONES RECEIVED but likely to be the weekly pager test. Confirm a possible" \
" call using other means."
elif argv[1].lower() == 'long':
type_ = 'long'
message = "LONGTONE (GROUP ALERT) RECEIVED. Stand by for further information."
if d.weekday() == 5 and d.hour == 12 and 0 <= d.minute <= 10:
message = "LONGTONE (GROUP ALERT) RECEIVED but likely to be the weekly all-call test. Confirm any" \
" possible message using other means."
else:
raise ValueError
requests.post(url=URL, data={'message': message, "type": type_},
headers={"Authorization": f"BEARER {VERIFICATION_TOKEN}"})
uploadaudio()
except ValueError:
print("Incorrect argument. Please use either 'normal' or 'long'")
15 changes: 0 additions & 15 deletions sendAudio.py

This file was deleted.

16 changes: 0 additions & 16 deletions sendLongtoneNotification

This file was deleted.

20 changes: 0 additions & 20 deletions sendNotification

This file was deleted.