예제 #1
0
    def run(self, mode, file_name, keys):
        # Open GCS file for writing
        gcs_file_key, gcs_file = tools.newFile("text/csv", file_name)

        si = cStringIO.StringIO()
        writer = csv.writer(si)

        for k in keys:
            try:
                e = tools.getKey(k).get()

                row_data = []

                if mode == "contacts":
                    c = e
                    row_data.append(c.name)
                    row_data.append(c.data.donation_total)
                    row_data.append(c.data.number_donations)
                    row_data.append(c.phone)
                    row_data.append(c.address[0])
                    row_data.append(c.address[1])
                    row_data.append(c.address[2])
                    row_data.append(c.address[3])
                    row_data.append(str(c.creation_date))

                    for e in c.email:
                        row_data.append(e)

                elif mode == "donations":
                    d = e
                    c = d.contact.get()
                    row_data.append(str(d.donation_date))
                    row_data.append(d.name)
                    row_data.append(d.given_email)
                    row_data.append(str(d.amount_donated))
                    row_data.append(d.payment_type)
                    row_data.append(d.designated_team)
                    row_data.append(d.designated_individual)
                    row_data.append(str(d.reviewed))
                    row_data.append(c.phone)
                    row_data.append(c.address[0])
                    row_data.append(c.address[1])
                    row_data.append(c.address[2])
                    row_data.append(c.address[3])

                elif mode == "individuals":
                    i = e
                    row_data.append(i.name)
                    row_data.append(i.email)
                    row_data.append(i.data.readable_team_names)
                    row_data.append(str(i.data.donation_total))
                    row_data.append(str(i.creation_date))

                writer.writerow(row_data)

            except Exception, e:
                logging.error("Failed on key " + k + " because " + str(e))

            # Call the garbage handler
            gc.collect()
예제 #2
0
    def post(self):
        target_year = int(self.request.get("year"))
        s = tools.getKey(self.request.get("skey"))
        mode = self.request.get("mode")

        td1 = datetime(target_year, 1, 1, 0, 0)
        td2 = datetime(target_year, 12, 31, 0, 0)

        annual_donations = models.Donation.query(models.Donation.settings == s,
                                                 models.Donation.donation_date >= td1,
                                                 models.Donation.donation_date <= td2)

        all_contacts = set([d.contact for d in annual_donations])

        with_email = []
        without_email = []
        missing_contacts = []

        for c_key in all_contacts:
            c = c_key.get()
            if not c:
                missing_contacts.append(c_key)

            else:

                if c.email != ['']:
                    with_email.append(c)

                else:
                    donation_total = c.data.donation_total
                    if donation_total >= tools.toDecimal("250"):
                        without_email.append(c)

                    elif c.data.number_donations == 1 and donation_total >= tools.toDecimal("100"):
                        without_email.append(c)

        body = ""

        body += "\n" + "#### " + str(len(with_email)) + " Donors with Email Addresses ####"
        for c in with_email:
            body += "\n" + c.websafe

        body += "\n" + "\n\n\n#### " + str(len(without_email)) + " Donors WITHOUT Email Addresses ####"
        for c in without_email:
            body += "\n" + "https://ghidonations.appspot.com/reports/donor?c=" + c.websafe + "&y=2013"

        body += "\n" + "\n\n\n#### " + str(len(missing_contacts)) + " Missing Contacts ####"
        for c in missing_contacts:
            body += "\n" + str(c)

        # Writing text file
        gcs_file_key, gcs_file = tools.newFile("text/plain", "GHI_Donations_" + str(target_year) + ".txt")
        gcs_file.write(body)
        gcs_file.close()
예제 #3
0
    def run(self, mode, file_name):
        # Open GCS file for writing
        gcs_file_key, gcs_file = tools.newFile("text/csv", file_name)

        si = cStringIO.StringIO()
        writer = csv.writer(si)

        # Write headers
        header_data = []

        if mode == "contacts":
            header_data.append("Name")
            header_data.append("Total Donated")
            header_data.append("Number Donations")
            header_data.append("Phone")
            header_data.append("Street")
            header_data.append("City")
            header_data.append("State")
            header_data.append("Zipcode")
            header_data.append("Created")
            header_data.append("Email")

        if mode == "donations":
            header_data.append("Date")
            header_data.append("Name")
            header_data.append("Email")
            header_data.append("Amount Donated")
            header_data.append("Payment Type")
            header_data.append("Team")
            header_data.append("Individual")
            header_data.append("Reviewed")
            header_data.append("Phone")
            header_data.append("Street")
            header_data.append("City")
            header_data.append("State")
            header_data.append("Zipcode")

        elif mode == "individuals":
            header_data.append("Name")
            header_data.append("Email")
            header_data.append("Teams")
            header_data.append("Raised")
            header_data.append("Date Created")

        writer.writerow(header_data)

        gcs_file.write(si.getvalue())
        gcs_file.close()

        taskqueue.add(url="/tasks/deletespreadsheet", params={'k': gcs_file_key}, countdown=1800,
                      queue_name="deletespreadsheet")

        return gcs_file_key
예제 #4
0
    def run(self, job_id, file_name, *blobs):
        gcs_writer_key, gcs_writer = tools.newFile("text/csv", file_name)

        for b in blobs:
            gcs_reader = gcs.open(b)
            data = gcs_reader.read()

            gcs_writer.write(data)

            # Call the garbage handler
            gc.collect()

        gcs_writer.close()
        taskqueue.add(url="/tasks/deletespreadsheet", params={'k': gcs_writer_key}, countdown=1800,
                      queue_name="deletespreadsheet")

        return gcs_writer_key