本文整理汇总了Python中bill.models.BillType类的典型用法代码示例。如果您正苦于以下问题:Python BillType类的具体用法?Python BillType怎么用?Python BillType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BillType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: was_bill_enacted
def was_bill_enacted(b, startdate, enddate, recurse=True):
# Our status code is currently tied to the assignment of a slip
# law number, which isn't what we mean exactly.
#
# (Additionally, we should count a bill as enacted if any identified companion
# bill is enacted.)
# If it *was* assigned a slip law number, which in the future might
# be useful for veto overrides, then OK.
if b.current_status in BillStatus.final_status_passed_bill and \
startdate <= b.current_status_date <= enddate:
return True
# Otherwise, check the actions for a <signed> action.
fn = "data/congress/%s/bills/%s/%s%d/data.json" % (
b.congress,
BillType.by_value(b.bill_type).slug,
BillType.by_value(b.bill_type).slug,
b.number)
bj = json.load(open(fn))
for axn in bj["actions"]:
if axn["type"] == "signed" and startdate.isoformat() <= axn["acted_at"] <= enddate.isoformat():
return True
# Otherwise check companion bills.
#if recurse:
# for rb in RelatedBill.objects.filter(bill=b, relation="identical").select_related("related_bill"):
# if was_bill_enacted(rb.related_bill, startdate, enddate, recurse=False):
# return True
return False
示例2: was_bill_enacted_2013
def was_bill_enacted_2013(b, startdate, enddate):
# Our status code is currently tied to the assignment of a slip
# law number, which isn't what we mean exactly.
#
# (Additionally, we should count a bill as enacted if any identified companion
# bill is enacted.)
# TODO: See new function in the Bill model.
# If it *was* assigned a slip law number, which in the future might
# be useful for veto overrides, then OK.
if b.current_status in BillStatus.final_status_passed_bill and \
startdate <= b.current_status_date <= enddate:
return True
# Otherwise, check the actions for a <signed> action.
fn = "data/congress/%s/bills/%s/%s%d/data.json" % (
b.congress,
BillType.by_value(b.bill_type).slug,
BillType.by_value(b.bill_type).slug,
b.number)
bj = json.load(open(fn))
for axn in bj["actions"]:
if axn["type"] == "signed" and startdate.isoformat() <= axn["acted_at"] <= enddate.isoformat():
return True
return False
示例3: get_bill_text_metadata
def get_bill_text_metadata(bill, version):
from bill.models import BillType # has to be here and not module-level to avoid cyclic dependency
import glob, json
bt = BillType.by_value(bill.bill_type).slug
basename = "data/congress/%d/bills/%s/%s%d/text-versions" % (bill.congress, bt, bt, bill.number)
if version == None:
# Cycle through files to find most recent version by date.
dat = None
for versionfile in glob.glob(basename + "/*/data.json"):
d = json.load(open(versionfile))
if not dat or d["issued_on"] > dat["issued_on"]:
dat = d
if not dat: return None
else:
dat = json.load(open(basename + "/%s/data.json" % version))
basename += "/" + dat["version_code"]
bt2 = BillType.by_value(bill.bill_type).xml_code
html_fn = "data/us/bills.text/%s/%s/%s%d%s.html" % (bill.congress, bt2, bt2, bill.number, dat["version_code"])
if os.path.exists(basename + "/mods.xml"):
dat["mods_file"] = basename + "/mods.xml"
# get a plain text file if one exists
if os.path.exists(basename + "/document.txt"):
dat["text_file"] = basename + "/document.txt"
dat["has_displayable_text"] = True
for source in dat.get("sources", []):
if source["source"] == "statutes":
dat["text_file_source"] = "statutes"
# get an HTML file if one exists
if os.path.exists(html_fn):
dat["html_file"] = html_fn
dat["has_displayable_text"] = True
# get a PDF file if one exists
pdf_fn = "data/us/bills.text/%s/%s/%s%d%s.pdf" % (bill.congress, bt2, bt2, bill.number, dat["version_code"])
if os.path.exists(pdf_fn):
dat["pdf_file"] = pdf_fn
dat["has_thumbnail"] = True
dat["thumbnail_path"] = bill.get_absolute_url() + "/_text_image"
# get an XML file if one exists
if os.path.exists(basename + "/catoxml.xml"):
dat["xml_file"] = basename + "/catoxml.xml"
dat["has_displayable_text"] = True
dat["xml_file_source"] = "cato-deepbills"
elif os.path.exists(basename + "/document.xml"):
dat["xml_file"] = basename + "/document.xml"
dat["has_displayable_text"] = True
return dat
示例4: bill_text
def bill_text(request, congress, type_slug, number, version=None):
if version == "":
version = None
try:
bill_type = BillType.by_slug(type_slug)
except BillType.NotFound:
raise Http404("Invalid bill type: " + type_slug)
bill = get_object_or_404(Bill, congress=congress, bill_type=bill_type, number=number)
from billtext import load_bill_text, bill_gpo_status_codes
try:
textdata = load_bill_text(bill, version)
except IOError:
textdata = None
# Get a list of the alternate versions of this bill.
alternates = None
if textdata:
alternates = []
for v in bill_gpo_status_codes:
fn = "data/us/bills.text/%s/%s/%s%d%s.mods.xml" % (bill.congress, BillType.by_value(bill.bill_type).xml_code, BillType.by_value(bill.bill_type).xml_code, bill.number, v)
if os.path.exists(fn):
alternates.append(load_bill_text(bill, v, mods_only=True))
alternates.sort(key = lambda mods : mods["docdate"])
# Get a list of related bills.
from billtext import get_current_version
related_bills = []
for rb in list(bill.find_reintroductions()) + [r.related_bill for r in bill.get_related_bills()]:
try:
rbv = get_current_version(rb)
if not (rb, rbv) in related_bills: related_bills.append((rb, rbv))
except IOError:
pass # text not available
for btc in BillTextComparison.objects.filter(bill1=bill).exclude(bill2=bill):
if not (btc.bill2, btc.ver2) in related_bills: related_bills.append((btc.bill2, btc.ver2))
for btc in BillTextComparison.objects.filter(bill2=bill).exclude(bill1=bill):
if not (btc.bill1, btc.ver1) in related_bills: related_bills.append((btc.bill1, btc.ver1))
return {
'bill': bill,
"congressdates": get_congress_dates(bill.congress),
"textdata": textdata,
"version": version,
"alternates": alternates,
"related_bills": related_bills,
}
示例5: bill_details_user_view
def bill_details_user_view(request, congress, type_slug, number):
try:
bill_type = BillType.by_slug(type_slug)
except BillType.NotFound:
raise Http404("Invalid bill type: " + type_slug)
bill = get_object_or_404(Bill, congress=congress, bill_type=bill_type, number=number)
ret = { }
if request.user.is_staff:
admin_panel = """
{% load humanize %}
<div class="clear"> </div>
<div style="margin-top: 1.5em; padding: .5em; background-color: #EEE; ">
<b>ADMIN</b> - <a href="{% url "bill_go_to_summary_admin" %}?bill={{bill.id}}">Edit Summary</a>
<br/>Tracked by {{feed.tracked_in_lists.count|intcomma}} users
({{feed.tracked_in_lists_with_email.count|intcomma}} w/ email).
</div>
"""
from django.template import Template, Context, RequestContext, loader
ret["admin_panel"] = Template(admin_panel).render(RequestContext(request, {
'bill': bill,
"feed": Feed.BillFeed(bill),
}))
from person.views import render_subscribe_inline
ret.update(render_subscribe_inline(request, Feed.BillFeed(bill)))
return ret
示例6: bill_advocacy_tips
def bill_advocacy_tips(request, congress, type_slug, number):
try:
bill_type = BillType.by_slug(type_slug)
except BillType.NotFound:
raise Http404("Invalid bill type: " + type_slug)
bill = get_object_or_404(Bill, congress=congress, bill_type=bill_type, number=number)
return { "bill": bill }
示例7: get_transparency_stats
def get_transparency_stats(person, role, stats, congress, startdate, enddate):
global transparency_bills
if not transparency_bills:
transparency_bills = []
for line in open("analysis/transparency-bills.txt"):
bill = Bill.from_congressproject_id(re.split("\s", line)[0])
if bill.congress != congress: continue
transparency_bills.append(bill)
# which bills are in the right chamber?
plausible_bills = []
for bill in transparency_bills:
if BillType.by_value(bill.bill_type).chamber == RoleType.by_value(role.role_type).congress_chamber:
plausible_bills.append(bill)
# did person sponsor any of these within this session?
sponsored = []
for bill in transparency_bills:
if startdate <= bill.introduced_date <= enddate and bill.sponsor == person:
sponsored.append(bill)
# did person cosponsor any of these within this session?
cosponsored = []
for cosp in Cosponsor.objects.filter(person=person, bill__in=transparency_bills, joined__gte=startdate, joined__lte=enddate):
cosponsored.append(cosp.bill)
stats["transparency-bills"] = {
"value": len(sponsored)*3 + len(cosponsored),
"sponsored": make_bill_entries(sponsored),
"cosponsored": make_bill_entries(cosponsored),
"num_bills": len(plausible_bills),
"chamber": RoleType.by_value(role.role_type).congress_chamber,
}
示例8: load_docs_house_gov
def load_docs_house_gov(options, bill_index):
# Look at the three most recent JSON files by looking at the lexicographically last ones,
# which possibly cover the current week, the next week, and the week after that.
if not os.path.exists(settings.CONGRESS_DATA_PATH + "/upcoming_house_floor"):
print("No upcoming_house_floor data.")
return
for fn in sorted(os.listdir(settings.CONGRESS_DATA_PATH + "/upcoming_house_floor"))[-3:]:
data = json.load(open(settings.CONGRESS_DATA_PATH + "/upcoming_house_floor/" + fn))
for billinfo in data.get("upcoming", []):
if "bill_id" not in billinfo: continue
m = re.match(r"([hrsjconres]+)(\d+)-(\d+)", billinfo["bill_id"])
if not m:
log.error('Could not parse bill_id "%s" in docs.house.gov.' % billinfo["bill_id"])
continue
bt = BillType.by_slug(m.group(1))
try:
bill = Bill.objects.get(congress=int(m.group(3)), bill_type=bt, number=int(m.group(2)))
except Exception as e:
log.error('Could not get bill "%s" in docs.house.gov: %s.' % (billinfo["bill_id"], str(e)))
continue
bill.docs_house_gov_postdate = BillProcessor.parse_datetime(billinfo["published_at"])
if bill.senate_floor_schedule_postdate is None or bill.docs_house_gov_postdate > bill.senate_floor_schedule_postdate: bill.scheduled_consideration_date = BillProcessor.parse_datetime(data["week_of"])
bill.save()
if bill_index: bill.update_index(bill_index)
if not options.disable_events: bill.create_events()
示例9: get_bill_number
def get_bill_number(bill, show_congress_number="ARCHIVAL"):
"Compute display form of bill number"
from bill.models import BillType
ret = '%s %s' % (BillType.by_value(bill.bill_type).label, bill.number)
if (bill.congress != settings.CURRENT_CONGRESS and show_congress_number == "ARCHIVAL") or show_congress_number == "ALL":
ret += ' (%s)' % ordinal(bill.congress)
return ret
示例10: bill_text
def bill_text(request, congress, type_slug, number, version=None):
if version == "":
version = None
try:
bill_type = BillType.by_slug(type_slug)
except BillType.NotFound:
raise Http404("Invalid bill type: " + type_slug)
bill = get_object_or_404(Bill, congress=congress, bill_type=bill_type, number=number)
from .billtext import load_bill_text, get_bill_text_versions
try:
textdata = load_bill_text(bill, version)
except IOError:
textdata = None
# Get a list of the alternate versions of this bill.
alternates = None
is_latest = True
if textdata:
alternates = []
for v in get_bill_text_versions(bill):
try:
alternates.append(load_bill_text(bill, v, mods_only=True))
except IOError:
pass
alternates.sort(key = lambda mods : mods["docdate"])
if len(alternates) > 0:
is_latest = False
if textdata["doc_version"] == alternates[-1]["doc_version"]:
is_latest = True
# Get a list of related bills.
from .billtext import get_current_version
related_bills = []
for rb in list(bill.find_reintroductions()) + [r.related_bill for r in bill.get_related_bills()]:
try:
rbv = get_current_version(rb)
if not (rb, rbv) in related_bills: related_bills.append((rb, rbv))
except IOError:
pass # text not available
for btc in BillTextComparison.objects.filter(bill1=bill).exclude(bill2=bill):
if not (btc.bill2, btc.ver2) in related_bills: related_bills.append((btc.bill2, btc.ver2))
for btc in BillTextComparison.objects.filter(bill2=bill).exclude(bill1=bill):
if not (btc.bill1, btc.ver1) in related_bills: related_bills.append((btc.bill1, btc.ver1))
return {
"bill_subpage": "Text",
'bill': bill,
"congressdates": get_congress_dates(bill.congress),
"textdata": textdata,
"version": version,
"is_latest": is_latest,
"alternates": alternates,
"related_bills": related_bills,
"days_old": (datetime.datetime.now().date() - bill.current_status_date).days,
"is_on_bill_text_page": True, # for the header tabs
}
示例11: process_bill
def process_bill(self, obj, node):
amends_type = BillType.by_xml_code(node.xpath('string(amends/@type)'))
amends_number = int(node.xpath('string(amends/@number)'))
try:
amends_seq = int(node.xpath('string(amends/@sequence)'))
except ValueError:
amends_seq = None
obj.bill = Bill.objects.get(congress=obj.congress, bill_type=amends_type, number=amends_number)
obj.sequence = amends_seq
示例12: load_bill_text
def load_bill_text(bill, version, plain_text=False, mods_only=False):
if bill.congress < 103 or plain_text:
return load_bill_text_alt(bill, version, plain_text=plain_text, mods_only=mods_only)
from bill.models import BillType # has to be here and not module-level to avoid cyclic dependency
bt = BillType.by_value(bill.bill_type).xml_code
basename = "data/us/bills.text/%s/%s/%s%d%s" % (bill.congress, bt, bt, bill.number, version if version != None else "")
if mods_only:
bill_text_content = None
else:
bill_text_content = open(basename + ".html").read()
mods = lxml.etree.parse(basename + ".mods.xml")
ns = { "mods": "http://www.loc.gov/mods/v3" }
docdate = mods.xpath("string(mods:originInfo/mods:dateIssued)", namespaces=ns)
gpo_url = "http://www.gpo.gov/fdsys/search/pagedetails.action?packageId=" + mods.xpath("string(mods:recordInfo/mods:recordIdentifier[@source='DGPO'])", namespaces=ns)
#gpo_url = mods.xpath("string(mods:identifier[@type='uri'])", namespaces=ns)
gpo_pdf_url = mods.xpath("string(mods:location/mods:url[@displayLabel='PDF rendition'])", namespaces=ns)
doc_version = mods.xpath("string(mods:extension/mods:billVersion)", namespaces=ns)
numpages = mods.xpath("string(mods:physicalDescription/mods:extent)", namespaces=ns)
if numpages: numpages = re.sub(r" p\.$", " pages", numpages)
docdate = datetime.date(*(int(d) for d in docdate.split("-")))
doc_version_name = bill_gpo_status_codes[doc_version]
# load a list of citations as marked up by GPO
citations = []
for cite in mods.xpath("//mods:identifier", namespaces=ns):
if cite.get("type") == "USC citation":
citations.append( parse_usc_citation(cite) )
elif cite.get("type") == "Statute citation":
citations.append({ "type": "statutes_at_large", "text": cite.text })
elif cite.get("type") == "public law citation":
try:
congress_cite, slip_law_num = re.match(r"Public Law (\d+)-(\d+)$", cite.text).groups()
citations.append({ "type": "slip_law", "text": cite.text, "congress": int(congress_cite), "number": int(slip_law_num) })
except:
citations.append({ "type": "unknown", "text": cite.text })
return {
"bill_id": bill.id,
"bill_name": bill.title,
"basename": basename,
"text_html": bill_text_content,
"docdate": docdate,
"gpo_url": gpo_url,
"gpo_pdf_url": gpo_pdf_url,
"doc_version": doc_version,
"doc_version_name": doc_version_name,
"numpages": numpages,
"has_html_text": True,
"citations": citations,
}
示例13: bill
def bill(self):
if not hasattr(self, "_ref"):
if ":" in self.feedname and self.feedname.split(":")[0] in ("bill",):
from bill.models import Bill, BillType
m = re.match(r"([a-z]+)(\d+)-(\d+)", self.feedname.split(":")[1])
bill_type = BillType.by_xml_code(m.group(1))
return Bill.objects.get(congress=m.group(2), bill_type=bill_type, number=m.group(3))
else:
self._ref = None
return self._ref
示例14: load_bill_from_url
def load_bill_from_url(congress, type_slug, number):
# not sure why we were trying this
#if type_slug.isdigit():
# bill_type = type_slug
try:
bill_type = BillType.by_slug(type_slug)
except BillType.NotFound:
raise Http404("Invalid bill type: " + type_slug)
return get_object_or_404(Bill, congress=congress, bill_type=bill_type, number=number)
示例15: process_relatedbills
def process_relatedbills(self, obj, node):
RelatedBill.objects.filter(bill=obj).delete()
for subnode in node.xpath("./relatedbills/bill"):
try:
related_bill = Bill.objects.get(
congress=subnode.get("session"),
bill_type=BillType.by_xml_code(subnode.get("type")),
number=int(subnode.get("number")),
)
except Bill.DoesNotExist:
continue
RelatedBill.objects.create(bill=obj, related_bill=related_bill, relation=subnode.get("relation"))