Closed joeyvanlierop closed 4 years ago
When working on this I came across a division by 0 error when the tables had no values. Dunno if it's any concern.
When working on this I came across a division by 0 error when the tables had no values. Dunno if it's any concern.
Are you able to provide any more information?
Of course, here's the stacktrace
(base) [jas@hades xkcdbot]$ python3 -m bot.bot
Traceback (most recent call last):
File "/usr/lib64/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib64/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/jas/Repos/xkcdbot/bot/bot.py", line 292, in <module>
bot.main()
File "/home/jas/Repos/xkcdbot/bot/bot.py", line 58, in main
self.run_stream(inbox_stream, self.handle_inbox)
File "/home/jas/Repos/xkcdbot/bot/bot.py", line 72, in run_stream
callback(item)
File "/home/jas/Repos/xkcdbot/bot/bot.py", line 127, in handle_inbox
self.handle_username_mention(item)
File "/home/jas/Repos/xkcdbot/bot/bot.py", line 153, in handle_username_mention
self.handle_comment(comment, False)
File "/home/jas/Repos/xkcdbot/bot/bot.py", line 111, in handle_comment
response = self.format_response(comic)
File "/home/jas/Repos/xkcdbot/bot/bot.py", line 242, in format_response
percentage = comic_count / total_count * 100
ZeroDivisionError: division by zero
Where total_count
comes from self.database.total_reference_count()
which returns 0 if the statistics_table
is empty.
Implemented in #11
Implement the ability to comment "!latest" or "#latest" and have the bot respond with the most current comic. More information can be found here.
According to xkcd's JSON interface page, the most current comic can be found at: https://xkcd.com/info.0.json