<commit_before>import sys
import requests
import json
import csv
from nameparser import HumanName
import req_data as req
import helpers_index as helpers

if len(sys.argv) > 1:
  command = sys.argv[1]
  if command == 'all':
    if len(sys.argv) == 4:
      from_index = sys.argv[2]
      num_records = sys.argv[3]
      if helpers.validate_int(from_index, num_records):
        params = req.create_params(from_index=from_index, num_records=num_records)
        label = helpers.get_csv_label(command=command, from_index=from_index, num_records=num_records)
      else:
        print('Index number and record size must be positive integers.')
        sys.exit()
    else:
      print('Please specify a start index (min 0) and the number of wanted records.')
      sys.exit()
  elif command == 'today':
    params = req.create_params(today=True)
    label = helpers.get_csv_label(command=command)
  elif command == 'custom':
    if len(sys.argv) >= 3:
      custom_date = sys.argv[2]
      if helpers.validate_date(custom_date):
        params = req.create_params(today=True, custom_date=custom_date)
        label = helpers.get_csv_label(command=command, custom_date=custom_date)
      else:
        print('Please input a valid date (yyyy-mm-dd).')
        sys.exit()
    else:
      print('Please specify a date (yyyy-mm-dd).')
      sys.exit()
  else:
    print('Please enter a valid command (all, today, custom).')
    sys.exit()
else:
  command = 'all'
  num_records = 100
  params = req.create_params()
  label = helpers.get_csv_label()

print('Scraping...')

payload = req.get_payload(params)
req_post = requests.post('https://ody.dekalbcountyga.gov/app/JailSearchService/search', json=payload, headers=req.get_headers())
search_results = req_post.json()

inmate_data = list(search_results['searchResult']['hits'])

if len(inmate_data) == 0:
  print('No records found.')
  sys.exit()

with open('./../../../data/dekalb_' + label + '_' + helpers.get_csv_timestamp() + '.csv', 'w', newline='') as new_file:<commit_msg>if/else to try/except<commit_after>import sys
import requests
import json
import csv
from nameparser import HumanName
import req_data as req
import helpers_index as helpers

try:
  command = sys.argv[1]
except IndexError:
  print('Please enter a valid command (all, today, custom).')
  sys.exit()
else:
  if command == 'all':
    try:
      from_index = sys.argv[2]
      num_records = sys.argv[3]
    except IndexError:
      print('Please specify a start index (min 0) and the number of wanted records.')
      sys.exit()
    else:
      try:
        n = int(from_index)
        m = int(num_records)
        if n < 0: raise ValueError
        if m < 0: raise ValueError
      except ValueError:
        print('Index number and record size must be positive integers.')
        sys.exit()
      else:
        params = req.create_params(from_index=from_index, num_records=num_records)
        label = helpers.get_csv_label(command=command, from_index=from_index, num_records=num_records)
  elif command == 'today':
    params = req.create_params(today=True)
    label = helpers.get_csv_label(command=command)
  elif command == 'custom':
    try:
      custom_date = sys.argv[2]
    except IndexError:
      print('Please specify a date (yyyy-mm-dd).')
      sys.exit()
    else:
      try:
        valid = helpers.validate_date(custom_date)
        if not valid: raise Exception
      except Exception:
        print('Please input a valid date (yyyy-mm-dd).')
        sys.exit()
      else:
        params = req.create_params(today=True, custom_date=custom_date)
        label = helpers.get_csv_label(command=command, custom_date=custom_date)
  else:
    print('Please enter a valid command (all, today, custom).')
    sys.exit()

# if len(sys.argv) > 1:
#   command = sys.argv[1]
#   if command == 'all':
#     if len(sys.argv) == 4:
#       from_index = sys.argv[2]
#       num_records = sys.argv[3]
#       if helpers.validate_int(from_index, num_records):
#         params = req.create_params(from_index=from_index, num_records=num_records)
#         label = helpers.get_csv_label(command=command, from_index=from_index, num_records=num_records)
#       else:
#         print('Index number and record size must be positive integers.')
#         sys.exit()
#     else:
#       print('Please specify a start index (min 0) and the number of wanted records.')
#       sys.exit()
#   elif command == 'today':
#     params = req.create_params(today=True)
#     label = helpers.get_csv_label(command=command)
#   elif command == 'custom':
#     if len(sys.argv) >= 3:
#       custom_date = sys.argv[2]
#       if helpers.validate_date(custom_date):
#         params = req.create_params(today=True, custom_date=custom_date)
#         label = helpers.get_csv_label(command=command, custom_date=custom_date)
#       else:
#         print('Please input a valid date (yyyy-mm-dd).')
#         sys.exit()
#     else:
#       print('Please specify a date (yyyy-mm-dd).')
#       sys.exit()
#   else:
#     print('Please enter a valid command (all, today, custom).')
#     sys.exit()
# else:
#   command = 'all'
#   num_records = 100
#   params = req.create_params()
#   label = helpers.get_csv_label()

print('Scraping...')

payload = req.get_payload(params)
req_post = requests.post('https://ody.dekalbcountyga.gov/app/JailSearchService/search', json=payload, headers=req.get_headers())
search_results = req_post.json()

inmate_data = list(search_results['searchResult']['hits'])

if len(inmate_data) == 0:
  print('No records found.')
  sys.exit()

with open('./../../../data/dekalb_' + label + '_' + helpers.get_csv_timestamp() + '.csv', 'w', newline='') as new_file:
{'fraction_non_alphanumeric': 0.13103205353997888, 'fraction_numerical': 0.005459668897499119, 'mean_word_length': 3.25712143928036, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3086882', 'n_tokens_mistral': 1881, 'n_tokens_neox': 1842, 'n_words': 442}