Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/fspmarshall/scrape-util into…
Browse files Browse the repository at this point in the history
… dev
  • Loading branch information
fourthetrees committed Jul 11, 2017
2 parents 35b717f + f789b82 commit 1f6fc84
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/acquire/parsers/occupant_query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python3
from src.core.data_utils import Row
import csv


REQUIRE = []


# primary entry point of this parser.
def parse(project,config,state,filepath):
rawdata = read_csv(filepath)
rows = reformat_data(config,rawdata)
return state,rows

# reformat the data into `Row` objects.
def reformat_data(config,raw):
if not raw: return
for r in raw: print(len(r))
fields = ['url','survey','question','option','timestamp']
if raw[0] == fields:
raw = raw[1:]
if not raw: return
toint = lambda r: [elem for elem in map(int,r)]
torow = lambda r: Row(r[0],r[1],r[2],r[4],r[3])
mkrow = lambda r: torow(toint(r))
rows = [mkrow(r) for r in raw]
return rows

# because who doesn't like reading CSVs?
def read_csv(filename):
with open(filename) as fp:
reader = csv.reader(fp)
rows = [r for r in reader if r]
return rows

0 comments on commit 1f6fc84

Please sign in to comment.