Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

adding a pickled message sender

  • Loading branch information...
commit 233ede4b3e4b3533826b83eb1faf918e7d200d84 1 parent f720711
Peter Bengtsson authored

Showing 1 changed file with 45 additions and 0 deletions. Show diff stats Hide diff stats

  1. +45 0 bin/send_pickled_messages.py
45 bin/send_pickled_messages.py
... ... @@ -0,0 +1,45 @@
  1 +#!/usr/bin/env python
  2 +import here
  3 +
  4 +import time
  5 +import cPickle
  6 +import os.path
  7 +import logging
  8 +from glob import glob
  9 +import tornado.options
  10 +from tornado.options import define, options
  11 +
  12 +define("verbose", default=False, help="be louder", type=bool)
  13 +define("debug", default=False, help="run in debug mode", type=bool)
  14 +define("dry_run", default=False, help="print messages to send", type=bool)
  15 +
  16 +def main():
  17 + from tornado_utils.send_mail import config
  18 + filenames = glob(os.path.join(config.PICKLE_LOCATION, '*.pickle'))
  19 + filenames.sort()
  20 + if not filenames:
  21 + return
  22 +
  23 + t0 = time.time()
  24 + tornado.options.parse_command_line()
  25 + if options.debug or options.dry_run:
  26 + from utils.send_mail.backends.console import EmailBackend
  27 + else:
  28 + from utils.send_mail.backends.smtp import EmailBackend
  29 + max_count = 10
  30 + filenames = filenames[:max_count]
  31 + messages = [cPickle.load(open(x, 'rb')) for x in filenames]
  32 + backend = EmailBackend()
  33 + backend.send_messages(messages)
  34 + if not options.dry_run:
  35 + for filename in filenames:
  36 + if options.verbose:
  37 + print "SENT", filename
  38 + os.remove(filename)
  39 + t1 = time.time()
  40 + if options.verbose:
  41 + print ("Sent %s messages in %s seconds" %
  42 + (len(filenames), t1 - t0))
  43 +
  44 +if __name__ == "__main__":
  45 + main()

0 comments on commit 233ede4

Please sign in to comment.
Something went wrong with that request. Please try again.