-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLaundryBot.py
64 lines (53 loc) · 3.5 KB
/
LaundryBot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import xmltodict
import requests
import tweepy
from secrets import *
auth = tweepy.OAuthHandler(C_KEY, C_SECRET)
auth.set_access_token(A_TOKEN, A_TOKEN_SECRET)
api = tweepy.API(auth)
def getData(room):
data=requests.get(room)
parsed = xmltodict.parse(data.content)
return parsed
def getWashers(laundryroomData): ##May merge getWashers and getDryers at some point
availWash=0
for appliance in laundryroomData['laundry_room']['appliances']['appliance']:
if appliance['appliance_type'] == 'WASHER':
if appliance['status'] == 'Available':
availWash=availWash+1
return availWash
def getDryers(laundryroomData):
availDry=0
for appliance in laundryroomData['laundry_room']['appliances']['appliance']:
if appliance['appliance_type'] == 'DRYER':
if appliance['status'] == 'Available':
availDry=availDry+1
return availDry
def listMaker():
listData=[]
laundryRooms = {
"Nance": 'http://api.laundryview.com/room/?api_key=8c31a4878805ea4fe690e48fddbfffe1&method=getAppliances&location=194624',
"Phelps 1st Floor":'http://api.laundryview.com/room/?api_key=8c31a4878805ea4fe690e48fddbfffe1&method=getAppliances&location=1946215', ############################
"Phelps 2nd Floor": 'http://api.laundryview.com/room/?api_key=8c31a4878805ea4fe690e48fddbfffe1&method=getAppliances&location=1946216',############################
"Phelps Basement": 'http://api.laundryview.com/room/?api_key=8c31a4878805ea4fe690e48fddbfffe1&method=getAppliances&location=194625', ############################
"Richardson": 'http://api.laundryview.com/room/?api_key=8c31a4878805ea4fe690e48fddbfffe1&method=getAppliances&location=194629', # This API is publicly known
"Roddey 1st Floor": 'http://api.laundryview.com/room/?api_key=8c31a4878805ea4fe690e48fddbfffe1&method=getAppliances&location=194621', # so I don't feel it's
"Roddey 2nd Floor": 'http://api.laundryview.com/room/?api_key=8c31a4878805ea4fe690e48fddbfffe1&method=getAppliances&location=194622', # dangerous to put on GitHub
"Roddey 3rd Floor": 'http://api.laundryview.com/room/?api_key=8c31a4878805ea4fe690e48fddbfffe1&method=getAppliances&location=194623', # (It's alright :) )
"Thomson East": 'http://api.laundryview.com/room/?api_key=8c31a4878805ea4fe690e48fddbfffe1&method=getAppliances&location=194627', ############################
"Thomson West": 'http://api.laundryview.com/room/?api_key=8c31a4878805ea4fe690e48fddbfffe1&method=getAppliances&location=194628', ############################
"Wofford":'http://api.laundryview.com/room/?api_key=8c31a4878805ea4fe690e48fddbfffe1&method=getAppliances&location=1946210', ############################
}
for key, value in laundryRooms.items():
#altText="Currently, there are " + str(getWashers(getData(value))) + " washers and "+ str(getDryers(getData(value))) + " dryers available in the "+ key +" laundry room."
listData.append (key +": "+ str(getWashers(getData(value))) + " W / " + str(getDryers(getData(value))) + " D")
listData.sort(key = lambda x: x.split()[0]) #this sorts listData alphabetically for my sanity
return listData
tweet="\n".join(listMaker())
try:
api.update_status(tweet)
except tweepy.TweepError as error:
if error.api_code == 187:
api.update_status('There are the same number of machines in every room as the last update.')
else:
raise error