Created
May 19, 2016 13:48
-
-
Save townie/e7cbb89c6cc59cc735d7a0ef7a1c7071 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 | |
# csv_parser.py - read csv check if shit is present | |
# Usage: | |
# python csv_parser.py <file.csv> | |
# CONFIGURE THESE 2 value | |
# postion_of_cig = 2 | |
# value_of_cig_in_string = '1' | |
# | |
# | |
import sys | |
import csv | |
# get csv | |
file = sys.argv[1] | |
data = [] | |
# open csv and read it into a list of lists | |
with open(file, 'rb') as csvfile: | |
csvreader = csv.reader(csvfile, delimiter=' ', quotechar='|') | |
for row in csvreader: | |
data.append(row[0].split(',')) | |
# get rid of csv headers | |
data.pop(0) | |
# change this to fit your data set | |
# @chelsea, remember stuff in 0 indexed into python lists | |
postion_of_cig = 2 | |
value_of_cig_in_string = '1' | |
last_six_seen_memebers = [] | |
for row in data: | |
# does current row match the cig thing | |
if row[postion_of_cig] == value_of_cig_in_string: | |
# check chace to see if it has been seen before in the last 6 | |
for last_seen in last_six_seen_memebers: | |
if last_seen[postion_of_cig] == value_of_cig_in_string: | |
print "seen" + str(row) | |
# update the cache of recently seen and remove oldest if bigger than 6 | |
last_six_seen_memebers.append(row) | |
if len(last_six_seen_memebers) > 6: | |
last_six_seen_memebers.pop(0) | |
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
h1 | h2 | cig | |
---|---|---|---|
k | webber | 1 | |
c | webber | 2 | |
j | webber | 2 | |
a | chapman | 2 | |
b | webber | 2 | |
c | chapman | 2 | |
d | webber | 2 | |
e | chapman | 1 | |
d | webber | 2 | |
bb | chapman | 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment