forked from bschoenfeld/va-court-scraper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcourt_bulk_task_creator.py
55 lines (46 loc) · 1.45 KB
/
court_bulk_task_creator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from courtreader import readers
from courtutils.logger import get_logger
from datetime import datetime, timedelta
import csv
import os
import sys
import time
MONGO = False
POSTGRES = True
if MONGO:
import pymongo
from courtutils.databases.mongo import MongoDatabase
if POSTGRES:
from courtutils.databases.postgres import PostgresDatabase
# get command line args
start_date = datetime.strptime(sys.argv[1], '%m/%d/%Y')
end_date = datetime.strptime(sys.argv[2], '%m/%d/%Y')
if start_date < end_date:
raise ValueError('Start Date must be after End Date so they decend')
court_type = sys.argv[3]
if court_type != 'circuit' and court_type != 'district':
raise ValueError('Unknown court type')
case_type = sys.argv[4]
if case_type != 'criminal' and case_type != 'civil':
raise ValueError('Unknown case type')
# connect to database
db = None
if MONGO: db = MongoDatabase('va_court_search', court_type)
if POSTGRES: db = PostgresDatabase(court_type)
# get the courts to create tasks for
# check command line args for a specific court
courts = list(db.get_courts())
if len(sys.argv) > 5:
courts = [court for court in courts if court['fips'] == sys.argv[5]]
# create the tasks
tasks = []
for court in courts:
tasks.append({
'fips': court['fips'],
'start_date': start_date,
'end_date': end_date,
'case_type': case_type
})
# add the tasks to the database
db.add_date_tasks(tasks)
print 'Created', len(tasks), 'tasks'