def create_id_filename_old(self, processed_filename, p_from='', p_until=''): """ create_id_filename """ p_from = p_from[0:10] p_until= p_until[0:10] localtime = time.localtime(time.time()) min_month = 3 min_day = 29 max_month = 13 max_day = 32 f = open(processed_filename) excluded_id_list = f.readlines() f.close() d = {} for e in excluded_id_list: e = e.strip("\n") d[e] = '' excluded_id_list = d #print(excluded_id_list) self.display_debug_message('create_id_filename') self.r2id = record2id(self.id_filename) if self.r2id: if p_from=='' and p_until=='': self.display_debug_message('create_id_filename for all') curr_date = str(localtime[0])+'-'+ str(localtime[1])+'-'+ str(localtime[2]) previous='' for year in range(2009, localtime[0]+1): if year > 2009: min_month = 1 min_day = 1 for month in range(min_month, max_month): for day in range(min_day, max_day): curr = str(year) + '-' + format(month) + '-' + format(day) if previous: self.__get_data_and_create_records__(excluded_id_list, previous, curr) if curr_date == previous: max_month=1 max_day=1 previous = curr min_day = 1 min_month=1 else: self.display_debug_message('create_id_filename for ' + p_from+ ' ' + p_until) self.__get_data_and_create_records__(excluded_id_list, p_from, p_until) self.r2id.close_files() else: print('invalid id file')
def create_id_filename(self, processed_filename, p_from, p_until, last_id): """ create_id_filename """ p_from = p_from[0:10] p_until= p_until[0:10] localtime = time.localtime(time.time()) min_month = int(p_from[5:7]) min_day = int(p_from[8:10]) max_month = 13 max_day = 29 self.start_year = int(p_from[0:4])) f = open(processed_filename) excluded_id_list = f.readlines() f.close() d = {} for e in excluded_id_list: d[e.strip("\n")] = '' excluded_id_list = d self.display_debug_message('create_id_filename') self.r2id = record2id(self.id_filename) if self.r2id: self.display_debug_message('create_id_filename (' + p_from +'-' + p_until + ')') curr_day='' for year in range(self.start_year , localtime[0]+1): if year == localtime[0] : max_month = localtime[1]+1 self.display_debug_message( str(year) + ' meses (' + str(min_month) + '-' + str(max_month) + ')' ) for month in range(min_month, max_month): if year == localtime[0] and month==localtime[1]: max_day = localtime[2]+1 self.display_debug_message( str(year) + str(month) + ' days (' + str(min_day) + '-' + str(max_day) + ')' ) for day in range(min_day, max_day): next_day = str(year) + '-' + format(month) + '-' + format(day) if curr_day: self.__get_data_and_create_records__(excluded_id_list, curr_day, next_day) curr_day = next_day min_day = 1 min_month=1 self.r2id.close_files() else: print('invalid id file')
from csv2tag import csv2tag from record2id import record2id input_filename = 'biota-fapesp-FIXED.csv' separator = ';' id_filename = 'biota_fapesp_lildbi' default_content_filename = 'default.seq' convertion_table_filename = "table.seq" dv = {} f = open(default_content_filename,'r') default_values = f.readlines() f.close() for val in default_values: if '|' in val: v = val.split("|") if not v[1]=='': dv[v[0]] = v[1].strip('\n') c2t = csv2tag(convertion_table_filename) records = c2t.convert(input_filename, separator) r2id = record2id(id_filename) for r in records: record = r2id.convert(r, dv) r2id.save(record) r2id.close_files()