示例#1
0
    def tweet_a_bill_action(self):
        # Tweet an interesting action on a bill.
        from bill.models import Bill, BillStatus
        from bill.status import get_bill_really_short_status_string
        bills = list(
            Bill.objects.filter(
                current_status_date__gte=timezone.now().date() -
                timedelta(days=1),
                current_status_date__lt=timezone.now().date(),
            ).exclude(current_status=BillStatus.introduced, ))
        if len(bills) == 0: return

        # Choose bill with the most salient status, breaking ties with the highest proscore.
        bills.sort(
            key=lambda b:
            (BillStatus.by_value(b.current_status).sort_order, b.proscore()),
            reverse=True)
        for bill in bills:
            status = BillStatus.by_value(bill.current_status).xml_code
            if "Providing for consideration" in bill.title: continue
            text = get_bill_really_short_status_string(status)
            if text == "": continue
            bill_number = bill.display_number
            if bill.sponsor and bill.sponsor.twitterid:
                bill_number += " by @" + bill.sponsor.twitterid
            text = text % (bill_number, u"yesterday")
            text += " " + bill.title_no_number
            self.post_tweet(
                bill.current_status_date.isoformat() + ":bill:%s:status:%s" %
                (bill.congressproject_id, status), text,
                "https://www.govtrack.us" + bill.get_absolute_url())
	def tweet_a_bill_action(self):
		# Tweet an interesting action on a bill.
		from bill.models import Bill, BillStatus
		from bill.status import get_bill_really_short_status_string
		bills = list(Bill.objects.filter(
			current_status_date__gte=timezone.now().date()-timedelta(days=1),
			current_status_date__lt=timezone.now().date(),
		).exclude(
			current_status=BillStatus.introduced,
		))
		if len(bills) == 0: return

		# Choose bill with the most salient status, breaking ties with the highest proscore.
		bills.sort(key = lambda b : (BillStatus.by_value(b.current_status).sort_order, b.proscore()), reverse=True)
		for bill in bills:
			status = BillStatus.by_value(bill.current_status).xml_code
			if "Providing for consideration" in bill.title: continue
			text = get_bill_really_short_status_string(status)
			if text == "": continue
			bill_number = bill.display_number
			if bill.sponsor and bill.sponsor.twitterid: bill_number += " by @" + bill.sponsor.twitterid
			text = text % (bill_number, "yesterday")
			text += " " + bill.title_no_number
			self.post_tweet(
				bill.current_status_date.isoformat() + ":bill:%s:status:%s" % (bill.congressproject_id, status),
				text,
				"https://www.govtrack.us" + bill.get_absolute_url())
def bill_search_manager():
    sm = SearchManager(Bill, connection="bill")
    
    sm.add_option('similar_to', type="text", label="similar to (enter bill number)", visible_if=lambda form : False, filter=similar_to)
    sm.add_option('usc_cite', type="text", label="cites", visible_if=lambda form : False, orm_field_name='usc_citations_uptree', filter=usc_cite)
    
    sm.add_option('text', label='search title & full text', type="text", choices="NONE")
    sm.add_option('congress', type="select", formatter=format_congress_number, sort="KEY-REVERSE")
    sm.add_option('sponsor', type="select", sort="LABEL", formatter=lambda p : p.sortname)
    sm.add_option('current_status', label="current status", sort=lambda s : BillStatus.by_value(s).sort_order)
    sm.add_option('cosponsors', label="cosponsor", type="select", sort="LABEL", formatter=lambda p : p.sortname)
    sm.add_option('committees', label="committee", type="select", sort="LABEL", formatter=lambda c : c.shortname)
    sm.add_option('terms', type="select", label="subject", choices=get_terms(BillTerm.objects.exclude(parents__id__gt=0)))
    sm.add_option('terms2', type="select", label="subject 2", choices=sub_terms, visible_if=lambda post:"terms" in post, filter=sub_term_filter)
    sm.add_option('sponsor_party', label="party of sponsor", type="select")
    sm.add_option('bill_type', label="bill or resolution type")
    
    #sm.add_sort("Popularity", "-total_bets", default=True)
    sm.add_sort("Secret Sauce", "-proscore", default=True)
    sm.add_sort("Introduced Date (Newest First)", "-introduced_date")
    sm.add_sort("Introduced Date (Oldest First)", "introduced_date")
    sm.add_sort("Last Major Action (Recent First)", "-current_status_date")

    #def safe_strftime(date, format):
    #    return date.replace(year=3456).strftime(format).replace("3456", str(date.year)).replace(" 12:00AM", "")
    
    sm.set_template("""
    	<a href="{{object.get_absolute_url}}" style="font-size: 15px">{{object|truncatewords_html:50}}</a>
    	{% if object.sponsor %}<div>Sponsor: {{object.sponsor}}</div>{% endif %}
    	{% if object.source != "statutesatlarge" %}<div>Introduced: {{object.introduced_date}}</div>{% endif %}
    	{% if object.source != "americanmemory" %}<div>{% if object.source != "statutesatlarge" %}{{object.get_current_status_display}}{% else %}Enacted/Agreed to{% endif %}: {{object.current_status_date}}</div>{% endif %}
	""")
    
    return sm
示例#4
0
def bill_search_manager():
    sm = SearchManager(Bill, connection="bill", bulk_loader=bill_bulk_loader)
    
    sm.add_option('similar_to', type="text", label="similar to (enter bill number)", visible_if=lambda form : False, filter=similar_to)
    sm.add_option('usc_cite', type="text", label="cites", visible_if=lambda form : False, orm_field_name='usc_citations_uptree', filter=usc_cite)
    
    sm.add_option('text', label='search title & full text', type="text", choices="NONE")
    sm.add_option('congress', type="select", formatter=format_congress_number, sort="KEY-REVERSE")
    sm.add_option('sponsor', type="select", sort="LABEL", formatter=lambda p : p.sortname)
    sm.add_option('current_status', label="current status", sort=lambda s : BillStatus.by_value(s).sort_order)
    sm.add_option('enacted_ex', type="boolean", label="Enacted \u2014 Including by Incorporation into Other Bills")
    sm.add_option('cosponsors', label="cosponsor", type="select", sort="LABEL", formatter=lambda p : p.sortname)
    sm.add_option('committees', label="committee", type="select", sort="LABEL", formatter=lambda c : c.shortname)
    sm.add_option('terms', type="select", label="subject", choices=get_terms(BillTerm.objects.exclude(parents__id__gt=0)))
    sm.add_option('terms2', type="select", label="subject 2", choices=sub_terms, visible_if=lambda post:"terms" in post, filter=sub_term_filter)
    sm.add_option('sponsor_party', label="party of sponsor", type="select")
    sm.add_option('bill_type', label="bill or resolution type")
    
    #sm.add_sort("Popularity", "-total_bets", default=True)
    # default sort order is handled by the view
    sm.add_sort("Relevance of Title/Text", "relevance", func=lambda x : x) # no-op to use Solr default
    sm.add_sort("Secret Sauce", "-proscore")
    sm.add_sort("Introduced Date (Newest First)", "-introduced_date")
    sm.add_sort("Introduced Date (Oldest First)", "introduced_date")
    sm.add_sort("Last Major Action (Recent First)", "-current_status_date")
    sm.add_sort("Cosponsors (Most First)", "-cosponsor_count")
    sm.add_sort("Cosponsors (Fewest First)", "cosponsor_count")

    #def safe_strftime(date, format):
    #    return date.replace(year=3456).strftime(format).replace("3456", str(date.year)).replace(" 12:00AM", "")
    
    sm.set_template("""
	<div class="row">
		<div class="col-xs-2 col-md-1" style="padding-right: 0">
			<img src="{{object.get_absolute_url}}/thumbnail?aspect=1.2&width=125" class="img-responsive"/>
		</div>
		<div class="col-xs-10 col-md-11">
    	<div style="margin-bottom: 3px"><a href="{{object.get_absolute_url}}" style="font-size: 15px; line-height: 125%;">{{object|truncatewords_html:50}}</a></div>
		<div style="font-size: 90%">
    	{% if object.sponsor %}<div style="margin-bottom: 3px">Sponsor: {{object.sponsor_name}}</div>{% endif %}
		<table width="100%"><tr valign="top">
    	{% if object.source != "statutesatlarge" %}<td width="25%" style="padding-right: 1.5em">Introduced<br>{{object.introduced_date}}</td>{% else %}<td/>{% endif %}
    	{% if object.source != "americanmemory" and object.get_current_status_display_simple != "Introduced" %}<td width="25%" style="padding-right: 1.5em">{% if object.source != "statutesatlarge" %}{{object.get_current_status_display_simple}}{% else %}Enacted/Agreed to{% endif %}<br>{{object.current_status_date}}</td>{% else %}<td/>{% endif %}
		{% if 1 %}<td width="25%" style="padding-right: 1.5em">Cosponsors<br>{{object.cosponsor_counts_summary}}</td>{% else %}<td/>{% endif %}
		{% if object.is_alive and object.get_prognosis %}<td width="25%" style="padding-right: 1.5em">Prognosis<br>{{object.get_prognosis.prediction|floatformat:0}}%</td>{% else %}<td/>{% endif %}
		</tr></table>
        {% with b_list=object.was_enacted_ex %}
        {% for b in b_list %}
            {% if b and b != object %}
                <div>Enacted via <a href="{{b.get_absolute_url}}" style="text-decoration: none">{{b.title}}</a></div>
            {% endif %}
        {% endfor %}
		</div>
		</div>
	</div>
        {% endwith %}
	""")
    
    return sm
示例#5
0
def bill_search_manager():
    sm = SearchManager(Bill, connection="bill", bulk_loader=bill_bulk_loader)
    
    sm.add_option('similar_to', type="text", label="similar to (enter bill number)", visible_if=lambda form : False, filter=similar_to)
    sm.add_option('usc_cite', type="text", label="cites", visible_if=lambda form : False, orm_field_name='usc_citations_uptree', filter=usc_cite)
    
    sm.add_option('text', label='search title & full text', type="text", choices="NONE")
    sm.add_option('congress', type="select", formatter=format_congress_number, sort="KEY-REVERSE")
    sm.add_option('sponsor', type="select", sort="LABEL", formatter=lambda p : p.sortname)
    sm.add_option('current_status', label="current status", sort=lambda s : BillStatus.by_value(s).sort_order)
    sm.add_option('enacted_ex', type="boolean", label="Enacted \u2014 Including by Incorporation into Other Bills")
    sm.add_option('cosponsors', label="cosponsor", type="select", sort="LABEL", formatter=lambda p : p.sortname)
    sm.add_option('committees', label="committee", type="select", sort="LABEL", formatter=lambda c : c.shortname)
    sm.add_option('terms', type="select", label="subject", choices=get_terms(BillTerm.objects.exclude(parents__id__gt=0)))
    sm.add_option('terms2', type="select", label="subject 2", choices=sub_terms, visible_if=lambda post:"terms" in post, filter=sub_term_filter)
    sm.add_option('sponsor_party', label="party of sponsor", type="select")
    sm.add_option('bill_type', label="bill or resolution type")
    
    #sm.add_sort("Popularity", "-total_bets", default=True)
    # default sort order is handled by the view
    sm.add_sort("Secret Sauce", "-proscore")
    sm.add_sort("Introduced Date (Newest First)", "-introduced_date")
    sm.add_sort("Introduced Date (Oldest First)", "introduced_date")
    sm.add_sort("Last Major Action (Recent First)", "-current_status_date")
    sm.add_sort("Cosponsors (Most First)", "-cosponsor_count")
    sm.add_sort("Cosponsors (Fewest First)", "cosponsor_count")

    #def safe_strftime(date, format):
    #    return date.replace(year=3456).strftime(format).replace("3456", str(date.year)).replace(" 12:00AM", "")
    
    sm.set_template("""
	<div class="row">
		<div class="col-xs-2 col-md-1" style="padding-right: 0">
			<img src="{{object.get_absolute_url}}/thumbnail?aspect=1.2&width=125" class="img-responsive"/>
		</div>
		<div class="col-xs-10 col-md-11">
    	<div style="margin-bottom: 3px"><a href="{{object.get_absolute_url}}" style="font-size: 15px; line-height: 125%;">{{object|truncatewords_html:50}}</a></div>
		<div style="font-size: 90%">
    	{% if object.sponsor %}<div style="margin-bottom: 3px">Sponsor: {{object.sponsor_name}}</div>{% endif %}
		<table width="100%"><tr valign="top">
    	{% if object.source != "statutesatlarge" %}<td width="25%" style="padding-right: 1.5em">Introduced<br>{{object.introduced_date}}</td>{% else %}<td/>{% endif %}
    	{% if object.source != "americanmemory" and object.get_current_status_display_simple != "Introduced" %}<td width="25%" style="padding-right: 1.5em">{% if object.source != "statutesatlarge" %}{{object.get_current_status_display_simple}}{% else %}Enacted/Agreed to{% endif %}<br>{{object.current_status_date}}</td>{% else %}<td/>{% endif %}
		{% if 1 %}<td width="25%" style="padding-right: 1.5em">Cosponsors<br>{{object.cosponsor_counts_summary}}</td>{% else %}<td/>{% endif %}
		{% if object.is_alive and object.get_prognosis %}<td width="25%" style="padding-right: 1.5em">Prognosis<br>{{object.get_prognosis.prediction|floatformat:0}}%</td>{% else %}<td/>{% endif %}
		</tr></table>
        {% with b_list=object.was_enacted_ex %}
        {% for b in b_list %}
            {% if b and b != object %}
                <div>Enacted via <a href="{{b.get_absolute_url}}" style="text-decoration: none">{{b.title}}</a></div>
            {% endif %}
        {% endfor %}
		</div>
		</div>
	</div>
        {% endwith %}
	""")
    
    return sm
示例#6
0
def bill_search_manager():
    sm = SearchManager(Bill, connection="bill")

    sm.add_option('similar_to',
                  type="text",
                  label="similar to (enter bill number)",
                  visible_if=lambda form: False,
                  filter=similar_to)
    sm.add_option('usc_cite',
                  type="text",
                  label="cites",
                  visible_if=lambda form: False,
                  orm_field_name='usc_citations_uptree',
                  filter=usc_cite)

    sm.add_option('text',
                  label='search title & full text',
                  type="text",
                  choices="NONE")
    sm.add_option('congress',
                  type="select",
                  formatter=format_congress_number,
                  sort="KEY-REVERSE")
    sm.add_option('sponsor',
                  type="select",
                  sort="LABEL",
                  formatter=lambda p: p.sortname)
    sm.add_option('current_status',
                  label="current status",
                  sort=lambda s: BillStatus.by_value(s).sort_order)
    sm.add_option(
        'enacted_ex',
        type="boolean",
        label=u"Enacted \u2014 Including by Incorporation into Other Bills")
    sm.add_option('cosponsors',
                  label="cosponsor",
                  type="select",
                  sort="LABEL",
                  formatter=lambda p: p.sortname)
    sm.add_option('committees',
                  label="committee",
                  type="select",
                  sort="LABEL",
                  formatter=lambda c: c.shortname)
    sm.add_option('terms',
                  type="select",
                  label="subject",
                  choices=get_terms(
                      BillTerm.objects.exclude(parents__id__gt=0)))
    sm.add_option('terms2',
                  type="select",
                  label="subject 2",
                  choices=sub_terms,
                  visible_if=lambda post: "terms" in post,
                  filter=sub_term_filter)
    sm.add_option('sponsor_party', label="party of sponsor", type="select")
    sm.add_option('bill_type', label="bill or resolution type")

    #sm.add_sort("Popularity", "-total_bets", default=True)
    # default sort order is handled by the view
    sm.add_sort("Secret Sauce", "-proscore")
    sm.add_sort("Introduced Date (Newest First)", "-introduced_date")
    sm.add_sort("Introduced Date (Oldest First)", "introduced_date")
    sm.add_sort("Last Major Action (Recent First)", "-current_status_date")

    #def safe_strftime(date, format):
    #    return date.replace(year=3456).strftime(format).replace("3456", str(date.year)).replace(" 12:00AM", "")

    sm.set_template("""
    	<a href="{{object.get_absolute_url}}" style="font-size: 15px; line-height: 125%;">{{object|truncatewords_html:50}}</a>
    	{% if object.sponsor %}<div>Sponsor: {{object.sponsor}}</div>{% endif %}
    	{% if object.source != "statutesatlarge" %}<div>Introduced: {{object.introduced_date}}</div>{% endif %}
    	{% if object.source != "americanmemory" %}<div>{% if object.source != "statutesatlarge" %}{{object.get_current_status_display}}{% else %}Enacted/Agreed to{% endif %}: {{object.current_status_date}}</div>{% endif %}
        {% with b_list=object.was_enacted_ex %}
        {% for b in b_list %}
            {% if b and b != object %}
                <div>Enacted via <a href="{{b.get_absolute_url}}">{{b.title}}</a></div>
            {% endif %}
        {% endfor %}
        {% endwith %}
	""")

    return sm
#!script

from django.db.models import Count
import sys, csv
from bill.models import Cosponsor, Bill, BillStatus

bills_most_cosponsored = \
 Cosponsor.objects \
   .filter(bill__congress=114) \
  .filter(withdrawn=None) \
  .values("bill") \
  .annotate(count=Count('id')) \
  .order_by("-count") #\
#[0:200]

w = csv.writer(sys.stdout)
for bill_and_count in bills_most_cosponsored:
    bill = Bill.objects.get(id=bill_and_count["bill"])
    w.writerow([
        bill_and_count["count"],
        unicode(bill).encode("utf8"),
        BillStatus.by_value(bill.current_status).label.encode("utf8"),
        "https://www.govtrack.us" + bill.get_absolute_url(),
    ])
#!script

from django.db.models import Count
import sys, csv
from bill.models import Cosponsor, Bill, BillStatus

bills_most_cosponsored = \
	Cosponsor.objects \
 	 .filter(bill__congress=114) \
	 .filter(withdrawn=None) \
	 .values("bill") \
	 .annotate(count=Count('id')) \
	 .order_by("-count") #\
	#[0:200]

w = csv.writer(sys.stdout)
for bill_and_count in bills_most_cosponsored:
	bill = Bill.objects.get(id=bill_and_count["bill"])
	w.writerow([
		bill_and_count["count"],
		str(bill).encode("utf8"),
		BillStatus.by_value(bill.current_status).label.encode("utf8"),
		"https://www.govtrack.us" + bill.get_absolute_url(),
	])