##Take raw data and extract higher level features using functions in metrics import utils import itertools from metrics import similarityMatrix searches = [[112],['house','senate']] for search in itertools.product(*searches): congress = str(search[0]) chamber = search[1] voteData = utils.readDict('votes-'+congress+chamber) similarities = similarityMatrix(voteData) utils.writeDict({'sims':similarities,'people':people},'similarities-'+congress+chamber)
select = input( "press 0: exit this process\npress 1: enter an URL to parse a recipe\n\ press 2: do transformation\npress 3: show old recipe(you can also find the old recipe in ./output/parserOutput.json)\npress 4: show new recipe(to see the complete new recipe of last transformation)(you can also find the new recipe in ./output/newRecipeOutput.json)\n" ) if select == '1': url = str( input("please enter an URL from allrecipe\n\ (default:https://www.allrecipes.com/recipe/232458/pork-chops-with-creamy-scalloped-potatoes/)\n" )) if len(url.strip()) == 0: url = 'https://www.allrecipes.com/recipe/232458/pork-chops-with-creamy-scalloped-potatoes/' test = parser.parser(url, resPath) test.parserIngredient() test.parserDirection() utils.printDict(utils.recipeAddNumber(test.res)) utils.writeDict(utils.recipeAddNumber(test.res), resPath) utils.printRecipeNL(test.res) elif select == '2': if url == None: print( "you need to press 1 to enter an URL to parser an recipe first" ) continue transfromtest = transfrom.transform(test.res) tran = input("press 0: exit this process\n\ press 1: change recipe to Vegetarian\n\ press 2: change recipe to Non-Vegetarian\n\ press 3: change recipe to Healthy recipe\n\ press 4: change recipe to Non-healthy recipe\n\ press 5: change recipe to Mexican recipe\n\
for member in members: voteData[member.find('id').text] = [] #Go through each rollcall of each session and record votes for session in ['1','2']: rollcallPath = 'data/raw/'+chamber+'/'+congress+'/'+session+'/rollcall' for fileList in os.walk(rollcallPath): for rollCall in fileList[2]: votes = ET.parse(rollcallPath+'/'+rollCall).getroot().find('results').find('votes').find('vote').find('positions').findall('position') for vote in votes: position = vote.find('vote_position').text memberId = vote.find('member_id').text if lookup.has_key(position): voteData[memberId].append(lookup[position]) else: voteData[memberId].append(-1) utils.writeDict(voteData,'votes-'+congress+chamber) last100 = """ for search in itertools.product(*searches): voteData = {} congress = str(search[0]) chamber = search[1] rootPath = 'data/'+chamber+'/'+congress members = ET.parse(rootPath+'/members.xml').getroot().find('results').find('members').findall('member') for member in members: member_id = member.find('id').text print member_id votes = ET.parse(rootPath+'/members/'+member_id+'/votes.xml').getroot().find('results').find('votes').findall('vote') voteList = map(lambda v: lookup[v.find('position').text], votes) voteData[member_id] = voteList utils.writeDict(voteData,'votes-'+congress+chamber)