Exemple #1
0
    def add_or_delete_associations(self):
        '''
            add_or_delete_associations starts the process of reading data from the add and delete
            associations portion of the input data.  This will be used when you want to associate a
            paragraph with another group, for example.  Usually adding a reference will be done in a
            normal update, but if you just forgot to add a reference, this is an easy fix.

            This is called only in Step 3 since it involves changing data in the database

            Throughout much of this process we have constants that drive the input data, directing to
            the correct process
        '''
        for input_key in crud.ASSOCIATION_KEYS:
            if utils.key_not_in_dictionary(self.file_data, input_key):
                continue
            function, data_key = input_key.split('_', 1)
            input_dictionaries = self.prepare_association_data(
                self.file_data[input_key], data_key)
            if function == 'delete':
                self.delete_associations(data_key, input_key,
                                         input_dictionaries)
                json_helper.write_dictionary_to_file(
                    self.file_data[input_key],
                    prefix=scripts.PROD_PROCESS_IND,
                    directory_path=scripts.PROD_INPUT_JSON)
            elif function == 'add':
                self.add_associations(input_key, input_dictionaries)
Exemple #2
0
 def create_json_list_of_records(out_dir, input_data):
     ''' list db record data in json file; records retrieved based on input parameters '''
     key = input_data['params']['key']
     class_ = crud.UPDATE_DATA[key]['class']
     id_list = RecordDictionaryUtility.retrieve_id_list(
         class_, input_data['params']['select_criteria'])
     out_directory = {'directory_path': out_dir}
     dict_output = RecordDictionaryUtility.create_output(
         key, class_, id_list)
     json_helper.write_dictionary_to_file(dict_output, **out_directory)
def run_edit_process():
    ''' Drives updates to the paragraphs with the mistakes and new ideas left by plant screen scraping'''
    file_path = utils.file_path_with_extension(file_paths.INPUT_DIR,
                                               constants.JSON_EXT)
    if file_path is None:
        sys.exit(
            f'No files with extension=={constants.JSON_EXT} in directory: {file_paths.INPUT_DIR}'
        )
    input_data = json_helper.json_to_dict(file_path)
    output_data = loop_through_input_data(input_data)
    params = {'out_json_path': scripts.INPUT_TO_UPDATER_STEP_THREE}
    json_helper.write_dictionary_to_file(output_data, **params)
    def collect_data_and_write_json(self):
        '''
            collect_data_and_write_json is Step 1 of the update process.  It reads the input file,
            which is created manually and passed in by scripts/db_updater_s1 (some input can only
            be passed in as parameters. See documentation in script)

            Step 1 will never be run in production, since data is updated only in development
        '''
        self.process_input_and_output()

        params = {}
        params['directory_path'] = self.input_data['output_directory']
        params[
            'prefix'] = constants.PROD_PROCESS_IND if self.for_prod else constants.DEFAULT_PREFIX
        json_helper.write_dictionary_to_file(self.output_data, **params)
def run():
    '''
        usage as follows:
        >>> python manage.py runscript -v3 csv_to_json_creator

        Example input data, like so:
        [
            {
                'guid': 'd40b2a7a-21a8-4b58-81b2-1beabba8bd6b',
                'group_slug': 'organization-and-documentation, quality-and-maintenance',
                'add_group': 'dev-ops-and-automation',
                'remove_group': ''
            },
        ]

        Creating data with the following format:
        input_data = {
            'add_group_paragraph': [
                {
                    'group_slug': '',
                    'paragraph_guid': ''
                }
            ],
            'delete_group_paragraph': [
                {
                    'group_slug': '',
                    'paragraph_guid': ''
                }
            ]
        }
    '''
    file_data = {
        'add_group_paragraph': [],
        'delete_group_paragraph': []
    }

    list_data = utils.dictionary_list_from_csv(IN_CSV_FILE)

    for data in list_data:
        add = ParagraphDictionaries.group_para_associations(data['guid'],
                                                            data['add_group'])
        file_data['add_group_paragraph'] += add
        delete = ParagraphDictionaries.group_para_associations(data['guid'],
                                                               data['remove_group'])
        file_data['delete_group_paragraph'] += delete

    params = {'out_json_path': OUT_JSON_PATH}
    json_helper.write_dictionary_to_file(file_data, **params)
Exemple #6
0
def one_time_get_content(out_dir):
    ''' fix references to be consistant '''
    list_output = []
    para_ids = []
    references = Reference.objects.all().values()
    out_directory = {'directory_path': out_dir}
    for ref in references:
        link_text = ref['link_text']
        short_text = ref['short_text']
        ref_slug = ref['slug']
        if no_work_required(link_text, short_text):
            continue
        para_ids = add_to_para_id_list_if_necessary(ref_slug, para_ids)
        list_output.append(ref)
    print(f'paras to update== {",".join(para_ids)}')
    json_helper.write_dictionary_to_file(list_output, **out_directory)
Exemple #7
0
 def write_json_file(self):
     ''' write_json_file writes a dictionary to the specified path '''
     params = {'out_json_path': self.path_to_json}
     json_helper.write_dictionary_to_file(self.output_to_json, **params)