def handle(self, *args, **options): councils = Council.objects.all() accepte_credit = get_credit() for council in councils: for event in council.events.all(): if event.sent_datetime == None and (event.event_datetime - timedelta(days=1)) < datetime.now(): if accepte_credit > 0: recipients = event.sms_recipients() sendsms(event.originator, recipients, event.message, datetime.now()) event.sent_datetime = datetime.now() event.save() accepte_credit = accepte_credit - len(recipients) else: message = 'ERROR: Accepte has not enough credit bought to send queued sms\'s. Buy credits imediately! To identify how many, run credits_left command. Then Purchase required amount. Then Manually run sms_send command again.' send_email( 'Credits Negative -- Error', '*****@*****.**', '*****@*****.**', {'message': message }, {'plain': 'elections/credits_low.txt'}, ) return False return True
def handle(self, *args, **options): accepte_credits = get_credit() for election_instance in ElectionInstance.objects.all(): if election_instance.modules.filter(slug='SMS').count() != 0: phone_nums = VisitorResult.objects.filter(election_instance=election_instance).exclude(telephone=None).values('telephone').distinct() for phone_num in phone_nums: if accepte_credits > 0: visitor_results = VisitorResult.objects.filter(election_instance=election_instance, telephone=phone_num['telephone']).latest() if visitor_results.sent == None: #get(election_instance=election_instance, telephone=phone_num). top_3 = visitor_results.candidate_answers.order_by('-candidates_score')[:3] message = 'Voting is tomorrow, your top three candidates were ' for candidate in top_3: message= message + str(candidate.candidate.profile.full_name()) + ', score: ' + str(candidate.candidates_score) + ' ' sendsms(election_instance.council.name[0:11], phone_num['telephone'], message, datetime.now()) visitor_results.sent = datetime.now() visitor_results.save() accepte_credits = accepte_credits - 1 else: message = 'ERROR: Accepte has not enough credit bought to send queued sms\'s. Buy credits imediately! To identify how many, run credits_left command. Then Purchase required amount. Then Manually run sms_results command again.' send_email( 'Credits Negative -- Error', '*****@*****.**', '*****@*****.**', {'message': message }, {'plain': 'elections/credits_low.txt'}, ) return False return True
def handle(self, *args, **options): councils = Council.objects.all() accepte_credit = get_credit() for council in councils: for event in council.events.all(): if event.sent_datetime == None and ( event.event_datetime - timedelta(days=1)) < datetime.now(): if accepte_credit > 0: recipients = event.sms_recipients() sendsms(event.originator, recipients, event.message, datetime.now()) event.sent_datetime = datetime.now() event.save() accepte_credit = accepte_credit - len(recipients) else: message = 'ERROR: Accepte has not enough credit bought to send queued sms\'s. Buy credits imediately! To identify how many, run credits_left command. Then Purchase required amount. Then Manually run sms_send command again.' send_email( 'Credits Negative -- Error', '*****@*****.**', '*****@*****.**', {'message': message}, {'plain': 'elections/credits_low.txt'}, ) return False return True
def handle(self, *args, **options): list_eis = options.get('list') send = options.get('send') fake = options.get('fake') accepte_credit = get_credit() if list_eis: for ei in ElectionInstance.objects.filter( modules__slug='SMS').filter( visitor_results__sent__isnull=True).distinct().all(): print "%s - %s" % (ei.pk, ei.name) return True if fake or send: id = fake or send try: ei = ElectionInstance.objects.get(pk=id) except: print "Election Instance not found" return False if ei.modules.filter( slug='SMS').count() == 0 or ei.visitor_results.filter( sent__isnull=True).count() == 0: print "Nothing to do" return False if accepte_credit > 0: recipients = ei.visitor_results.filter( sent__isnull=True).distinct('telephone').filter( telephone__isnull=False).values_list('telephone', flat=True) recipients = list(set(recipients)) if send: for r in recipients: sendsms( 'Wiekiesjij', [r], 'Vandaag: Tweede Kamerverkiezingen! U kunt stemmen in ieder stemlokaal (binnen uw eigen gemeente). Vergeet uw stempas en ID-bewijs niet!', datetime.now()) ei.visitor_results.update(sent=datetime.now()) accepte_credit = accepte_credit - len(recipients) elif fake: print "Would send %s messages for the election instance" % ( len(recipients)) else: print "Not enough credits" return False return True
def handle(self, *args, **options): accepte_credits = get_credit() for election_instance in ElectionInstance.objects.all(): if election_instance.modules.filter(slug='SMS').count() != 0: phone_nums = VisitorResult.objects.filter( election_instance=election_instance).exclude( telephone=None).values('telephone').distinct() for phone_num in phone_nums: if accepte_credits > 0: visitor_results = VisitorResult.objects.filter( election_instance=election_instance, telephone=phone_num['telephone']).latest() if visitor_results.sent == None: #get(election_instance=election_instance, telephone=phone_num). top_3 = visitor_results.candidate_answers.order_by( '-candidates_score')[:3] message = 'Voting is tomorrow, your top three candidates were ' for candidate in top_3: message = message + str( candidate.candidate.profile.full_name( )) + ', score: ' + str( candidate.candidates_score) + ' ' sendsms(election_instance.council.name[0:11], phone_num['telephone'], message, datetime.now()) visitor_results.sent = datetime.now() visitor_results.save() accepte_credits = accepte_credits - 1 else: message = 'ERROR: Accepte has not enough credit bought to send queued sms\'s. Buy credits imediately! To identify how many, run credits_left command. Then Purchase required amount. Then Manually run sms_results command again.' send_email( 'Credits Negative -- Error', '*****@*****.**', '*****@*****.**', {'message': message}, {'plain': 'elections/credits_low.txt'}, ) return False return True
def handle(self, *args, **options): list_eis = options.get('list') send = options.get('send') fake = options.get('fake') accepte_credit = get_credit() if list_eis: for ei in ElectionInstance.objects.filter(modules__slug='SMS').filter(visitor_results__sent__isnull=True).distinct().all(): print "%s - %s" % (ei.pk, ei.name) return True if fake or send: id = fake or send try: ei = ElectionInstance.objects.get(pk=id) except: print "Election Instance not found" return False if ei.modules.filter(slug='SMS').count() == 0 or ei.visitor_results.filter(sent__isnull=True).count() == 0: print "Nothing to do" return False if accepte_credit > 0: recipients = ei.visitor_results.filter(sent__isnull=True).distinct('telephone').filter(telephone__isnull=False).values_list('telephone', flat=True) recipients = list(set(recipients)) if send: for r in recipients: sendsms('Wiekiesjij', [r], 'Vandaag: Tweede Kamerverkiezingen! U kunt stemmen in ieder stemlokaal (binnen uw eigen gemeente). Vergeet uw stempas en ID-bewijs niet!', datetime.now()) ei.visitor_results.update(sent=datetime.now()) accepte_credit = accepte_credit - len(recipients) elif fake: print "Would send %s messages for the election instance" % (len(recipients)) else: print "Not enough credits" return False return True
def handle(self, *args, **options): list_events = options.get('list') send = options.get('send') fake = options.get('fake') accepte_credit = get_credit() if list_events: for event in CouncilEvent.objects.filter( sent_datetime__isnull=True).all(): print '%s - %s for %s' % (event.pk, event.title, event.council) return True if fake or send: id = fake or send try: event = CouncilEvent.objects.get(pk=id) except: print "Event not found" return False if event.sent_datetime == None: if accepte_credit > 0: recipients = event.sms_recipients() if send: for r in recipients: sendsms(event.originator, [r], event.message, datetime.now()) event.sent_datetime = datetime.now() event.save() accepte_credit = accepte_credit - len(recipients) elif fake: print "Would send %s messages for the event" % ( len(recipients)) else: print "Not enough credits" return False return True
def handle(self, *args, **options): list_events = options.get('list') send = options.get('send') fake = options.get('fake') accepte_credit = get_credit() if list_events: for event in CouncilEvent.objects.filter(sent_datetime__isnull=True).all(): print '%s - %s for %s' % (event.pk, event.title, event.council) return True if fake or send: id = fake or send try: event = CouncilEvent.objects.get(pk=id) except: print "Event not found" return False if event.sent_datetime == None: if accepte_credit > 0: recipients = event.sms_recipients() if send: for r in recipients: sendsms(event.originator, [r], event.message, datetime.now()) event.sent_datetime = datetime.now() event.save() accepte_credit = accepte_credit - len(recipients) elif fake: print "Would send %s messages for the event" % (len(recipients)) else: print "Not enough credits" return False return True