예제 #1
0
    current_pdf_file_path = sys.argv[1]
    old_generated_JSON_file_path = sys.argv[2]
    new_generated_JSON_file_path = sys.argv[3]

    new_pdf = Pdf(current_pdf_file_path)
    old_json = get_json_from_file(old_generated_JSON_file_path)

    # Exit if PDF file is the same as the last time.
    new_pdf_hash = new_pdf.get_pdf_hash()
    old_pdf_hash = old_json["referenced_pdf_hash"]

    if new_pdf_hash == old_pdf_hash:
        print("PDF file hasn't changed since the last time. Exiting.")
        exit(1)

    new_addresses = new_pdf.get_addresses()
    old_addresses = {Address(**address) for address in old_json["addresses"]}

    # Google Geocoding calls are pretty expensive, so we don't really want to query every address every time.
    addresses_to_be_removed = old_addresses - new_addresses
    addresses_to_be_added = new_addresses - old_addresses

    new_addresses = old_addresses - addresses_to_be_removed
    json_data = {
        "generation_time": str(datetime.now()),
        "referenced_pdf_hash": new_pdf_hash
    }
    for address in addresses_to_be_added:
        address_latlng = geocoder.google(address).latlng
        if address_latlng is None:
            sys.stderr.write("Geocoder returned empty result for address: " +