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

Houseseat v2 #11

Merged
merged 6 commits into from
Feb 7, 2024
Merged
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
12 changes: 12 additions & 0 deletions .github/workflows/houseseat-notify-on-event.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,22 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Setup
run: |
pip install slack-sdk
- name: Run Script
run: |
cd ./houseseats.com/notify-on-event
python3 search.py
- name: Commit and push
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add .
git commit -m "[houseseat-notify-on-event action] Updating the state.yaml file"
git push origin main
env:
## This is the personal access token (PAT) for the GitHub bot user
GITHUB_TOKEN: ${{ secrets.PLAYGROUND_REPO }}
23 changes: 23 additions & 0 deletions houseseats.com/notify-on-event/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,26 @@ new shows or one time shows that comes up sometimes and these are the shows we a


## scratch

New process:
* Open the state.yaml file and read it the yaml to a list of dictionaries
* Go and get a list of all the events
* Loop through the new events list
* If the event is in the exclude file list, then dont process this event anymore, else continue
* If the event is NOT in the previous state dictionary list
* then send a notification to slack
* add it into the new state list dictionary
* If the event is in the previous state dictionary list
* add it into the new state list dictionary
* Output the new state list dictionary to the state.yaml file


What this should do based on how events shows up and leaves:
* 7:00pm battle bot comes up
* alert goes to slack
* 7:05pm battle bots does not alert again
* 7:10pm battle bots is removed
* 7:15pm battle bots shows up again
* alert goes to slack

This means that it will only alert on new events that freshly comes up.
49 changes: 41 additions & 8 deletions houseseats.com/notify-on-event/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import urllib.parse
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError
import yaml

# How many tickets are you looking for per time slot
NUMBER_OF_RESERVABLE_PER_TIME_SLOT = 2
Expand All @@ -30,6 +31,17 @@ def send_to_slack(message):

print('Starting program...')


# Open the state YAML file
with open('state.yaml', 'r') as file:
# Load the YAML data from the file
previous_state = yaml.safe_load(file)

# Now data is a list of dictionaries
print(previous_state)

new_state = []

# Create a session object
s = requests.Session()

Expand Down Expand Up @@ -93,12 +105,33 @@ def send_to_slack(message):

found_exclude = True

## If the event is not in the exclude list, then send a message to Slack
## If the event is not in the exclude list, then continue to process the event
if found_exclude == False:
print(f'[NOTIFY] not found in exclude list: {event[0]} | {event[1]}')

## Send message to Slack
if slack_enabled == 'true':
send_to_slack(f"""
*[Houseseat]* Search found: <https://lv.houseseats.com/member/tickets/view/?showid={urllib.parse.unquote(event[0])}|{urllib.parse.unquote(event[1])}>
""")
print(f'[NOT IN EXCLUDE LIST] not found in exclude list: {event[0]} | {event[1]}')

## Add the event to the new state dictionary list
new_state.append({
'event_id': event[0],
'event_name': event[1]
})

## If the event is NOT in the previous state dictionary list then send a message to Slack
## and write it to the new state dictionary list
found_in_previous_state = False

for item in previous_state:
if item['event_id'] == event[0]:
found_in_previous_state = True

if not found_in_previous_state:
## Send message to Slack
print(f'[NOTIFY] Sending slack message for: {event[0]} | {event[1]}')
if slack_enabled == 'true':
send_to_slack(f"""
*[Houseseat v2]* Search found: <https://lv.houseseats.com/member/tickets/view/?showid={urllib.parse.unquote(event[0])}|{urllib.parse.unquote(event[1])}>
""")

# Output the new state dictionary list to the state.yaml file
with open('state.yaml', 'w') as file:
# Write the YAML data to the file
yaml.dump(new_state, file)
3 changes: 3 additions & 0 deletions houseseats.com/notify-on-event/state.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- event_id: '1'
event_name: foo

Loading