-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from ror-community/separate-address-update
Separate address update
- Loading branch information
Showing
9 changed files
with
51 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
requests==2.27.1 | ||
update_address @ git+https://github.com/ror-community/update_address.git | ||
requests==2.27.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
requests==2.27.1 | ||
update_address @ git+https://github.com/ror-community/update_address.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,4 @@ | ||
import os | ||
import sys | ||
import json | ||
import re | ||
import glob | ||
import update_address | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,2 @@ | ||
certifi==2021.10.8 | ||
charset-normalizer==2.0.11 | ||
idna==3.3 | ||
requests==2.27.1 | ||
urllib3==1.26.8 | ||
update_address @ git+https://github.com/ror-community/update_address.git | ||
update_address @ git+https://github.com/ror-community@add-caching/update_address.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import os | ||
import json | ||
import logging | ||
import sys | ||
sys.path.append('/Users/ekrznarich/git/update_address') | ||
import update_address | ||
|
||
RECORDS_PATH = "." | ||
ERROR_LOG = "address_update_errors.log" | ||
logging.basicConfig(filename=ERROR_LOG,level=logging.ERROR, filemode='w') | ||
|
||
def export_json(json_data, json_file): | ||
json_file.seek(0) | ||
json.dump(json_data, json_file, ensure_ascii=False, indent=2) | ||
json_file.truncate() | ||
|
||
def get_files(top): | ||
filepaths = [] | ||
for dirpath, dirs, files in os.walk(top, topdown=True): | ||
for file in files: | ||
filepaths.append(os.path.join(dirpath, file)) | ||
return filepaths | ||
|
||
def update_addresses(filepaths): | ||
for filepath in filepaths: | ||
filename, file_extension = os.path.splitext(filepath) | ||
if file_extension == '.json': | ||
try: | ||
with open(filepath, 'r+') as json_in: | ||
print("updating " + filepath) | ||
json_data = json.load(json_in) | ||
json_data = update_address.update_geonames(json_data) | ||
export_json(json_data, json_in) | ||
except Exception as e: | ||
logging.error(f"Writing {filepath}: {e}") | ||
|
||
if __name__ == '__main__': | ||
update_addresses(get_files(RECORDS_PATH)) | ||
file_size = os.path.getsize(ERROR_LOG) | ||
if (file_size == 0): | ||
os.remove(ERROR_LOG) | ||
elif (file_size != 0): | ||
print("ERRORS RECORDED IN address_update_errors.log") | ||
with open(ERROR_LOG, 'r') as f: | ||
print(f.read()) | ||
sys.exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
requests==2.27.1 | ||
update_address @ git+https://github.com/ror-community/update_address.git | ||
requests==2.27.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters