Skip to content

Instantly share code, notes, and snippets.

@craigcabrey
Last active March 7, 2016 22:04
Show Gist options
  • Save craigcabrey/edba23a07ab3ac81d1ed to your computer and use it in GitHub Desktop.
Save craigcabrey/edba23a07ab3ac81d1ed to your computer and use it in GitHub Desktop.
Quick script to see if the Field House is closed.
[Unit]
Description=Check status of Field House
[Service]
Type=oneshot
ExecStart=/usr/local/bin/is_it_closed.py
[Install]
WantedBy=multiuser.target
[Unit]
Description=Check status of field house
[Timer]
OnCalendar=Sat 10:00:00
Persistent=true
[Install]
WantedBy=timers.target
#!/usr/bin/env python3
# Install dependencies: sudo pip3 install requests beautifulsoup4 pushbullet.py
# Usage: python3 is_it_closed.py
import sys
# If you want pushbullet notifications (for a cron job, say) install the
# pushbullet.py pip package and generate an API key on their site and put it
# here.
pb_key = ''
try:
import pushbullet
pb = pushbullet.Pushbullet(pb_key)
except ImportError:
pb = None
except pushbullet.errors.InvalidKeyError:
pb = None
print('Invalid Pushbullet key, ignoring.')
try:
import bs4
import requests
except ImportError:
print('You need requests and beautifulsoup4, try running')
print('sudo pip3 install requests beautifulsoup4 pushbullet.py')
sys.exit(1)
def notify(message):
if pb:
pb.push_note('Field House Status', message)
def main():
res = requests.get('https://www.rit.edu/fa/arenas/gordon-field-house/facility-hours')
html = bs4.BeautifulSoup(res.text, 'html.parser')
selector = 'div.field-item.even div.columns.evencolumns div > p'
element = html.select_one(selector)
if element and 'due to a ticketed event' in element.text:
print('you better believe it\'s closed')
notify('Field House entrance is closed.')
else:
print('looks like students can use it for once')
notify('Field House entrance is open.')
if __name__ == '__main__':
main()
@craigcabrey
Copy link
Author

Usage: python3 is_it_closed.py -or- ./is_it_closed.py

Throw in a pushbullet API key for extra juiciness. Add it to your crontab (or systemd timer, those configs are included) for bonus points.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment