コード例 #1
0
ファイル: views.py プロジェクト: haikezegwaard/buzzart
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')
コード例 #2
0
ファイル: statsservice.py プロジェクト: haikezegwaard/buzzart
 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
コード例 #3
0
ファイル: statsservice.py プロジェクト: haikezegwaard/buzzart
 def get_list_stats(self, project):
     """
     Return list stats for list specified in project
     (opt ins, existing, imports per month) formatted for use in Cyfe plot
     example js series:
     series: [{
         name: 'John',
         data: [5, 3, 4, 7, 2]
     }, {
         name: 'Jane',
         data: [2, 2, 3, 2, 1]
     }, {
         name: 'Joe',
         data: [3, 4, 4, 2, 5]
     }]
     """
     mc_man = MailchimpManager(project.mailchimp_api_token)
     list_growth = mc_man.get_list_growth_data(project.mailchimp_list_id)
     optins = {'name':'optins'}
     optins['data'] = []
     existing = {'name':'existing'}
     existing['data'] = []
     imports = {'name':'imports'}
     imports['data'] = []
     months = {'name' : 'months'}
     months['data'] = []
     for item in list_growth:
             optins['data'].append(item.get('optins'))
             existing['data'].append(item.get('existing'))
             imports['data'].append(item.get('imports'))
             months['data'].append(item.get('month'))
     result = []
     result.append(optins)
     result.append(existing)
     result.append(imports)
     result.append(months)
     return result
コード例 #4
0
ファイル: views.py プロジェクト: haikezegwaard/buzzart
def list_overview(request, project_id):
    '''
    Fetch list growth data of project's Mailchimp list.
    Convert the data to Highchart stacked column chart format:
    
        [{
            name: 'imports',
            data: [5, 3, 4, 7, 2]
        }, {
            name: 'existing',
            data: [2, 2, 3, 2, 1]
        }, {
            name: 'optins',
            data: [3, 4, 4, 2, 5]
        }]
    Timerange (months) are returned as 'categories' dict.
    '''
    project = Project.objects.get(id=project_id)
    manager = MailchimpManager(project.mailchimp_api_token)
    data = manager.get_list_growth_data(project.mailchimp_list_id)
    months = []
    existing = []
    optins = []
    imports = []
    result = []
    for item in data:
        months.append(item['month'])
        existing.append(int(item['existing']))
        imports.append(int(item['imports']))
        optins.append(int(item['optins']))
    result.append({'categories' : months})
    series = []
    series.append({'name': 'existing', 'data': existing})
    series.append({'name': 'imports', 'data': imports})
    series.append({'name': 'optins', 'data': optins})
    result.append({'series': series})
    return HttpResponse(json.dumps(result), content_type='application/json')
コード例 #5
0
ファイル: statsservice.py プロジェクト: haikezegwaard/buzzart
 def get_list_overview(self, project):
     mc_man = MailchimpManager(project.mailchimp_api_token)
     list_growth = mc_man.get_list_growth_data(project.mailchimp_list_id)
     return list_growth
コード例 #6
0
ファイル: views.py プロジェクト: haikezegwaard/SAM20
def index(request):
    m = MailchimpManager("8e7536a78b89a35edfa0122d2e417186-us1")

    list_growth = m.get_list_growth_data("23c3cfb062")

    return render_to_response("list.html", {"list_growth": list_growth}, context_instance=RequestContext(request))