def writeFromList(finalist): ''' Called by cbemailtoinfo2.py in creating log file and summary file for PEOPLE and COMPANIES ''' if type(finalist) != list: raise TypeError('Only lists should be fed into the writeFromList method') finalstr = '\n'.join(finalist) lilist = [] twitlist = [] fblist = [] peopleList = [] compList = [] filetitle = input('Choose a name for the log file') logfile = open(filetitle, 'w') writeSafe(finalstr, logfile) logfile.close() sumtitle = input('Choose a name for the PEOPLE summary file: ') comptitle = input('Choose a name for the COMPANIES summary file: ') sumfile = open(sumtitle, 'w') compfile = open(comptitle, 'w') sumfile.write('General Information:\n') compfile.write('General Information:\n') checkfile = open(filetitle) bigstrlower = checkfile.read().lower() checkfile.close() uniques = countUnique.numUnique(bigstrlower) licount = uniques['linkedin'] twitcount = uniques['twitter'] fbcount = uniques['facebook'] sumfile.write('Total Appearances of LinkedIn: ' + str(licount) + "\n") sumfile.write('Total Appearances of Twitter: ' + str(twitcount) + "\n") sumfile.write('Total Appearances of Facebook: ' + str(fbcount) + "\n") mylines = bigstrlower.split('\n') index = 0 email = '' compInfo = '' peopleLIs = 0 peopleFBs = 0 peopleTWs = 0 compLIs = 0 compFBs = 0 compTWs = 0 person_mode = True while index < len(mylines): line = mylines[index] if 'info for ' in line: words = line.split() email = words[-2] if line == 'person': person_mode = True if line == 'company': compInfo = email + '\n' + '\n'.join(mylines[index + 1 : mylines.index('', index)]) if compInfo != email + '\n': compList.append(compInfo + '\n') person_mode = False if line == '': email = '' compInfo = '' if 'linkedin' in line: if person_mode: peopleLIs += 1 lilist.append(email + ' : ' + line) else: compLIs += 1 if 'twitter' in line: if person_mode: peopleTWs += 1 twitlist.append(email + ' : ' + line) else: compTWs += 1 if 'facebook' in line: if person_mode: peopleFBs += 1 fblist.append(email + ' : ' + line) else: compFBs += 1 index += 1 sumfile.write('PEOPLE Appearances of LinkedIn: ' + str(peopleLIs) + '\n') sumfile.write('PEOPLE Appearances of Twitter: ' + str(peopleTWs) + '\n') sumfile.write('PEOPLE Appearances of Facebook: ' + str(peopleFBs) + '\n\n') liHeader = 'Displaying information relevant to LinkedIn:\n' sumfile.write(liHeader) peopleList.append(liHeader) liContent = '\n'.join(lilist) + '\n' writeSafe(liContent + '\n', sumfile) peopleList += lilist peopleList.append('\n') twHeader = 'Displaying information relevant to Twitter:\n' sumfile.write(twHeader) peopleList.append(twHeader) twContent = '\n'.join(twitlist) + '\n' writeSafe(twContent + '\n', sumfile) peopleList += twitlist peopleList.append('\n') fbHeader = 'Displaying information relevant to Facebook:\n' sumfile.write(fbHeader) peopleList.append(fbHeader) fbContent = '\n'.join(fblist) + '\n' writeSafe(fbContent + '\n', sumfile) peopleList += fblist peopleList.append('\n') compfile.write('Displaying information for COMPANIES:\n') compfile.write('COMPANY Appearances of LinkedIn: ' + str(compLIs) + '\n') compfile.write('COMPANY Appearances of Twitter: ' + str(compTWs) + '\n') compfile.write('COMPANY Appearances of Facebook: ' + str(compFBs) + '\n\n') compfile.write('\n\n') writeSafe('\n'.join(compList), compfile) sumfile.write('End Of PEOPLE Report\n') pplBitsWritten = sumfile.tell() sumfile.close() compfile.write('End Of COMPANIES Report\n') compBitsWritten = compfile.tell() compfile.close() #return pplBitsWritten + compBitsWritten return (peopleList, compList)
def writeFromList(finalist): if type(finalist) == str: finalist = finalist.split('\n') #print(len(finalist)) lilist = [] twitlist = [] fblist = [] filetitle = input('Choose a name for the log file') logfile = open(filetitle, 'w') for line in finalist: try: logfile.write(line + '\n') except UnicodeEncodeError: print('Hey! Some unencodable characters were encountered! This is ' + str(logfile.tell()) +' bytes into the file. The following line will have missing characters in the log:') print(line) for char in line: try: logfile.write(char) except UnicodeEncodeError: continue logfile.close() sumtitle = input('Choose a name for the summary file') sumfile = open(sumtitle, 'w') sumfile.write('General information:\n') checkfile = open(filetitle) bigstrlower = checkfile.read().lower() checkfile.close() uniques = countUnique.numUnique(bigstrlower) #licount = bigstrlower.count('linkedin') #twitcount = bigstrlower.count('twitter') #fbcount = bigstrlower.count('facebook') licount = uniques['linkedin'] twitcount = uniques['twitter'] fbcount = uniques['facebook'] sumfile.write('Appearances of "LinkedIn: "' + str(licount) + "\n") sumfile.write('Appearances of "Twitter: "' + str(twitcount) + "\n") sumfile.write('Appearances of "Facebook: "' + str(fbcount) + "\n") mylines = bigstrlower.split('\n') for line in mylines: if 'linkedin' in line: lilist.append(line) if 'twitter' in line: twitlist.append(line) if 'facebook' in line: fblist.append(line) sumfile.write('Displaying information relevant to LinkedIn:\n') for line in lilist: sumfile.write(line + '\n') sumfile.write('\n') sumfile.write('Displaying information relevant to Twitter:\n') for line in twitlist: sumfile.write(line + '\n') sumfile.write('\n') sumfile.write('Displaying information relevant to Facebook:\n') for line in fblist: sumfile.write(line + '\n') sumfile.write('\n') sumfile.write('End Of Report\n') bitswritten = sumfile.tell() sumfile.close() return bitswritten
def writeFromList(finalist): """ Called by cbemailtoinfo2.py in creating log file and summary file for PEOPLE and COMPANIES """ if type(finalist) != list: raise TypeError("Only lists should be fed into the writeFromList method") finalstr = "\n".join(finalist) lilist = [] twitlist = [] fblist = [] peopleList = [] compList = [] filetitle = input("Choose a name for the log file") logfile = open(filetitle, "w") writeSafe(finalstr, logfile) logfile.close() sumtitle = input("Choose a name for the PEOPLE summary file: ") comptitle = input("Choose a name for the COMPANIES summary file: ") sumfile = open(sumtitle, "w") compfile = open(comptitle, "w") sumfile.write("General Information:\n") compfile.write("General Information:\n") checkfile = open(filetitle) bigstrlower = checkfile.read().lower() checkfile.close() uniques = countUnique.numUnique(bigstrlower) licount = uniques["linkedin"] twitcount = uniques["twitter"] fbcount = uniques["facebook"] sumfile.write("Total Appearances of LinkedIn: " + str(licount) + "\n") sumfile.write("Total Appearances of Twitter: " + str(twitcount) + "\n") sumfile.write("Total Appearances of Facebook: " + str(fbcount) + "\n") mylines = bigstrlower.split("\n") index = 0 email = "" compInfo = "" peopleLIs = 0 peopleFBs = 0 peopleTWs = 0 compLIs = 0 compFBs = 0 compTWs = 0 person_mode = True while index < len(mylines): line = mylines[index] if "info for " in line: words = line.split() email = words[-2] if line == "person": person_mode = True if line == "company": compInfo = email + "\n" + "\n".join(mylines[index + 1 : mylines.index("", index)]) if compInfo != email + "\n": compList.append(compInfo + "\n") person_mode = False if line == "": email = "" compInfo = "" if "linkedin" in line: if person_mode: peopleLIs += 1 lilist.append(email + " : " + line) else: compLIs += 1 if "twitter" in line: if person_mode: peopleTWs += 1 twitlist.append(email + " : " + line) else: compTWs += 1 if "facebook" in line: if person_mode: peopleFBs += 1 fblist.append(email + " : " + line) else: compFBs += 1 index += 1 sumfile.write("PEOPLE Appearances of LinkedIn: " + str(peopleLIs) + "\n") sumfile.write("PEOPLE Appearances of Twitter: " + str(peopleTWs) + "\n") sumfile.write("PEOPLE Appearances of Facebook: " + str(peopleFBs) + "\n\n") liHeader = "Displaying information relevant to LinkedIn:\n" sumfile.write(liHeader) peopleList.append(liHeader) liContent = "\n".join(lilist) + "\n" writeSafe(liContent + "\n", sumfile) peopleList += lilist peopleList.append("\n") twHeader = "Displaying information relevant to Twitter:\n" sumfile.write(twHeader) peopleList.append(twHeader) twContent = "\n".join(twitlist) + "\n" writeSafe(twContent + "\n", sumfile) peopleList += twitlist peopleList.append("\n") fbHeader = "Displaying information relevant to Facebook:\n" sumfile.write(fbHeader) peopleList.append(fbHeader) fbContent = "\n".join(fblist) + "\n" writeSafe(fbContent + "\n", sumfile) peopleList += fblist peopleList.append("\n") compfile.write("Displaying information for COMPANIES:\n") compfile.write("COMPANY Appearances of LinkedIn: " + str(compLIs) + "\n") compfile.write("COMPANY Appearances of Twitter: " + str(compTWs) + "\n") compfile.write("COMPANY Appearances of Facebook: " + str(compFBs) + "\n\n") compfile.write("\n\n") writeSafe("\n".join(compList), compfile) sumfile.write("End Of PEOPLE Report\n") pplBitsWritten = sumfile.tell() sumfile.close() compfile.write("End Of COMPANIES Report\n") compBitsWritten = compfile.tell() compfile.close() # return pplBitsWritten + compBitsWritten return (peopleList, compList)