def main(): db = Database() db.connect() d = db.get_client_id('Denton', '2009-50481-367', '*****@*****.**') print(d)
def main(): queue = BotQueue() db = Database() db.connect() attorney_searcher = TexasBarSearch() google_extractor = GoogleTextExtractor() emailer = EmailNotifier() processed_path = os.environ.get('processed_path') extractors = { "PDF": google_extractor, "DOCX": google_extractor, "DOC": google_extractor, "RTF": google_extractor, "TXT": google_extractor, } logger_obj = Logger() logger = logger_obj.get_logger(MAIN) parser = TextParser() while True: # Retrieve next item from queue. This call blocks. item = queue.next() # Ensure item is properly constructed if not validate_item(item, logger): queue.finish(item) continue # Extract filename from payload. This is the file we are extracting # text from filename = item["payload"]["filename"] # See if we know now to extract text from this type of file. file_type = filename[filename.rindex(".") + 1:].upper() if file_type not in extractors: logger.debug("Unable to process %s file: %s", file_type, filename) queue.finish(item) continue # We have a handler...use it. extractor = extractors[file_type] logger.debug("Processing %s.", filename) text = extractor.extract(filename) # Parse out the discovery requests logger.debug("Parsing requests from %s.", filename) parser.init(text) requests = parser.discovery_requests() logger.debug("Extracted %s requests from %s", str(len(requests)), filename) # NOQA if requests: if DEBUG: for request in requests: # print("REQUEST {}: {}\n{}\n".format(request["number"], request["request"], "-"*80)) # NOQA pass # stop printing this while we debug other stuff. TJD 2021-03.14 bar_number = parser.oc_bar_number() email_from = get_email(item['payload']['email_from']) doc = { 'court_type': parser.court_type(), 'court_number': parser.court_number(), 'county': parser.county(), 'cause_number': parser.cause_number(), 'discovery_type': parser.discovery_type(), 'owner': email_from, 'server': socket.gethostname(), 'requesting_attorney': { 'bar_number': bar_number, 'email': parser.oc_email(), 'details': attorney_searcher.find(bar_number) }, 'requests': requests, 'item': item, } # Link to client record, if we can find it. client = db.get_client_id(parser.county(), parser.cause_number(), email_from) if client: doc['client_id'] = client['_id'] db.insert_discovery_requests(doc) emailer.reply(doc) if DEBUG: outfile = output_file_name(filename, processed_path) + ".json" # NOQA with open(outfile, "w") as json_file: json.dump(doc, json_file, indent=4, default=json_util.default) # NOQA parser.dump_lines( output_file_name(filename, processed_path) + "_dump.txt") # NOQA # See if we got anything useful if text is not None: # Save extracted text outfile = output_file_name(filename, processed_path) with open(outfile, "w") as text_file: text_file.write(text) queue.finish(item) logger.debug("Processed %s to %s", filename, outfile)