def update_links_and_ffts(self):
figure_counter = <NUM_LIT:0><EOL>for field in record_get_field_instances(self.record,<EOL>tag='<STR_LIT>',<EOL>ind1='<STR_LIT:4>'):<EOL><INDENT>subs = field_get_subfields(field)<EOL>newsubs = []<EOL>remove = False<EOL>if '<STR_LIT:z>' in subs:<EOL><INDENT>is_figure = [s for s in subs['<STR_LIT:z>'] if "<STR_LIT>" in s.lower()]<EOL>if is_figure and '<STR_LIT:u>' in subs:<EOL><INDENT>is_subformat = [<EOL>s for s in subs['<STR_LIT:u>'] if "<STR_LIT>" in s.lower()]<EOL>if not is_subformat:<EOL><INDENT>url = subs['<STR_LIT:u>'][<NUM_LIT:0>]<EOL>if url.endswith("<STR_LIT>"):<EOL><INDENT>fd, local_url = mkstemp(suffix=os.path.basename(url))<EOL>os.close(fd)<EOL>self.logger.info(<EOL>"<STR_LIT>" % (url, local_url))<EOL>plotfile = "<STR_LIT>"<EOL>try:<EOL><INDENT>plotfile = download_file(url=url,<EOL>download_to_file=local_url)<EOL><DEDENT>except Exception as e:<EOL><INDENT>self.logger.exception(e)<EOL>remove = True<EOL><DEDENT>if plotfile:<EOL><INDENT>converted = convert_images([plotfile])<EOL>if converted:<EOL><INDENT>url = converted.pop()<EOL>msg = "<STR_LIT>"% (local_url, url)<EOL>self.logger.info(msg)<EOL><DEDENT>else:<EOL><INDENT>msg = "<STR_LIT>"% (local_url,)<EOL>self.logger.error(msg)<EOL>url = None<EOL>remove = True<EOL><DEDENT><DEDENT><DEDENT>if url:<EOL><INDENT>newsubs.append(('<STR_LIT:a>', url))<EOL>newsubs.append(('<STR_LIT:t>', '<STR_LIT>'))<EOL>figure_counter += <NUM_LIT:1><EOL>if '<STR_LIT:y>' in subs:<EOL><INDENT>newsubs.append(<EOL>('<STR_LIT:d>', "<STR_LIT>" % (figure_counter, subs['<STR_LIT:y>'][<NUM_LIT:0>])))<EOL>newsubs.append(('<STR_LIT:n>', subs['<STR_LIT:y>'][<NUM_LIT:0>]))<EOL><DEDENT>else:<EOL><INDENT>name = os.path.basename(<EOL>os.path.splitext(subs['<STR_LIT:u>'][<NUM_LIT:0>])[<NUM_LIT:0>])<EOL>newsubs.append(<EOL>('<STR_LIT:d>', "<STR_LIT>" % (figure_counter, name)))<EOL>newsubs.append(('<STR_LIT:n>', name))<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>if not newsubs and '<STR_LIT:u>' in subs:<EOL><INDENT>is_fulltext = [s for s in subs['<STR_LIT:u>'] if "<STR_LIT>" in s]<EOL>if is_fulltext:<EOL><INDENT>newsubs = [('<STR_LIT:t>', '<STR_LIT>'), ('<STR_LIT:a>', subs['<STR_LIT:u>'][<NUM_LIT:0>])]<EOL><DEDENT><DEDENT>if not newsubs and '<STR_LIT:u>' in subs:<EOL><INDENT>remove = True<EOL>is_zipfile = [s for s in subs['<STR_LIT:u>'] if "<STR_LIT>" in s]<EOL>if is_zipfile:<EOL><INDENT>url = is_zipfile[<NUM_LIT:0>]<EOL>local_url = os.path.join(self.get_local_folder(), os.path.basename(url))<EOL>self.logger.info("<STR_LIT>" %<EOL>(url, local_url))<EOL>zipped_archive = "<STR_LIT>"<EOL>try:<EOL><INDENT>zipped_archive = download_file(url=is_zipfile[<NUM_LIT:0>],<EOL>download_to_file=local_url)<EOL><DEDENT>except Exception as e:<EOL><INDENT>self.logger.exception(e)<EOL>remove = True<EOL><DEDENT>if zipped_archive:<EOL><INDENT>unzipped_archive = unzip(zipped_archive)<EOL>list_of_pngs = locate("<STR_LIT>", unzipped_archive)<EOL>for png in list_of_pngs:<EOL><INDENT>if "<STR_LIT>" in png or "<STR_LIT>" in png:<EOL><INDENT>continue<EOL><DEDENT>figure_counter += <NUM_LIT:1><EOL>plotsubs = []<EOL>plotsubs.append(('<STR_LIT:a>', png))<EOL>caption = '<STR_LIT>' % (<EOL>figure_counter, os.path.basename(png))<EOL>plotsubs.append(('<STR_LIT:d>', caption))<EOL>plotsubs.append(('<STR_LIT:t>', '<STR_LIT>'))<EOL>record_add_field(<EOL>self.record, '<STR_LIT>', subfields=plotsubs)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>if not remove and not newsubs and '<STR_LIT:u>' in subs:<EOL><INDENT>urls = ('<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>')<EOL>for val in subs['<STR_LIT:u>']:<EOL><INDENT>if any(url in val for url in urls):<EOL><INDENT>remove = True<EOL>break<EOL><DEDENT>if val.endswith('<STR_LIT>'):<EOL><INDENT>remove = True<EOL><DEDENT><DEDENT><DEDENT>if newsubs:<EOL><INDENT>record_add_field(self.record, '<STR_LIT>', subfields=newsubs)<EOL>remove = True<EOL><DEDENT>if remove:<EOL><INDENT>record_delete_field(self.record, '<STR_LIT>', ind1='<STR_LIT:4>',<EOL>field_position_global=field[<NUM_LIT:4>])<EOL><DEDENT><DEDENT>
FFT (856) Dealing with graphs.