diff --git a/smash/import_file.py b/smash/import_file.py index 3b71e0322b2ba601ca22177d00e99089356fabb4..d3a2e78cadb86978fc3b2c7d1dd4aa66d59160be 100644 --- a/smash/import_file.py +++ b/smash/import_file.py @@ -1,3 +1,4 @@ +# coding=utf-8 import os import django from django.conf import settings @@ -37,7 +38,7 @@ def indexof(element, l): ''' -#Â Things that *could* already be on the database: +# Things that *could* already be on the database: - Language - Country @@ -310,7 +311,7 @@ def parse_row(index, row, visit_columns, appointmentTypes, voucher_types): country.save() # Location and Flying Team - #Â If no FT, then default location is CHL + # If no FT, then default location is CHL ft = None location = None if not row['FLYING TEAM (FT)']: @@ -438,7 +439,7 @@ def parse_row(index, row, visit_columns, appointmentTypes, voucher_types): for visit_date in set(visit_dates): datetime_when = visit_date.strftime('%Y-%m-%d') - # Â get the indices of each occurrence of the date and use them to get + # get the indices of each occurrence of the date and use them to get # the appointment types appointment_types = itembetter( indexof(visit_date, visit_dates), appointmentTypes) @@ -461,7 +462,13 @@ def parse_row(index, row, visit_columns, appointmentTypes, voucher_types): if __name__ == '__main__': logging.basicConfig(level=logging.DEBUG) - file = '/Users/carlos.vega/ownCloud/Documents/Projects/PDP/copy.xlsx' + if len(sys.argv) < 2: + logging.warn('Please, execute the program as: python {} file_path.xlsx'.format(sys.argv[0])) + sys.exit(1) + file = sys.argv[1] + if not os.path.isfile(file): + logging.warn('Please, execute the program with a valid file path.') + sys.exit(1) df = pd.read_excel(file, dtype=object) df = df.fillna('').astype(unicode) df.columns = [c.upper() for c in df.columns] @@ -471,7 +478,7 @@ if __name__ == '__main__': df[column] = df[column].apply(function) # get visits columns regex = re.compile(r'\(V\d\)') - #Â + # study = Study.objects.filter(id=GLOBAL_STUDY_ID)[0] #enable vouchers study.columns.voucher_types = True