-
Notifications
You must be signed in to change notification settings - Fork 1
Garage pubsub alert #23
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
base: master
Are you sure you want to change the base?
Changes from all commits
091f060
a000889
7a6c33c
1f30de1
2296bd2
11c5bf9
ed48cc4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,13 +22,21 @@ module.exports = (robot) -> | |
| if garage.garage.toLowerCase() is msg.match[2].toLowerCase() | ||
| msg.send("Garage " + garage.garage + " is " + garage.perc + "% full") | ||
|
|
||
| robot.respond /garage/i, (msg)-> | ||
| getGarages (garages) -> | ||
| robot.respond /garage$/i, (msg)-> | ||
| getGarages (garages, pubsub) -> | ||
| response = "" | ||
| smallest = 100 | ||
| for garage in garages | ||
| if garage.perc < smallest and garage.garage != 'Libra' | ||
| smallest = garage.perc | ||
| response += "Garage #{garage.garage} #{garage.perc}%\n" | ||
| if smallest > 90 | ||
| response += "http://i.imgur.com/OXlUFE1.jpg\n" | ||
| if pubsub | ||
| response += "But hey, Chicken Tender Subs are on sale! | www.arepublixchickentendersubsonsale.com" | ||
|
|
||
| msg.send(response) | ||
|
|
||
| robot.respond /where should I park?/i, (msg)-> | ||
| getGarages (garages) -> | ||
| smallestGarage = {garage: "THEY'RE ALL FULL", perc: 100}; | ||
|
|
@@ -41,17 +49,31 @@ module.exports = (robot) -> | |
| getGarages = (callback) -> | ||
| r = request 'https://secure.parking.ucf.edu/GarageCount/iframe.aspx/', (error, response, body) -> | ||
| garages = [] | ||
| $ = cheerio.load(body); | ||
| pubsub = false; | ||
| $ = cheerio.load(body) | ||
| $('.dxgvDataRow_DevEx').each (i, obj) -> | ||
| thisGarage = {}; | ||
| thisGarage = {} | ||
| html = $(obj).html().replace(RegExp(' ', 'g'), '').split '\n' | ||
| for line in html | ||
| if line.startsWith("percent:") | ||
| percent = parseInt(line.replace("percent:", '')) | ||
| thisGarage.perc = percent | ||
| thisGarage.garage = ($(obj).find('.dxgv').html()).replace("Garage ", '') | ||
| garages[i] = thisGarage | ||
| callback garages | ||
| return null | ||
|
|
||
|
|
||
|
|
||
| if robot.brain.get('pubsubCheckDate') isnt (new Date()).toDateString() | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since now we have two different places where we do the same thing (get pubsub stuff) it would probably be best to have a function somewhere else that is used both here and in scripts/pubsub.js. Buuut we may want to hold off this specific change until we deal with #24 |
||
| robot.brain.set('pubsubCheckDate', (new Date()).toDateString()) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is more a matter of opinion, but wouldn't it be better to assign today's date to a variable instead of calling |
||
| r2 = request 'http://www.arepublixchickentendersubsonsale.com/', (error2, response2, body2) -> | ||
| $ = cheerio.load(body2); | ||
| if $.html().includes("onsale:yes") | ||
| robot.brain.set('pubsub', 'true') | ||
| pubsub = true | ||
| else | ||
| pubsub = false | ||
| callback garages, pubsub | ||
| return null | ||
| else | ||
| if robot.brain.get('pubsub') is 'true' | ||
| pubsub = true | ||
| callback garages, pubsub | ||
| return null | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think
randomexists here. You set it in aforloop in a different function (line 39), on a scope we don't have access to here.