Created
May 19, 2017 16:20
-
-
Save paul-english/f89460fd5b9a98407ff4436a82738341 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/local/bin/python | |
| # !/usr/bin/env python | |
| from __future__ import division, print_function | |
| import random | |
| import sys | |
| from datetime import datetime | |
| import numpy as np | |
| import slackweb | |
| slack = slackweb.Slack(url="https://hooks.slack.com/services/...") | |
| lunch_choices = [ | |
| {'weight': 2., 'type': 'mexican', 'name': "Chunga's"}, | |
| {'weight': 2., 'type': 'mexican', 'name': "Red Iguana"}, | |
| {'weight': 2., 'type': 'mexican', 'name': 'Taco Taco'}, | |
| {'weight': 2., 'type': 'mexican', 'name': 'Sear\'s Parking Lot Taco\'s'}, | |
| {'weight': 2., 'type': 'indian', 'name': 'Saffron Valley'}, | |
| {'weight': 3., 'type': 'sandwiches', 'name': 'Robin\'s Nest'}, | |
| {'weight': 2., 'type': 'sandwiches', 'name': 'Even Steven\'s'}, | |
| {'weight': 2., 'type': 'chinese', 'name': 'Panda Express'}, | |
| {'weight': 2., 'type': 'wings', 'name': 'Wing Nutz'}, | |
| {'weight': 2., 'type': 'mexican', 'name': 'Costa Vida'}, | |
| {'weight': 2., 'type': 'grocery', 'name': 'Harmons'}, | |
| {'weight': 2., 'type': 'doner', 'name': 'Spitz'}, | |
| {'weight': 2., 'type': 'german', 'name': 'Seigfreig\'s'}, | |
| {'weight': 2., 'type': 'burgers', 'name': 'Rich\'s Burgers'}, | |
| {'weight': 2., 'type': 'greek', 'name': 'Padelli\'s'}, | |
| {'weight': 2., 'type': 'philly', 'name': 'Moochies'}, | |
| {'weight': 3., 'type': 'middle_eastern_indian', 'name': 'Curried Fried Chicken'}, | |
| {'weight': 1., 'type': 'asian', 'name': 'Zao\'s Asian Cafe'}, | |
| {'weight': 2., 'type': 'asian', 'name': 'Dim Sum House'}, | |
| {'weight': 2., 'type': 'vietnamese', 'name': 'Bahn Mi'}, | |
| {'weight': 3., 'type': 'thai', 'name': 'Ekamai'}, | |
| {'weight': 2., 'type': 'burgers', 'name': 'Tony Burger'}, | |
| {'weight': 2., 'type': 'asian', 'name': 'Hong Kong Tea House'}, | |
| {'weight': 2., 'type': 'pizza', 'name': 'Pie Hole'}, | |
| ] | |
| def query_yes_no(question, default="yes"): | |
| """Ask a yes/no question via raw_input() and return their answer. | |
| "question" is a string that is presented to the user. | |
| "default" is the presumed answer if the user just hits <Enter>. | |
| It must be "yes" (the default), "no" or None (meaning | |
| an answer is required of the user). | |
| The "answer" return value is True for "yes" or False for "no". | |
| """ | |
| valid = {"yes": True, "y": True, "ye": True, | |
| "no": False, "n": False} | |
| if default is None: | |
| prompt = " [y/n] " | |
| elif default == "yes": | |
| prompt = " [Y/n] " | |
| elif default == "no": | |
| prompt = " [y/N] " | |
| else: | |
| raise ValueError("invalid default answer: '%s'" % default) | |
| while True: | |
| sys.stdout.write(question + prompt) | |
| choice = raw_input().lower() | |
| if default is not None and choice == '': | |
| return valid[default] | |
| elif choice in valid: | |
| return valid[choice] | |
| else: | |
| sys.stdout.write("Please respond with 'yes' or 'no' " | |
| "(or 'y' or 'n').\n") | |
| def main(): | |
| today = datetime.now() | |
| if today.weekday() == 2: | |
| lunch_choices.append({'weight': 10, 'type': 'mexican', 'name': 'It\'s Wednesday anyone want Red Iguana'}) | |
| p = np.array([c['weight'] for c in lunch_choices]) | |
| p /= p.sum() | |
| choice = np.random.choice(lunch_choices, p=p) | |
| while not query_yes_no(choice['name']): | |
| choice = np.random.choice(lunch_choices, p=p) | |
| print(choice) | |
| slack.notify(text='%s?' % choice['name'], channel="#artecafeteria", username="Paul English") | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment