Advertisement
Guest User

bombing_bot.py

a guest
Feb 16th, 2017
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1. from time import time
  2. import praw
  3.  
  4. """
  5. HIROSHIMA
  6. 08/06/1945 08:16:00 JST
  7. -770172240
  8.  
  9. NAGASAKI
  10. 08/09/1945 11:02:00 JST
  11. -769903080
  12. """
  13.  
  14. reddit = praw.Reddit(
  15.     username='username',
  16.     password='password',
  17.     client_id='client_id',
  18.     client_secret='client_secret',
  19.     user_agent='script:Time_Since_Bombings:0.1 (by /u/kimpeek)'
  20. )
  21.  
  22.  
  23. def seconds_since():
  24.     """Return the total seconds since each bombing"""
  25.  
  26.     return time() + 770168640, time() + 769903080
  27.  
  28.  
  29. def converted_seconds(seconds):
  30.     """Calculate the the years, months, days, hours, minutes, seconds and return as tuple
  31.  
  32.    :param seconds: int, float
  33.    :return tuple: 6 ints"""
  34.  
  35.     y, r = divmod(seconds, 60 * 60 * 24 * 365)
  36.     mo, r = divmod(r, 60 * 60 * 24 * (365 / 12))
  37.     d, r = divmod(r, 60 * 60 * 24)
  38.     h, r = divmod(r, 60 * 60)
  39.     mi, r = divmod(r, 60)
  40.     return int(y), int(mo), int(d), int(h), int(mi), int(r)
  41.  
  42.  
  43. def response():
  44.     """Build the response comment
  45.  
  46.    :return str:"""
  47.  
  48.     response_string = """BOOM
  49. Time since Little Boy on Hiroshima
  50. [{}/{}/{}/{}/{}/{}]
  51. Time since Fat Man on Nagasaki
  52. [{}/{}/{}/{}/{}/{}]
  53. """.format(*converted_seconds(seconds_since()[0]), *converted_seconds(seconds_since()[1]))
  54.  
  55.     return response_string
  56.  
  57.  
  58. def main():
  59.     """Watch for mentions and respond to them as they come. Mark them as read after responding"""
  60.  
  61.     for mention in reddit.inbox.mentions():
  62.         if mention.new:
  63.             mention.reply(response())
  64.             mention.mark_read()
  65.  
  66. if __name__ == '__main__':
  67.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement