Tuesday, April 30, 2013

Perl and Open Government



For any interested in initiatives to make government data more accessible, I ran across an interesting API put out by Civic Impulse – the GovTrack API (http://www.govtrack.us/developers/api).  The API allows queries to be made regarding many of the bills being debated about in the US congress as well as the ability to programmatically look up information pertaining to members of Congress.  The available documentation for the API is located at the link already provided, but a small Perl script below will demonstrate the basics of accessing the API in Perl.



This script will query the API for bills regarding “fracking” in the “112” session of congress and will simply print out the retrieved results.

#!usr/bin/perl

use LWP;
use strict;
use warnings;

#sets query and congress session
my $query='fracking';
my $congress=112;

my $ua = LWP::UserAgent->new;

my $url="http://www.govtrack.us/api/v2/bill?q=$query&congress=$congress";

my $response=$ua->get($url);
my $result=$response->content;
print $result;


The results are returned in the JSON format be default, but the API does allow for parameters to be specified for XML or CSV based results as alternatives.  For the code above the returned JSON would look as follows:

 {
 "meta": {
  "limit": 100,
  "offset": 0,
  "total_count": 2
 },
 "objects": [
  {
   "bill_resolution_type": "bill",
   "bill_type": "senate_bill",
   "bill_type_label": "S.",
   "congress": 112,
   "current_status": "referred",
   "current_status_date": "2012-03-28",
   "current_status_description": "This bill was introduced on March 28, 2012, in a previous session of Congress, but was not enacted.",
   "current_status_label": "Referred to Committee",
   "display_number": "S. 2248",
   "docs_house_gov_postdate": null,
   "id": 251518,
   "introduced_date": "2012-03-28",
   "is_alive": false,
   "is_current": false,
   "link": "http://www.govtrack.us/congress/bills/112/s2248",
   "major_actions": [
    [
     "datetime.datetime(2012, 3, 28, 0, 0)",
     1,
     "Sponsor introductory remarks on measure. (CR S2166-2167)"
    ],
    [
     "datetime.datetime(2012, 3, 28, 0, 0)",
     2,
     "Read twice and referred to the Committee on Energy and Natural Resources."
    ]
   ],
   "noun": "bill",
   "number": 2248,
   "senate_floor_schedule_postdate": null,
   "sliplawnum": null,
   "sliplawpubpriv": null,
   "sponsor": {
    "bioguideid": "I000024",
    "birthday": "1934-11-17",
    "cspanid": 5619,
    "firstname": "James",
    "gender": "male",
    "gender_label": "Male",
    "id": 300055,
    "lastname": "Inhofe",
    "link": "http://www.govtrack.us/congress/members/james_inhofe/300055",
    "middlename": "M.",
    "name": "Sen. James “Jim” Inhofe [R-OK]",
    "namemod": "",
    "nickname": "Jim",
    "osid": "N00005582",
    "pvsid": "27027",
    "sortname": "Inhofe, James “Jim” (Sen.) [R-OK]",
    "twitterid": "InhofePress",
    "youtubeid": "jiminhofepressoffice"
   },
   "sponsor_role": {
    "congress_numbers": [
     111,
     112,
     113
    ],
    "current": true,
    "description": "Senator from Oklahoma",
    "district": null,
    "enddate": "2015-01-03",
    "id": 4082,
    "party": "Republican",
    "person": 300055,
    "role_type": "senator",
    "role_type_label": "Senator",
    "senator_class": "class2",
    "senator_class_label": "Class 2",
    "startdate": "2009-01-06",
    "state": "OK",
    "title": "Sen.",
    "title_long": "Senator",
    "website": "http://www.inhofe.senate.gov"
   },
   "thomas_link": "http://thomas.loc.gov/cgi-bin/bdquery/z?d112:s2248:",
   "title": "S. 2248 (112th): Fracturing Regulations are Effective in State Hands Act",
   "title_without_number": "Fracturing Regulations are Effective in State Hands Act",
   "titles": [
    [
     "short",
     "introduced",
     "Fracturing Regulations are Effective in State Hands Act"
    ],
    [
     "official",
     "introduced",
     "A bill to clarify that a State has the sole authority to regulate hydraulic fracturing on Federal land within the boundaries of the State."
    ]
   ]
  },
  {
   "bill_resolution_type": "bill",
   "bill_type": "house_bill",
   "bill_type_label": "H.R.",
   "congress": 112,
   "current_status": "referred",
   "current_status_date": "2012-03-29",
   "current_status_description": "This bill was introduced on March 29, 2012, in a previous session of Congress, but was not enacted.",
   "current_status_label": "Referred to Committee",
   "display_number": "H.R. 4322",
   "docs_house_gov_postdate": null,
   "id": 251585,
   "introduced_date": "2012-03-29",
   "is_alive": false,
   "is_current": false,
   "link": "http://www.govtrack.us/congress/bills/112/hr4322",
   "major_actions": [
    [
     "datetime.datetime(2012, 3, 29, 0, 0)",
     2,
     "Referred to the Committee on Natural Resources, and in addition to the Committees on Agriculture, Transportation and Infrastructure, and Energy and Commerce, for a period to be subsequently determined by the Speaker, in each case for consideration of such provisions as fall within the jurisdiction of the committee concerned."
    ]
   ],
   "noun": "bill",
   "number": 4322,
   "senate_floor_schedule_postdate": null,
   "sliplawnum": null,
   "sliplawpubpriv": null,
   "sponsor": {
    "bioguideid": "G000552",
    "birthday": "1953-08-18",
    "cspanid": 1011394,
    "firstname": "Louie",
    "gender": "male",
    "gender_label": "Male",
    "id": 400651,
    "lastname": "Gohmert",
    "link": "http://www.govtrack.us/congress/members/louie_gohmert/400651",
    "middlename": "B.",
    "name": "Rep. Louie Gohmert [R-TX1]",
    "namemod": "Jr.",
    "nickname": "",
    "osid": "N00026148",
    "pvsid": "50029",
    "sortname": "Gohmert, Louie (Rep.) [R-TX1]",
    "twitterid": "replouiegohmert",
    "youtubeid": "GohmertTX01"
   },
   "sponsor_role": {
    "congress_numbers": [
     112
    ],
    "current": false,
    "description": "Representative for Texas's 1st congressional district",
    "district": 1,
    "enddate": "2013-01-03",
    "id": 5197,
    "party": "Republican",
    "person": 400651,
    "role_type": "representative",
    "role_type_label": "Representative",
    "senator_class": null,
    "startdate": "2011-01-05",
    "state": "TX",
    "title": "Rep.",
    "title_long": "Representative",
    "website": "http://gohmert.house.gov"
   },
   "thomas_link": "http://thomas.loc.gov/cgi-bin/bdquery/z?d112:hr4322:",
   "title": "H.R. 4322 (112th): Fracturing Regulations are Effective in State Hands Act",
   "title_without_number": "Fracturing Regulations are Effective in State Hands Act",
   "titles": [
    [
     "short",
     "introduced",
     "Fracturing Regulations are Effective in State Hands Act"
    ],
    [
     "official",
     "introduced",
     "To clarify that a State has the sole authority to regulate hydraulic fracturing on Federal land within the boundaries of the State."
    ]
   ]
  }
 ]
}


10 comments:

Rajesh said...

thanks for sharing this information
best data science training institute in bangalore
best data science training in bangalore
tableau classroom training in bangalore
python training in bangalore
best python training institute in bangalore
python training in jayanagar bangalore
Artificial Intelligence training in Bangalore
data science with python training in Bangalore

Suresh said...

Thanks for this blog are more informative contents step by step. I here attached my site would you see this blog

7 tips to start a career in digital marketing

“Digital marketing is the marketing of product or service using digital technologies, mainly on the Internet, but also including mobile phones, display advertising, and any other digital medium”. This is the definition that you would get when you search for the term “Digital marketing” in google. Let’s give out a simpler explanation by saying, “the form of marketing, using the internet and technologies like phones, computer etc”.

we have offered to the advanced syllabus course digital marketing for available join now.

more details click the link now.

https://www.webdschool.com/digital-marketing-course-in-chennai.html

BestTrainingMumbai said...

Your article is extremely well-written. This is great informational content from my point of view. You also make many valid points with compelling, unique content.
SAP training in Kolkata
Best SAP training in Kolkata
SAP training institute in Kolkata

Anirban Ghosh said...

I regularly wouldn't be so connected by any articles relating to this subject, yet yours caught my eye.
SAP training in Mumbai
Best SAP training in Mumbai
SAP training institute Mumbai

kalaivaanan said...
This comment has been removed by the author.
kalaivaanan said...
This comment has been removed by the author.
kalaivaanan said...

you have written an excellent blog.. keep sharing your knowledge...
Perl Training in Chennai
Perl Course in Chennai

Sarika A said...

Very interesting blog Awesome post. Your article is really informative and helpful for me and other bloggers too. We are providing the best services click on below links to visit our website.
Oracle Fusion HCM Training
Workday Training
Okta Training
Palo Alto Training
Adobe Analytics Training

newin said...

ทดลองเล่นสล็อต Bagua เกมสล็อต บากัว ที่มีรูปแบบการเล่นที่เป็นรูปแบบพื้นฐานที่สามารถเข้าใจได้ง่ายในการเล่น จากค่ายเกม MEGA GAME แหล่งทำเงินและ ฟีเจอร์เข้าเล่นก่อนการทำเงินจริง https://www.megaslot.game/play-demo/ เพื่อเพิ่มโอกาสในการได้รับเงินรางวัลที่มากขึ้น.

สล็อตเว็บตรง said...

หลายท่านรู้จักตัว สล็อตเว็บตรง กันเป็นอย่างมากเพราะเป็นค่ายที่ตัวเกมส์สนุกสนานและได้เงินจริงในสมัยก่อนค่าย PG slot ยังเล่นได้แต่ในคอมพิวเตอร์แต่ในปัจจุบันทาง PG slotได้อัปเดตระบบทางเข้าPG slot มือถือ เสร็จเป็นที่เรียบร้อยแล้วเพื่อให้ผู้เล่นที่ไม่มีคอมพิวเตอร์หรือเวลาออกไปไหนมาไหนก็สามารถเล่นและสร้างรายได้จาก PG slot