Beispiel #1
0
    def GET(self, polid, format=None):
        if polid != polid.lower():
            raise web.seeother('/p/' + polid.lower())

        i = web.input()
        idlookup = False
        for k in ['votesmartid', 'bioguideid', 'opensecretsid', 'govtrackid']:
            if i.get(k):
                idlookup = True
                ps = schema.Politician.where(**{k: i[k]})
                if ps: raise web.seeother('/p/' + ps[0].id)

        if idlookup:
            # we were looking up by ID but nothing matched
            raise web.notfound()

        if polid == "" or polid == "index":
            polids = tuple(x.id
                           for x in db.query('select id from curr_politician'))
            p = schema.Politician.select(where='id in $polids',
                                         order='district_id asc',
                                         vars=locals())
            out = apipublish.publish(p, format)
            if out: return out

            return render.pollist(p)

        try:
            p = schema.Politician.where(id=polid)[0]
        except IndexError:
            raise web.notfound()

        #@@move into schema
        p.fec_ids = [
            x.fec_id for x in db.select('politician_fec_ids',
                                        what='fec_id',
                                        where='politician_id=$polid',
                                        vars=locals())
        ]

        p.related_groups = group_politician_similarity(polid)
        p.contributors = politician_contributors(polid, 5)
        p.contributor_employers = politician_contributor_employers(polid, 5)
        p.lob_contribs = politician_lob_contributions(polid, 0, 5)
        p.capitolwords = p.bioguideid and get_capitolwords(p.bioguideid)
        out = apipublish.publish([p], format)
        if out: return out

        return render.politician(p, sparkpos)
Beispiel #2
0
    def GET(self, polid, format=None):
        if polid != polid.lower():
            raise web.seeother('/p/' + polid.lower())
        
        i = web.input()
        idlookup = False
        for k in ['votesmartid', 'bioguideid', 'opensecretsid', 'govtrackid']:
            if i.get(k):
                idlookup = True
                ps = schema.Politician.where(**{k: i[k]})
                if ps: raise web.seeother('/p/' + ps[0].id)

        if idlookup:
            # we were looking up by ID but nothing matched
            raise web.notfound()

        if polid == "" or polid == "index":
            polids = tuple(x.id for x in db.query('select id from curr_politician'))
            p = schema.Politician.select(where='id in $polids', order='district_id asc', vars=locals())
            out = apipublish.publish(p, format)
            if out: return out

            return render.pollist(p)

        try:
            p = schema.Politician.where(id=polid)[0]
        except IndexError:
            raise web.notfound()

        #@@move into schema
        p.fec_ids = [x.fec_id for x in db.select('politician_fec_ids', what='fec_id',
          where='politician_id=$polid', vars=locals())]

        p.related_groups = group_politician_similarity(polid)
        p.contributors = politician_contributors(polid, 5)
        p.contributor_employers = politician_contributor_employers(polid, 5)
        p.lob_contribs = politician_lob_contributions(polid, 0, 5)
        p.capitolwords = p.bioguideid and get_capitolwords(p.bioguideid)
        out = apipublish.publish([p], format)
        if out: return out

        return render.politician(p, sparkpos)
Beispiel #3
0
    def GET(self, polid, format=None):
        if polid != polid.lower():
            raise web.seeother('/p/' + polid.lower())
        
        i = web.input()
        idlookup = False
        for k in ['votesmartid', 'bioguideid', 'opensecretsid', 'govtrackid']:
            if i.get(k):
                idlookup = True
                ps = schema.Politician.where(**{k: i[k]})
                if ps: raise web.seeother('/p/' + ps[0].id)

        if idlookup:
            # we were looking up by ID but nothing matched
            raise web.notfound

        if polid == "" or polid == "index":
            p = schema.Politician.select(order='district_id asc')

            out = apipublish.publish(p, format)
            if out: return out

            return render.pollist(p)

        try:
            p = schema.Politician.where(id=polid)[0]
        except IndexError:
            raise web.notfound

        #@@move into schema
        p.fec_ids = [x.fec_id for x in db.select('politician_fec_ids', what='fec_id',
          where='politician_id=$polid', vars=locals())]

        p.related_groups = group_politician_similarity(polid)

        out = apipublish.publish([p], format)
        if out: return out

        return render.politician(p, sparkpos)
Beispiel #4
0
 def GET(self, polid, format=None):
     if polid != polid.lower():
         raise web.seeother('/p/' + polid.lower())
     
     if polid == "" or polid == "index":
         p = db.select(['politician'], order='district asc').list()
         
         out = apipublish.publish({
           'uri': apipublish.generic(lambda x: 'http://watchdog.net/p/' +
                                     x.id),
           'type': 'Politician',
           'district': lambda x: apipublish.URI('http://watchdog.net/us/' +
                                                x.lower()),
           'wikipedia': apipublish.URI,
          }, p, format)
         if out is not False:
             return out
         
         return render.pollist(p)
     
     try:
         p = db.select(['politician', 'district'],
                       what=("politician.*, "
                             "district.center_lat as d0, "
                             "district.center_lng as d1, "
                             "district.zoom_level as d2"),
                       where=('id=$polid AND '
                              'district.name = politician.district'),
                       vars=locals())[0]
     except IndexError:
         raise web.notfound
     
     p.fec_ids = [x.fec_id for x in db.select('politician_fec_ids', what='fec_id', 
       where='politician_id=$polid', vars=locals())]
     
     p.interest_group_rating = interest_group_ratings(polid)
     p.interest_group_table = interest_group_table(p.interest_group_rating)
     p.related_groups = group_politician_similarity(polid)
     p.sponsored_bills = bills_sponsored(polid)                           
         
     out = apipublish.publish({
       'uri': 'http://watchdog.net/p/' + polid,
       'type': 'Politician',
       'district': apipublish.URI('http://watchdog.net/us/' + p.district.lower()),
       'wikipedia photo_credit_url officeurl': apipublish.URI,
       'interest_group_rating': apipublish.table({
             'year groupname longname rating': apipublish.identity}),
       'related_groups' : apipublish.table({
             'longname': apipublish.identity,
             'num_bills_agreed': apipublish.generic(lambda g: g.agreed),
             'num_bills_voted': apipublish.generic(lambda g: g.total),
             'agreement_percent': apipublish.generic(lambda g: int(g.agreement * 100)),
             'group_politician_url': apipublish.generic(lambda g: 
                                     'http://watchdog.net/p/%s/%s' % (polid, g.id))
         }), 
         'sponsored_bills': apipublish.table({
             'id': apipublish.generic(lambda b: '%s. %s' % (b.type.upper(), b.number)),
             'session title introduced': apipublish.identity,
             'url': apipublish.generic(lambda b: 'http://watchdog.net/b/%s' % (b.id))
         }),
       'bioguideid opensecretsid govtrackid gender birthday firstname '
       'middlename lastname party religion photo_path '
       'photo_credit_text '
       'amt_earmark_requested n_earmark_requested n_earmark_received '
       'amt_earmark_received '
       'n_bills_introduced n_bills_enacted n_bills_debated '
       'n_bills_cosponsored '
       'icpsrid nominate predictability '
       'n_speeches words_per_speech '
       'fec_ids money_raised pct_spent pct_self '
       'pct_indiv pct_pac': apipublish.identity,
      }, [p], format)
     if out:
         return out
     
     return render.politician(p)