Examples of NYSenateClient


Examples of gov.nysenate.services.NYSenateClient

    public void execute(CommandLine opts) throws IOException, XmlRpcException
    {
        String apiKey = Application.getConfig().getValue("nysenate.apiKey");
        String apiDomain = Application.getConfig().getValue("nysenate.apiDomain");
        NYSenateClient client = new MemoryCachedNYSenateClient(apiDomain, apiKey);

        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(Feature.INDENT_OUTPUT, true);


        File baseDir = new File("/home/graylinkim/projects/nysenate/OpenLegislation/src/main/resources/data/");
        String sessionYear = String.valueOf(SessionYear.getSessionYear());


        if (opts.hasOption("committees") || opts.hasOption("all")) {
            File committeesDir = new File(baseDir, "committees");
            File currentCommitteesDir = new File(committeesDir, sessionYear);
            FileUtils.forceMkdir(currentCommitteesDir);

            List<Committee> committees = client.getStandingCommittees();
            for (Committee committee : committees) {
                // Fix senator shortNames.
                @SuppressWarnings("unchecked")
                List<Member> members = ListUtils.union(committee.getChairs(), committee.getMembers());
                for(Member member : members) {
                    member.setShortName(getSenatorKey(member.getName()));
                }

                // Remove all but the first listed chair, remove that chair from member listings.
                if (!committee.getChairs().isEmpty()) {
                    Member chair = committee.getChairs().get(0);
                    committee.setChairs(new ArrayList<Member>(Arrays.asList(new Member[]{chair})));
                    committee.getMembers().remove(chair);
                }

                String filename = committee.getName().replaceAll("[',.-]", "").replaceAll(" ", "_").toLowerCase()+".json";
                File committeeFile = new File(currentCommitteesDir, filename);
                mapper.writeValue(committeeFile, committee);
            }

        }

        if (opts.hasOption("senators") || opts.hasOption("all")) {
            File senatorsDir = new File(baseDir, "senators");
            File currentSenatorsDir = new File(senatorsDir, sessionYear);
            FileUtils.forceMkdir(currentSenatorsDir);

            List<Senator> senators =  client.getSenators();
            for (Senator senator : senators) {
                senator.setShortName(getSenatorKey(senator.getName()));
                File senatorFile = new File(currentSenatorsDir, senator.getDistrict().getNumber()+".json");
                System.out.println("Writing "+senator.getName()+" ["+senator.getShortName()+"] to "+senatorFile.getAbsolutePath());
                mapper.writeValue(senatorFile, senator);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.