Skip to content

Commit

Permalink
Login table check (#4277)
Browse files Browse the repository at this point in the history
check to see if login table exists before attempting record insert
  • Loading branch information
BreezeRo authored and joelgreen committed Aug 19, 2016
1 parent 7293896 commit f002251
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,23 @@ def login(self):
time.sleep(10)

with self.database as conn:
conn.execute('''INSERT INTO login (timestamp, message) VALUES (?, ?)''', (time.time(), 'LOGIN_SUCCESS'))
c = conn.cursor()
c.execute("SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='login'")

result = c.fetchone()

while True:
if result[0] == 1:
conn.execute('''INSERT INTO login (timestamp, message) VALUES (?, ?)''', (time.time(), 'LOGIN_SUCCESS'))
break
else:
self.event_manager.emit(
'login_failed',
sender=self,
level='info',
formatted="Login table not founded, skipping log"
)
break

self.event_manager.emit(
'login_successful',
Expand Down

0 comments on commit f002251

Please sign in to comment.