<commit_before>import re, logging, datetime, time, json
from lxml import etree

import utils

from bill_info import sponsor_for, actions_for


# downloads amendment information from THOMAS.gov, 
# parses out basic information, writes JSON to disk

def fetch_amendment(amendment_id, options):
  logging.info("\n[%s] Fetching..." % amendment_id)
  
  body = utils.download(
    amendment_url_for(amendment_id), 
    amendment_cache_for(amendment_id, "information.html"),
    options)

  if not body:
    return {'saved': False, 'ok': False, 'reason': "failed to download"}

  if options.get("download_only", False):
    return {'saved': False, 'ok': True, 'reason': "requested download only"}

  amendment_type, number, congress = utils.split_bill_id(amendment_id)
  
  actions = actions_for(body, amendment_id, is_amendment=True)
  if actions is None: actions = []
  parse_amendment_actions(actions)

  amdt = {<commit_msg>More specific targeting of orphaned amendments<commit_after>import re, logging, datetime, time, json
from lxml import etree

import utils

from bill_info import sponsor_for, actions_for


# downloads amendment information from THOMAS.gov, 
# parses out basic information, writes JSON to disk

def fetch_amendment(amendment_id, options):
  logging.info("\n[%s] Fetching..." % amendment_id)
  
  body = utils.download(
    amendment_url_for(amendment_id), 
    amendment_cache_for(amendment_id, "information.html"),
    options)

  if not body:
    return {'saved': False, 'ok': False, 'reason': "failed to download"}

  if options.get("download_only", False):
    return {'saved': False, 'ok': True, 'reason': "requested download only"}

  if "Amends:" not in body:
    return {'saved': False, 'ok': True, 'reason': "orphaned amendment"}

  amendment_type, number, congress = utils.split_bill_id(amendment_id)
  
  actions = actions_for(body, amendment_id, is_amendment=True)
  if actions is None: actions = []
  parse_amendment_actions(actions)

  amdt = {
{'fraction_non_alphanumeric': 0.11274014155712841, 'fraction_numerical': 0.0, 'mean_word_length': 4.8898809523809526, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4192224', 'n_tokens_mistral': 645, 'n_tokens_neox': 618, 'n_words': 180}