def list_campaigns(request): params = request.GET if params.get('apikey') is not None: m = MailchimpManager(params.get('apikey')) result = m.get_campaigns(None,None) logger.debug(result) return HttpResponse(json.dumps(result), content_type='application/json')
def get_campaigns_over_time(self, project, start, end): """ Return a list of highchart flags tuples ({x, title, text}) representing the mailchimp campaigns available for token in project. """ mc_man = MailchimpManager(project.mailchimp_api_token) json = mc_man.get_campaigns(start, end, project.mailchimp_list_id) result = [] for item in json.get('data'): if(item.get('status') == 'sent'): dt = parser.parse(item.get('send_time')) result.append({'x':util.unix_time_millis(dt), 'title': 'M', 'text': u'Mailchimp campaign verstuurd: {}'.format(item.get('title'))}) # sort the array of dicts by the value of x newlist = sorted(result, key=itemgetter('x')) return newlist