<s> from django . core . management . base import BaseCommand <EOL> from django . db import DEFAULT_DB_ALIAS <EOL> from optparse import make_option <EOL> class Command ( BaseCommand ) : <EOL> option_list = BaseCommand . option_list + ( <EOL> make_option ( '<STR_LIT>' , <EOL> action = '<STR_LIT:store>' , <EOL> dest = '<STR_LIT>' , <EOL> default = DEFAULT_DB_ALIAS , <EOL> ) , <EOL> ) <EOL> def handle ( self , * args , ** options ) : <EOL> from courriers . backends import get_backend <EOL> from courriers . models import NewsletterSubscriber <EOL> self . connection = options . get ( '<STR_LIT>' ) <EOL> backend_klass = get_backend ( ) <EOL> backend = backend_klass ( ) <EOL> unsubscribed_users = ( NewsletterSubscriber . objects . using ( self . connection ) <EOL> . filter ( is_unsubscribed = True ) <EOL> . values_list ( '<STR_LIT:email>' , flat = True ) <EOL> . order_by ( '<STR_LIT>' ) ) <EOL> mailjet_contacts = backend . mailjet_api . contact . list ( unsub = <NUM_LIT:1> ) <EOL> mailjet_users = [ contact [ '<STR_LIT:email>' ] for contact in mailjet_contacts [ '<STR_LIT:result>' ] ] <EOL> diff = list ( set ( unsubscribed_users ) - set ( mailjet_users ) ) <EOL> print "<STR_LIT>" % len ( diff ) <EOL> for email in diff : <EOL> backend . unregister ( email ) <EOL> print "<STR_LIT>" % email </s>
