Permalink
Browse files

adding a pickled message sender

  • Loading branch information...
1 parent f720711 commit 233ede4b3e4b3533826b83eb1faf918e7d200d84 @peterbe committed Nov 6, 2011
Showing with 45 additions and 0 deletions.
  1. +45 −0 bin/send_pickled_messages.py
View
45 bin/send_pickled_messages.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+import here
+
+import time
+import cPickle
+import os.path
+import logging
+from glob import glob
+import tornado.options
+from tornado.options import define, options
+
+define("verbose", default=False, help="be louder", type=bool)
+define("debug", default=False, help="run in debug mode", type=bool)
+define("dry_run", default=False, help="print messages to send", type=bool)
+
+def main():
+ from tornado_utils.send_mail import config
+ filenames = glob(os.path.join(config.PICKLE_LOCATION, '*.pickle'))
+ filenames.sort()
+ if not filenames:
+ return
+
+ t0 = time.time()
+ tornado.options.parse_command_line()
+ if options.debug or options.dry_run:
+ from utils.send_mail.backends.console import EmailBackend
+ else:
+ from utils.send_mail.backends.smtp import EmailBackend
+ max_count = 10
+ filenames = filenames[:max_count]
+ messages = [cPickle.load(open(x, 'rb')) for x in filenames]
+ backend = EmailBackend()
+ backend.send_messages(messages)
+ if not options.dry_run:
+ for filename in filenames:
+ if options.verbose:
+ print "SENT", filename
+ os.remove(filename)
+ t1 = time.time()
+ if options.verbose:
+ print ("Sent %s messages in %s seconds" %
+ (len(filenames), t1 - t0))
+
+if __name__ == "__main__":
+ main()

0 comments on commit 233ede4

Please sign in to comment.