Skip to content

Commit

Permalink
Merge tag '3685_file_handlers_fix' into develop
Browse files Browse the repository at this point in the history
Fix file handlers in rejected script 3685
  • Loading branch information
Steven-Eardley committed Aug 21, 2023
2 parents 784f495 + 23b21c3 commit 911ded7
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions portality/scripts/applications_rejected_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

APP_FILE_HANDLES = {}
UR_FILE_HANDLES = {}
APP_WRITERS = {}
UR_WRITERS = {}
APP_RECORD_COUNTER = {}
UR_RECORD_COUNTER = {}
BASE_DIR_PATH = None
Expand Down Expand Up @@ -71,14 +73,23 @@ def provenance_query(resource_id):
def get_file_handler(year, application_type):
global APP_FILE_HANDLES
global UR_FILE_HANDLES
global APP_WRITERS
global UR_WRITERS
# applications file handle
if application_type == constants.APPLICATION_TYPE_NEW_APPLICATION:
filename = os.path.join(BASE_DIR_PATH, "rejected_applications_" + str(year) + ".csv")
return csv.writer(APP_FILE_HANDLES.setdefault(year, open(filename, 'w')))
# update requests file handle
if year not in APP_WRITERS:
filename = os.path.join(BASE_DIR_PATH, "rejected_applications_" + str(year) + ".csv")
file_handle = open(filename, 'w')
APP_FILE_HANDLES[year] = file_handle
APP_WRITERS[year] = csv.writer(file_handle)
return APP_WRITERS[year]
else:
filename = os.path.join(BASE_DIR_PATH, "rejected_update_requests_" + str(year) + ".csv")
return csv.writer(UR_FILE_HANDLES.setdefault(year, open(filename, 'w')))
if year not in UR_WRITERS:
filename = os.path.join(BASE_DIR_PATH, "rejected_update_requests_" + str(year) + ".csv")
file_handle = open(filename, 'w')
UR_FILE_HANDLES[year] = file_handle
UR_WRITERS[year] = csv.writer(file_handle)
return UR_WRITERS[year]


def get_record_counter(year, application_type):
Expand Down

0 comments on commit 911ded7

Please sign in to comment.