diff options
Diffstat (limited to 'scripts/status_script.py')
-rwxr-xr-x | scripts/status_script.py | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/scripts/status_script.py b/scripts/status_script.py index b1ea146..bfc8ade 100755 --- a/scripts/status_script.py +++ b/scripts/status_script.py @@ -43,11 +43,14 @@ def tweet(status, last_change): DATE_MSG = 'Last change was on' SUBLAB_CLOSED = 'OH NOEZ! @sublab is now closed.' + SEPARATOR + DATE_MSG + ' ' SUBLAB_OPEN = 'YAY! @sublab is now open' + SEPARATOR + DATE_MSG + ' ' + SUBLAB_UNKNOWN = "DAMN SON! Current status of @sublab couldn't be retrieved" + ' ' if status == 'open': tweet = SUBLAB_OPEN + last_change elif status == 'closed': tweet = SUBLAB_CLOSED + last_change + elif status == 'unknown': + tweet = SUBLAB_UNKNOWN if len(tweet) <= 140: @@ -58,7 +61,8 @@ def tweet(status, last_change): con_secret_key)) t.statuses.update(status=tweet) - + else: + print "Message too long: " + tweet def update_css(colors): css = ''' @@ -103,7 +107,6 @@ if __name__ == '__main__': # instance of class which gets current status s = SublabStatus() - status = s.door_status() # read file with last status with open(STATUSFILE, 'r') as status_file: @@ -111,13 +114,16 @@ if __name__ == '__main__': last_change = status_file.readline().rstrip() # check if status changed, if yes, update css and tweet it - if status == 'open' and old_status == 'closed': - save_statusfile(STATUSFILE, status) - update_css(('#0f0', '#222', 'status-open.png')) - tweet('open', last_change) - elif status == 'closed' and old_status == 'open': - save_statusfile(STATUSFILE, status) - update_css(('#222', '#f00', 'status-closed.png')) - tweet('closed', last_change) - else: - update_css = (('#222', '#222', 'status-unknown.png')) + if s.door_status() != old_status: + if s.door_status() == 'open': + update_css(('#0f0', '#222', 'status-open.png')) + save_statusfile(STATUSFILE, s.door_status()) + tweet('open', last_change) + if s.door_status() == 'closed': + save_statusfile(STATUSFILE, s.door_status()) + update_css(('#222', '#f00', 'status-closed.png')) + tweet('closed', last_change) + else: + save_statusfile(STATUSFILE, s.door_status()) + update_css(('#222', '#222', 'status-unknown.png')) + tweet('unknown', last_change) |