def _parse_movies_from_csv(self, filepath): sys.stdout.write('===== getting movies from CSV\r\n') sys.stdout.flush() file_impex.wait_for_file_to_exist(filepath) with open(filepath, newline='') as input_file: reader = csv.reader(input_file, delimiter=',') next(reader, None) # ignore csv header return [self._convert_csv_row_to_movie(row) for row in reader]
def _parse_movies_from_csv(self, filepath): sys.stdout.write("===== getting movies from CSV\r\n") sys.stdout.flush() file_impex.wait_for_file_to_exist(filepath) with open(filepath, newline="", encoding="UTF-8") as input_file: reader = csv.reader(input_file, delimiter=self.csv_delimiter) headers = next(reader, None) return [self._convert_csv_row_to_movie(headers, row) for row in reader]
def _parse_xml(self): file_impex.wait_for_file_to_exist( os.path.join(self.exports_folder, self.xml_filename)) xml_data = ElementTree.parse( os.path.join(self.exports_folder, self.xml_filename)).getroot() return [ self.convert_xml_node_to_movie(xml_node) for xml_node in xml_data.findall('film') ]
def _rename_csv_file(self): filepath = os.path.join(self.exports_folder, 'ratings.csv') file_impex.wait_for_file_to_exist(filepath) try: os.rename(filepath, os.path.join(self.exports_folder, self.csv_filename)) sys.stdout.write( '\r===== %s: CSV downloaded to %s/%s\r\n' % (self.site.site_name, self.exports_folder, self.csv_filename)) sys.stdout.flush() except FileNotFoundError: sys.stdout.write('\r===== %s: Could not retrieve ratings CSV\r\n' % self.site.site_name) sys.stdout.flush()
def _rename_csv_file(self, original_filename): filepath = os.path.join(self.exports_folder, original_filename) file_impex.wait_for_file_to_exist(filepath) try: os.rename(filepath, os.path.join(self.exports_folder, self.csv_filename)) sys.stdout.write( f"\r===== {self.site.site_displayname}: CSV downloaded to " f"{self.exports_folder}/{self.csv_filename}\r\n" ) sys.stdout.flush() except FileNotFoundError: sys.stdout.write( f"\r===== {self.site.site_displayname}: Could not retrieve ratings CSV\r\n" ) sys.stdout.flush()