diff --git a/tasks/bill_info.py b/tasks/bill_info.py index 58a672c..f06762a 100644 --- a/tasks/bill_info.py +++ b/tasks/bill_info.py @@ -19,7 +19,7 @@ def create_govtrack_xml(bill, options): if options.get("govtrack", False): # Rewrite bioguide_id attributes as just id with GovTrack person IDs. attrs2 = {} - for k, v in list(attrs.items()): + for k, v in attrs.items(): if v: if k == "bioguide_id": # remap "bioguide_id" attributes to govtrack "id" @@ -328,7 +328,7 @@ def titles_for(title_list): titles_copy = list(titles) # clone before beginning sort def first_index_of(**kwargs): for i, title in enumerate(titles_copy): - for k, v in list(kwargs.items()): + for k, v in kwargs.items(): k = k.replace("_", "") if title.get(k) != v: break diff --git a/tasks/bills.py b/tasks/bills.py index c0e4d30..bef4e16 100644 --- a/tasks/bills.py +++ b/tasks/bills.py @@ -108,7 +108,7 @@ def process_bill(bill_id, options): # Convert and write out data.json and data.xml. utils.write( - str(json.dumps(bill_data, indent=2, sort_keys=True)), + json.dumps(bill_data, indent=2, sort_keys=True), os.path.dirname(fdsys_xml_path) + '/data.json') from bill_info import create_govtrack_xml diff --git a/tasks/committee_meetings.py b/tasks/committee_meetings.py index b23c371..72bbbc1 100644 --- a/tasks/committee_meetings.py +++ b/tasks/committee_meetings.py @@ -113,7 +113,7 @@ def fetch_senate_committee_meetings(committees, options): if subcommittee_code and subcommittee_code not in committees[committee_code]["subcommittees"]: raise ValueError(subcommittee_code) except: - print(("Invalid committee code", committee_id)) + print("Invalid committee code", committee_id) continue # See if this meeting already exists. If so, take its GUID. @@ -122,7 +122,7 @@ def fetch_senate_committee_meetings(committees, options): for mtg in existing_meetings: if mtg["committee"] == committee_code and mtg.get("subcommittee", None) == subcommittee_code and mtg["occurs_at"] == occurs_at.isoformat(): if options.get("debug", False): - print(("[%s] Reusing gUID." % mtg["guid"])) + print("[%s] Reusing gUID." % mtg["guid"]) guid = mtg["guid"] break else: @@ -139,7 +139,7 @@ def fetch_senate_committee_meetings(committees, options): # Create the meeting event. if options.get("debug", False): - print(("[senate][%s][%s] Found meeting in room %s at %s." % (committee_code, subcommittee_code, room, occurs_at.isoformat()))) + print("[senate][%s][%s] Found meeting in room %s at %s." % (committee_code, subcommittee_code, room, occurs_at.isoformat())) meetings.append({ "chamber": "senate", @@ -153,7 +153,7 @@ def fetch_senate_committee_meetings(committees, options): "bill_ids": bills, }) - print(("[senate] Found %i meetings." % len(meetings))) + print("[senate] Found %i meetings." % len(meetings)) return meetings # House @@ -217,7 +217,7 @@ def fetch_house_committee_meetings(committees, options): # if bad zipfile if load_xml_from_page == False: continue - print(("[house] Found %i meetings." % len(meetings))) + print("[house] Found %i meetings." % len(meetings)) return meetings @@ -245,7 +245,7 @@ def fetch_meeting_from_event_id(committees, options, load_id): if load_xml_from_page == False: continue current_id += 1 - print(("[house] Found %i meetings." % len(meetings))) + print("[house] Found %i meetings." % len(meetings)) return meetings @@ -301,7 +301,7 @@ def extract_meeting_package(eventurl, event_id, options): try: dom = lxml.etree.fromstring(request.read()) except lxml.etree.XMLSyntaxError as e: - print((event_id, e)) + print(event_id, e) return False return {"witnesses": None, "uploaded_documents": [], "dom": dom} @@ -539,7 +539,7 @@ def parse_house_committee_meeting(event_id, dom, existing_meetings, committees, # return the parsed meeting if options.get("debug", False): - print(("[house][%s][%s] Found meeting in room %s at %s" % (committee_code, subcommittee_code, room, occurs_at.isoformat()))) + print("[house][%s][%s] Found meeting in room %s at %s" % (committee_code, subcommittee_code, room, occurs_at.isoformat())) results = { "chamber": "house", @@ -582,7 +582,7 @@ def save_documents(package, event_id): try: bytes = package.read(name) except: - print(("Did not save to disk: file %s" % (name))) + print("Did not save to disk: file %s" % (name)) continue file_name = "%s/%s" % (output_dir, name) @@ -651,7 +651,7 @@ def save_file(url, event_id): text_doc = text_from_pdf(file_name) return True except: - print(("Failed to save- %s" % (url))) + print("Failed to save- %s" % (url)) return False else: logging.info("failed to fetch: " + url) diff --git a/tasks/utils.py b/tasks/utils.py index 8ca522a..36f2d1b 100644 --- a/tasks/utils.py +++ b/tasks/utils.py @@ -535,7 +535,7 @@ def admin(body): except Exception as exception: print("Exception logging message to admin, halting as to avoid loop") - print((format_exception(exception))) + print(format_exception(exception)) def format_exception(exception): @@ -575,7 +575,7 @@ def make_node(parent, tag, text, **attrs): n = etree.Element(tag) parent.append(n) n.text = text - for k, v in list(attrs.items()): + for k, v in attrs.items(): if v is None: continue if isinstance(v, datetime.datetime): @@ -836,7 +836,7 @@ def translate_legislator_id(source_id_type, source_id, dest_id_type): _translate_legislator_id_cache = { } for filename in ("legislators-historical", "legislators-current"): for moc in yaml_load("congress-legislators/%s.yaml" % (filename)): - for id_type, id_value in list(moc["id"].items()): + for id_type, id_value in moc["id"].items(): try: _translate_legislator_id_cache[(id_type, id_value)] = moc['id'] except TypeError: @@ -874,6 +874,6 @@ class NoInterrupt(object): for sig in self.sigs: signal.signal(sig, self.old_handlers[sig]) # Issue the signals caught during the with-block. - for sig, args in list(self.signal_received.items()): + for sig, args in self.signal_received.items(): if self.old_handlers[sig]: self.old_handlers[sig](*args) diff --git a/tasks/vote_info.py b/tasks/vote_info.py index adb8c33..68499bd 100644 --- a/tasks/vote_info.py +++ b/tasks/vote_info.py @@ -33,7 +33,7 @@ def fetch_vote(vote_id, options): if options.get("download_only", False): return {'saved': False, 'ok': True, 'reason': "requested download only"} - if bytes("This vote was vacated".encode('utf8')) in body: + if b"This vote was vacated" in body: # Vacated votes: 2011-484, 2012-327, ... # Remove file, since it may previously have existed with data. for f in (output_for_vote(vote_id, "json"), output_for_vote(vote_id, "xml")): @@ -132,7 +132,7 @@ def output_vote(vote, options, id_type=None): # preferred order of output: ayes, nays, present, then not voting, and similarly for guilty/not-guilty # and handling other options like people's names for votes for the Speaker. option_sort_order = ('Aye', 'Yea', 'Guilty', 'No', 'Nay', 'Not Guilty', 'OTHER', 'Present', 'Not Voting') - options_list = sorted(list(vote["votes"].keys()), key=lambda o: option_sort_order.index(o) if o in option_sort_order else option_sort_order.index("OTHER")) + options_list = sorted(vote["votes"].keys(), key=lambda o: option_sort_order.index(o) if o in option_sort_order else option_sort_order.index("OTHER")) for option in options_list: if option not in option_keys: option_keys[option] = option @@ -155,7 +155,7 @@ def output_vote(vote, options, id_type=None): if v.get("voteview_votecode_extra") is not None: n.set("voteview_votecode_extra", v["voteview_votecode_extra"]) - xmloutput = etree.tostring(root, pretty_print=True).decode('utf8') + xmloutput = etree.tostring(root, pretty_print=True, encoding="unicode") # mimick two hard line breaks in GovTrack's legacy output to ease running diffs xmloutput = re.sub('(source=".*?") ', r"\1\n ", xmloutput) @@ -424,7 +424,7 @@ def parse_house_vote(dom, vote): # See https://github.com/unitedstates/congress/issues/46. seen_ids = set() - all_voters = sum(list(vote["votes"].values()), []) + all_voters = sum(vote["votes"].values(), []) all_voters.sort(key=lambda v: len(v["display_name"]), reverse=True) # process longer names first for v in all_voters: if v["id"] not in ("", "0000000"): diff --git a/tasks/votes.py b/tasks/votes.py index 4bec884..c6b6993 100644 --- a/tasks/votes.py +++ b/tasks/votes.py @@ -125,7 +125,7 @@ def vote_ids_for_senate(congress, session_year, options): utils.merge(options, {'binary': True}) ) - if not page or bytes("Requested Page Not Found (404)".encode('utf-8')) in page: + if not page or b"Requested Page Not Found (404)" in page: logging.error("Couldn't download Senate vote XML index %s, skipping" % url) return None diff --git a/tasks/voteview.py b/tasks/voteview.py index 1252068..043e9d3 100644 --- a/tasks/voteview.py +++ b/tasks/voteview.py @@ -462,7 +462,7 @@ def build_votes(vote_list): }) # sort for output - for voters in list(votes.values()): + for voters in votes.values(): voters.sort(key=lambda v: v['display_name']) return (votes, presidents_positions)