Skip to content

Commit

Permalink
Merge pull request #10 from ManagedKube/houseseat
Browse files Browse the repository at this point in the history
Houseseat
  • Loading branch information
sekka1 authored Feb 6, 2024
2 parents ecd73f6 + 9091266 commit 28959be
Show file tree
Hide file tree
Showing 4 changed files with 236 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/houseseat-notify-on-event.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## Sends a slack message
## Docs:
## * https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#running-your-pull_request-workflow-when-a-pull-request-merges
##
name: "Slack - houseseat - notify on event"

on:
# Push is for testing only to allow you to test this workflow without
# a merge and just a push.
# push:
pull_request:
# types:
# - closed
# branches:
# - main

## Schedule doc: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule
schedule:
## Cron time is in UTC: 5pm UTC is 10am PST
- cron: '* * * * *'

env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
SLACK_CHANNEL: 'C05B9LLPVD5' # sf-devops.slack.com - recreation-gov
HOUSESEAT_USERNAME: ${{ secrets.HOUSESEAT_USERNAME }}
HOUSESEAT_PASSWORD: ${{ secrets.HOUSESEAT_PASSWORD }}

# Enable debug output
DEBUG: false


jobs:
run:
# if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup
run: |
pip install slack-sdk
- name: Run Script
run: |
cd ./houseseats.com/notify-on-event
python3 search.py
46 changes: 46 additions & 0 deletions houseseats.com/notify-on-event/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# notify-on-event
The purpose of this set of scripts are to continuously search the houseseats.com site after a user has logged in
and search for specific keywords in the events list. Once an event is found, it should send a Slack
notification to a Slack destination.

# Envars

```
export HOUSESEAT_USERNAME=
export HOUSESEAT_PASSWORD=
```

# Run
```
python3 search.py
```

# The process

Logs in

Gets the events page's source

Search for and get a list of all instances of the pattern:
```
<h1><a href="./tickets/view/?showid=1743">Murray The Magician at Tropicana Las Vegas</a></h1>
```
This would be all of the events.

With this list, loop through it.

For each items found, compare it to the items in the `items_to_exclude.txt` file list.

If the item is in the exclude list, then skip it.

If the item is not in the exclude list, send and alert on it


Then for each item, if the string in the excluded text file is not in there, it will send a
notification. This represents a show that we don't know about and is interested in. There are
new shows or one time shows that comes up sometimes and these are the shows we are trying to find.




## scratch
41 changes: 41 additions & 0 deletions houseseats.com/notify-on-event/items_to_exclude.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
bee gees
murray
fooxxxx
l.a. comedy club
mondays dark
carpenters legacy
happy hour comedy
pressbox swing dance
elvis
rich little
the jets
the australian
flyover las vegas
trusted nail
tina turner
jew man group
jay owenhouse
sinatra up close
the joi jazz orchestra
fil-am comedy show
carrot top
a touch of burlesque
adam london laughternoon
house of magic
banachek
eriko trevensolli magic
delirious comedy club
the chris and james dueling piano show
motown extreme
bleach presents
thunder from down under
the magic of jen kramer
chase brown
downtown comedy lounge
black magic live
justin tranz comedy hypnosis show
black girl magic
comedysportz
late night magic
shock collar comedy
micki free
104 changes: 104 additions & 0 deletions houseseats.com/notify-on-event/search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# python script that takes in 4 user inputs via the command line input: FACILITY_ID, TOUR_ID, YEAR, MONTH. Then http get this url: https://www.recreation.gov/api/ticket/availability/facility/${FACILITY_ID}/monthlyAvailabilitySummaryView?year=${YEAR}&month=${MONTH}&inventoryBucket=FIT&tourId=${TOUR_ID}. It will return a json which we will parse in a loop

import requests
import sys
import os
import re
import urllib.parse
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError

# How many tickets are you looking for per time slot
NUMBER_OF_RESERVABLE_PER_TIME_SLOT = 2
SLACK_CHANNEL = os.environ['SLACK_CHANNEL']

## Get envars
debug_on = os.environ.get('DEBUG_ON')

## Disable slack call for local runs
slack_enabled = 'true'
if os.environ.get('DISABLE_SLACK') == 'true':
slack_enabled = 'false'

## Send message to Slack
## doc: https://github.com/slackapi/python-slack-sdk#sending-a-message-to-slack
def send_to_slack(message):
client = WebClient(token=os.environ['SLACK_BOT_TOKEN'])

response = client.chat_postMessage(channel=SLACK_CHANNEL, text=message)


print('Starting program...')

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

# Define the login data
login_data = {
'email': os.environ['HOUSESEAT_USERNAME'],
'password': os.environ['HOUSESEAT_PASSWORD'],
'submit': 'login',
'lastplace': '',
}

headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
'Accept-Language': 'en-US,en;q=0.5'
}

# URL of the login page
login_url = 'https://lv.houseseats.com/member/index.bv'

# Send a POST request to the login page with your login data
s.post(login_url, data=login_data, headers=headers)

# Now s maintains the 'logged in' session. You can use it to send additional requests
response = s.get('https://lv.houseseats.com/member/ajax/upcoming-shows.bv?supersecret=&search=&sortField=&startMonthYear=&endMonthYear=&startDate=&endDate=&start=0', headers=headers)

# Print the content of the 'protected page'
# print(response.text)


# Find all instances of the <h1> title of a show
pattern = r'<h1><a href="./tickets/view/\?showid=(.*?)">(.*?)</a></h1>'

# Use re.findall() to find all instances of the pattern in the string
matches = re.findall(pattern, response.text.lower())

## Loop through the list of matches which should be all of the shows/events on the page
for event in matches:
print(f'found: {event[0]} | {event[1]}')

## Compare to see if the event is in the exclude list.
## If it is in the exclude list, then do not send a message to Slack
## if it is not in the exclude list, then send a message to Slack
found_exclude = False

with open('items_to_exclude.txt', 'r') as file:
for line in file:
## Do something with each line
search_item = line.strip()
# print(search_item)

# Define regular expression pattern
pattern = fr'{search_item}'

# Use regular expression to extract text
result = re.search(pattern, event[1].lower())

# Print extracted text
if result:
print(f'found {search_item}')

found_exclude = True

## If the event is not in the exclude list, then send a message to Slack
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])}>
""")

0 comments on commit 28959be

Please sign in to comment.