@@ -0,0 +1,2206 @@
+import csv%0A%0A%0Afrom datetime import timedelta,date%0A%0A#from dateutil.parser import parse as dateparse%0A%0Afrom fec_alerts.models import WebK%0Afrom summary_data.models import Candidate_Overlay%0Afrom parsing.form_parser import form_parser, ParserMissingError%0A%0A%0ACYCLE = '2014'%0Athis_cycle_start = date(2013,1,1)%0Aone_day = timedelta(days=1)%0A%0A%0Adef write_webk_csv(webk_list, file_name):%0A    %22%22%22Given a queryset of webks, write a csv file%22%22%22%0A    outfile = open(file_name, 'w')%0A    field_list = %5B'can_id','com_id','com_nam','fil_fre','fec_ele_yea','com_typ','com_des','coverage_from_date','coverage_through_date','tot_dis','tot_loa','tot_rec','cas_on_han_clo_of_per','par_com_con','oth_com_con','tra_fro_oth_aut_com','ind_ite_con','ind_uni_con','can_con','can_loa','oth_loa'%5D%0A    header = ''%0A    for i in field_list:%0A        header = header + i + %22, %22%0A    outfile.write(header + %22%5Cn%22)%0A    csvwriter = csv.DictWriter(outfile, field_list, restval='', extrasaction='ignore')%0A    # calling values on this--dunno about efficiency. %0A    for this_webk in webk_list.values():%0A        csvwriter.writerow(this_webk)%0A%0A%0Adef summarize_committee_periodic(committee_id, fp=None):%0A%0A    if not fp:%0A        fp = form_parser()%0A    %0A    %0A    %0A    relevant_webks = WebK.objects.filter(com_id=committee_id, cycle=CYCLE).order_by('cov_sta_dat')%0A    if not relevant_webks:%0A        print %22No webks found for id %25s%22 %25 (committee_id)%0A    %0A    # check gaps%0A    last_end_date = None%0A    gap_list = %5B%5D%0A    for i, wk in enumerate(relevant_webks):%0A        print i, wk.coverage_from_date, wk.coverage_through_date%0A        %0A        if i==0:%0A            if wk.coverage_from_date - this_cycle_start %3E one_day:%0A                print %22Missing coverage from start of cycle!!%22%0A                gap_list.append(%7B%22gap_start%22:this_cycle_start, %22gap_end%22:wk.coverage_from_date%7D)%0A        %0A        if i%3E0:%0A            difference = wk.coverage_from_date - last_end_date%0A            if difference %3E one_day:%0A                print %22gap found!%22%0A                gap_list.append(%7B%22gap_start%22:last_end_date, %22gap_end%22:wk.coverage_from_date%7D)%0A                %0A        %0A        %0A        last_end_date = wk.coverage_through_date%0A    %0A    for gap in gap_list:%0A        print gap%0A    

add partially done summary bit