def csv_Send_To_House(csvfile='demo-dataz.csv', messagefile="noCispaMessage.txt", statfile='csv_Send_To_House.log', dryrun=False, onedistrict=None):
    '''
    Parse from the csv file

    '''
    writeYourRep = WriteYourRep()
    reader = csv.DictReader(open(csvfile, 'rb'))
    genderassigner = GenderLookup()

    (subject, message) = parseMessageFile(messagefile)
    for row in reader:
        state='unknown'
        status = ""
        try:
            i = csv_To_Data(row, writeYourRep, genderassigner, subject, message)
            if onedistrict!=None:
                print "Feature of specifying one district is not supported yet"
                return
            if dryrun:
            	distListStr=' '.join(writeYourRep.getWyrDistricts(i.zip5))
            	status += distListStr + " " + ": Not attempted with "+ i.__str__()+"\n"
            else:
                q = writeYourRep.writerep(i)
                status += writeYourRep.getStatus(q) +", "
        except Exception, e:
            import traceback; traceback.print_exc()
            status=status + ' failed: ' + e.__str__()
        file(statfile, 'a').write('%s %s, %s, "%s"\n' % (i.fname, i.lname, i.state, status))
Esempio n. 2
0
def csv_Send_To_House(csvfile='demo-dataz.csv', messagefile="noCispaMessage.txt", statfile='csv_Send_To_House.log', dryrun=False, onedistrict=None, jsoninput=False):
    '''
    Parse from the csv file

    '''
    writeYourRep = WriteYourRep()
    if not jsoninput:  # default is csv    
        reader = csv.DictReader(open(csvfile, 'rb'), delimiter='\t')
    else:
        try:
            reader = json.load(open(csvfile, 'r'))
        except:
            reader = load_json(csvfile)
    genderassigner = GenderLookup()
    (subject, message) = parseMessageFile(messagefile)

    for row in reader:
        i = None
        state='unknown'
        status = ""
        try:
            i = row_dict_to_data(row, writeYourRep, genderassigner, subject, message)
            if onedistrict!=None:
                if DEBUG: print "Feature of specifying one district is not supported yet"
                return
            if dryrun:
            	distListStr=' '.join(writeYourRep.getWyrDistricts(i.zip5))
            	status += distListStr + " " + ": Not attempted with "+ i.__str__()+"\n"
            else:
                q = writeYourRep.writerep(i)
                status += i.dist + ": "
                status += writeYourRep.getStatus(q)
        except Exception, e:
            traceback.print_exc()
            status=status + ' failed: ' + e.__str__()
        if i is not None:
            file(statfile, 'a').write('%s %s, %s, "%s"\n' % (i.fname.encode('utf-8', 'ignore'), i.lname.encode('utf-8', 'ignore'), i.state, status))
def csv_Send_To_House(csvfile='demo-dataz.csv',
                      messagefile="noCispaMessage.txt",
                      statfile='csv_Send_To_House.log',
                      dryrun=False,
                      onedistrict=None):
    '''
    Parse from the csv file

    '''
    writeYourRep = WriteYourRep()
    reader = csv.DictReader(open(csvfile, 'rb'))
    genderassigner = GenderLookup()

    (subject, message) = parseMessageFile(messagefile)
    for row in reader:
        state = 'unknown'
        status = ""
        try:
            i = csv_To_Data(row, writeYourRep, genderassigner, subject,
                            message)
            if onedistrict != None:
                print "Feature of specifying one district is not supported yet"
                return
            if dryrun:
                distListStr = ' '.join(writeYourRep.getWyrDistricts(i.zip5))
                status += distListStr + " " + ": Not attempted with " + i.__str__(
                ) + "\n"
            else:
                q = writeYourRep.writerep(i)
                status += writeYourRep.getStatus(q) + ", "
        except Exception, e:
            import traceback
            traceback.print_exc()
            status = status + ' failed: ' + e.__str__()
        file(statfile, 'a').write('%s %s, %s, "%s"\n' %
                                  (i.fname, i.lname, i.state, status))
def csv_Send_To_House(csvfile='demo-dataz.csv', messagefile="noCispaMessage.txt", statfile='csv_Send_To_Senate.log', dryrun=False):
    '''
    Parse from the csv file

    '''
    import csv
    from ZipLookup import ZipLookup
    from GenderLookup import GenderLookup
    writeYourRep = WriteYourRep()
    reader = csv.reader(open(csvfile, 'rb'))
    genderassigner = GenderLookup()

    (subject, message) = parseMessageFile(messagefile)
    zipLookup = ZipLookup()
    for row in reader:
        state='unknown'
        status = ""
        try:
            #First_Name,Email,Street,Zip
            (first_name, email, addr1, zip5) = row
            last_name = ""
            addr2=""
            zip4 = None
            (first_name, last_name) = cleanName(first_name, last_name)
            if zip5.find('-')>0:
                zip4 = zip5.split('-')[1]
                zip5 = zip5.split('-')[0]            
            (first_name, last_name) = cleanName(first_name, last_name)
            zip5=zip5.zfill(5)
            (city, state) = zipLookup.getCityAndState(zip5)
            #print "found city and state: %s, %s" % (city, state)
            i = writeYourRep.prepare_i(state+"_" + "XX") #hack, need dist for prepare_i
            if email:
                #print email
                i.email=email
            if first_name:
                # this code below was used when a single name field was given
                # and not separate first and last name fields
                #names = name.split()
                #i.fname = "".join(iter(names[0:len(names)-1]))
                #i.lname = names[-1]
                i.fname = first_name
                i.lname = last_name
                i.prefix = genderassigner.getPrefix(i.fname)
                i.id = "%s %s" % (first_name, last_name)
            if addr1:
                i.addr1 = addr1
                i.addr2 = addr2
            if zip5:
                i.zip5 = zip5
                i.zip4 = '0001'
            if zip4:
                i.zip4 = zip4
            if city:
                i.city = city
            if message:
                i.full_msg = message
            if subject:
                i.subject = subject

            if dryrun:
                print "getting link for i:", i.addr1, i.addr2
            	contactLink=writeYourRep.getWyrContactLink(i)
            	status += contactLink + " " + ": Not attempted with "+ i.__str__()+"\n"
            else:
                q = writeYourRep.writerep(i)
                status += writeYourRep.getStatus(q) +", "
        except Exception, e:
            import traceback; traceback.print_exc()
            status=status + ' failed: ' + e.__str__()
        file(statfile, 'a').write('%s %s, %s, "%s"\n' % (first_name, last_name, state, status))
Esempio n. 5
0
def housetest(distToEmail=None):
    '''
    Test every house form, or just check the particular distToEmail form.
    Todo: add the check-by-eye option
    '''
    broken = set(['AR-01','AZ-05','AZ-07','CA-21','CA-25','CA-30','CA-34','CA-44','CA-49','FL-12','FL-14','FL-17','IA-05','IL-16','IN-05','MI-14','MT-00','NC-03','NC-10','NJ-04','NJ-11','NY-20','NY-23','OH-14','OH-15','SC-01','SC-05','SD-00','TN-07','TX-23','TX-24','TX-32','UT-02','WI-05',])

    # 38 judiciary members
    judiciary=set(['TX-21', 'WI-05', 'NC-06', 'CA-24', 'VA-06', 'CA-03', 'OH-01',  'IN-06', 'VA-04', 'IA-05', 'AZ-02', 'TX-01', 'OH-04', 'TX-02', 'UT-03', 'AR-02', 'PA-10', 'SC-04', 'FL-12', 'FL-24', 'AZ-03', 'NV-02', 'MI-14', 'CA-28', 'NY-08', 'VA-03', 'NC-12', 'CA-16', 'TX-18', 'CA-35', 'TN-09', 'GA-04', 'PR-00', 'IL-05', 'CA-32', 'FL-19', 'CA-39'])

    allCaptcha =set(['CA-44', 'CA-49', 'TX-32', 'IN-05', 'NC-03', 'MI-14', 'CA-21', 'FL-14'])


    # judiciary members with captchas
    judCaptcha=set(['CA-49', 'MI-14' ])

    #n = set()
    #n.update(correction);
    #n.update(err);

    # Speed up test.
    # To check the return pages using pattern matching
    # rather than by eye, set this flag to false
    checkByEye=False
    
    fh = file('results.log', 'a')
    writeYourRep = WriteYourRep()
    for dist in sorted(dist_zip_dict.keys()):
        #if dist not in allCaptcha: continue     
        #if dist not in broken: continue
        #if dist in h_working or dist in n: continue
        #if dist not in judiciary: continue
        if distToEmail and dist != distToEmail: continue
        print "\n------------\n", dist,"\n"
        q=None
        try:
            q = writeYourRep.writerep(writeYourRep.prepare_i(dist))
            errorString = None
            if checkByEye:
                subprocess.Popen(['open', 'house/%s.html' % dist])
                print
                result = raw_input('%s? ' % dist)
            else:
                confirmations=[cstr for cstr in confirmationStrings if cstr in q.lower()]
                if len(confirmations) > 0:
                    result='thanked'
                else:
                    result = 'err'
                    
            errorString = getError(q)
            print "ErrorString: ", errorString

            print result + '.add(%s)' % repr(dist)

            if not errorString:
                fh.write('%s.add(%s)\n' % (result, repr(dist)))
            else:
                #if thanked, but still have error, we assume we have an error (see FL-14 for example)
                result = 'err'
                fh.write('%s.add(%s) %s\n' % (result, repr(dist), errorString))

        except Exception, detail:
            #print "DETAIL: ", detail
            q=detail.__str__()
            errorString = detail.__str__()
            import traceback; traceback.print_exc()
            print 'err.add(%s)' % (repr(dist))
            fh.write('%s.add(%s) %s\n' % ('err', repr(dist),errorString))          
        fh.flush()
        if q:
            file('house/%s.html' % dist, 'w').write(q)    
Esempio n. 6
0
def housetest(distToEmail=None):
    """
    Test every house form, or just check the particular distToEmail form.
    Todo: add the check-by-eye option
    """
    broken = set(
        [
            "AR-01",
            "AZ-05",
            "AZ-07",
            "CA-21",
            "CA-25",
            "CA-30",
            "CA-34",
            "CA-44",
            "CA-49",
            "FL-12",
            "FL-14",
            "FL-17",
            "IA-05",
            "IL-16",
            "IN-05",
            "MI-14",
            "MT-00",
            "NC-03",
            "NC-10",
            "NJ-04",
            "NJ-11",
            "NY-20",
            "NY-23",
            "OH-14",
            "OH-15",
            "SC-01",
            "SC-05",
            "SD-00",
            "TN-07",
            "TX-23",
            "TX-24",
            "TX-32",
            "UT-02",
            "WI-05",
        ]
    )

    # 38 judiciary members
    judiciary = set(
        [
            "TX-21",
            "WI-05",
            "NC-06",
            "CA-24",
            "VA-06",
            "CA-03",
            "OH-01",
            "IN-06",
            "VA-04",
            "IA-05",
            "AZ-02",
            "TX-01",
            "OH-04",
            "TX-02",
            "UT-03",
            "AR-02",
            "PA-10",
            "SC-04",
            "FL-12",
            "FL-24",
            "AZ-03",
            "NV-02",
            "MI-14",
            "CA-28",
            "NY-08",
            "VA-03",
            "NC-12",
            "CA-16",
            "TX-18",
            "CA-35",
            "TN-09",
            "GA-04",
            "PR-00",
            "IL-05",
            "CA-32",
            "FL-19",
            "CA-39",
        ]
    )

    allCaptcha = set(["CA-44", "CA-49", "TX-32", "IN-05", "NC-03", "MI-14", "CA-21", "FL-14"])

    # judiciary members with captchas
    judCaptcha = set(["CA-49", "MI-14"])

    # n = set()
    # n.update(correction);
    # n.update(err);

    # Speed up test.
    # To check the return pages using pattern matching
    # rather than by eye, set this flag to false
    checkByEye = False

    fh = file("results.log", "a")
    writeYourRep = WriteYourRep()
    for dist in sorted(dist_zip_dict.keys()):
        # if dist not in allCaptcha: continue
        # if dist not in broken: continue
        # if dist in h_working or dist in n: continue
        # if dist not in judiciary: continue
        if distToEmail and dist != distToEmail:
            continue
        print "\n------------\n", dist, "\n"
        q = None
        try:
            q = writeYourRep.writerep(writeYourRep.prepare_i(dist))
            errorString = None
            if checkByEye:
                subprocess.Popen(["open", "house/%s.html" % dist])
                print
                result = raw_input("%s? " % dist)
            else:
                confirmations = [cstr for cstr in confirmationStrings if cstr in q.lower()]
                if len(confirmations) > 0:
                    result = "thanked"
                else:
                    result = "err"

            errorString = getError(q)
            print "ErrorString: ", errorString

            print result + ".add(%s)" % repr(dist)

            if not errorString:
                fh.write("%s.add(%s)\n" % (result, repr(dist)))
            else:
                # if thanked, but still have error, we assume we have an error (see FL-14 for example)
                result = "err"
                fh.write("%s.add(%s) %s\n" % (result, repr(dist), errorString))

        except Exception, detail:
            # print "DETAIL: ", detail
            q = detail.__str__()
            errorString = detail.__str__()
            import traceback

            traceback.print_exc()
            print "err.add(%s)" % (repr(dist))
            fh.write("%s.add(%s) %s\n" % ("err", repr(dist), errorString))
        fh.flush()
        if q:
            file("house/%s.html" % dist, "w").write(q)