Created
January 18, 2018 19:19
-
-
Save MikeiLL/63c1bdd8a54f0bc63041033532ed4116 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
""" | |
Compare two small csv files and create two new files, one with matches, the other which don't match. | |
I use it here to to get the names and email addresses from "personal" FB friends which are in a specific group. | |
It loops the group and pulls matches from the friends list, so that only group members whom are also found in the | |
friends list will be included in the GroupFriends list. | |
A hipper, more efficient approach is found here: https://stackoverflow.com/a/23090697/2223106 | |
""" | |
import csv | |
f1 = file('FBGroupMembers.csv', 'r') | |
f2 = file('FBFriends.csv', 'r') | |
f3 = file('GroupFriends.csv', 'w') | |
f4 = file('GroupNonFriends.csv', 'w') | |
group_reader = csv.reader(f1) | |
friends_reader = csv.reader(f2) | |
crosssection_writer = csv.writer(f3) | |
non_match_writer = csv.writer(f4) | |
friend_list = list(friends_reader) | |
for group_row in group_reader: | |
row = 1 | |
found = False | |
for friends_row in friend_list: | |
results_row = group_row | |
if friends_row[0].lower() == group_row[1].lower() or friends_row[3].lower() == group_row[2].lower(): | |
friends_row[0] = friends_row[0].title() | |
friends_row[3] = friends_row[3].title() | |
print(friends_row[0] +'\t'+friends_row[3]+' found.') | |
crosssection_writer.writerow(friends_row) | |
found = True | |
break | |
row = row + 1 | |
if not found: | |
results_row.append('NOT FOUND in master list') | |
non_match_writer.writerow(group_row) | |
f1.close() | |
f2.close() | |
f3.close() | |
f4.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment