def handle(self, *args, **options): files = PDF_File.objects.all() efficient_query_for_ids = """select scraper_pdf_file.id from scraper_pdf_file left join fccpublicfiles_politicalbuy on scraper_pdf_file.id = fccpublicfiles_politicalbuy."related_FCC_file_id" where fccpublicfiles_politicalbuy."related_FCC_file_id" is null;""" c.execute(efficient_query_for_ids) results = c.fetchall() for count, result in enumerate(results): print "%s Running load %s " % (count, result[0]) result = make_ad_buy_from_pdf_file(result[0])
def handle(self, *args, **options): files = PDF_File.objects.all() count = 0 for afile in files: count += 1 #print "%s Running load %s " % (count, afile) result = make_ad_buy_from_pdf_file(afile)
def handle_row_data(this_data, create_new_ads): #print this_data # does it exist as a pdf file? pdffile = None adbuy = None fac_id = None if this_data['raw_url']: fcc_id = get_fcc_id(this_data['raw_url']) fac_id, pathArray = parse_file_url(this_data['raw_url']) if fcc_id and fac_id: try: pdffile = PDF_File.objects.get(file_id=fcc_id, facility_id=fac_id) except PDF_File.DoesNotExist: if create_new_ads: print "Missing file %s -- now creating" % ( this_data['raw_url']) pdffile = enter_pdf_file(this_data) if pdffile: adbuy = make_ad_buy_from_pdf_file(pdffile.pk) else: print "Missing file %s -- skipping" % (this_data['raw_url']) # if we don't have the related ad buy, get it. if pdffile: try: adbuy = PoliticalBuy.objects.get(related_FCC_file=pdffile) except PoliticalBuy.DoesNotExist: # This shouldn't really happen... print "No PoliticalBuy found for ad buy %s" % (pdffile) return None if this_data['total_spent_raw']: this_data['total_spent_raw'] = clean_numeric( this_data['total_spent_raw']) for key in this_data.keys(): try: current_value = getattr(adbuy, key) except AttributeError: continue if not current_value: if this_data[key]: setattr(adbuy, key, this_data[key]) print "Setting %s %s in %s" % (key, this_data[key], adbuy) adbuy.save(auser) return None
def handle_row_data(this_data, create_new_ads): #print this_data # does it exist as a pdf file? pdffile = None adbuy = None fac_id = None if this_data['raw_url']: fcc_id = get_fcc_id(this_data['raw_url']) fac_id, pathArray = parse_file_url(this_data['raw_url']) if fcc_id and fac_id: try: pdffile = PDF_File.objects.get(file_id=fcc_id, facility_id=fac_id) except PDF_File.DoesNotExist: if create_new_ads: print "Missing file %s -- now creating" % (this_data['raw_url']) pdffile = enter_pdf_file(this_data) if pdffile: adbuy = make_ad_buy_from_pdf_file(pdffile.pk) else: print "Missing file %s -- skipping" % (this_data['raw_url']) # if we don't have the related ad buy, get it. if pdffile: try: adbuy = PoliticalBuy.objects.get(related_FCC_file=pdffile) except PoliticalBuy.DoesNotExist: # This shouldn't really happen... print "No PoliticalBuy found for ad buy %s" % (pdffile) return None if this_data['total_spent_raw']: this_data['total_spent_raw'] = clean_numeric(this_data['total_spent_raw']) for key in this_data.keys(): try: current_value = getattr(adbuy, key) except AttributeError: continue if not current_value: if this_data[key]: setattr(adbuy, key, this_data[key]) print "Setting %s %s in %s" % (key, this_data[key], adbuy) adbuy.save(auser) return None