Skip to content

Commit

Permalink
Slight refactor of chat logon handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
teward committed Mar 13, 2017
1 parent f8a4ec8 commit 158e861
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,42 +77,29 @@
for cl in range(1, 10):
chatlogoncount += 1
try:
# chat.stackexchange.com
GlobalVars.wrap.login(username, password)
GlobalVars.smokeDetector_user_id[GlobalVars.charcoal_room_id] = str(GlobalVars.wrap.get_me().id)
break # If we didn't error out horribly, we can be done with this loop
except (ValueError, AssertionError):
time.sleep(1)
continue # If we did error, we need to try this again.
if chatlogoncount >= 10: # Handle "too many logon attempts" case to prevent infinite looping
raise RuntimeError("Could not get Chat.SE logon.")

# chat.meta.stackexchange.com logon/wrapper
metalogoncount = 0
for cml in range(1, 10):
metalogoncount += 1
try:
# chat.meta.stackexchange.com
GlobalVars.wrapm.login(username, password)
GlobalVars.smokeDetector_user_id[GlobalVars.meta_tavern_room_id] = str(GlobalVars.wrapm.get_me().id)
break # If we didn't error out horribly, we can be done with this loop
except (ValueError, AssertionError):
time.sleep(1)
continue # If we did error, we need to try this again.
if metalogoncount >= 10: # Handle "too many logon attempts" case to prevent infinite looping
raise RuntimeError("Could not get Chat.Meta.SE logon.")

# chat.stackoverflow.com logon/wrapper
sologoncount = 0
for sol in range(1, 10):
sologoncount += 1
try:
# chat.stackoverflow.com
GlobalVars.wrapso.login(username, password)
GlobalVars.smokeDetector_user_id[GlobalVars.socvr_room_id] = str(GlobalVars.wrapso.get_me().id)
break # If we didn't error out horribly, we can be done with this loop

# If we didn't error out horribly, we can be done with this loop
break

except (ValueError, AssertionError):
# One of the chats died, so let's wait a second, and start over.
time.sleep(1)
continue # If we did error, we need to try this again.
if sologoncount >= 10: # Handle "too many logon attempts" case to prevent infinite looping
raise RuntimeError("Could not get Chat.SO logon.")

# Handle "too many logon attempts" case to prevent infinite looping and to handle the 'too many logons' error.
if chatlogoncount >= 10:
raise RuntimeError("Could not get at least one of the chat logons.")

GlobalVars.s = "[ " + GlobalVars.chatmessage_prefix + " ] " \
"SmokeDetector started at [rev " +\
Expand Down

0 comments on commit 158e861

Please sign in to comment.