def _convert_files(obj, eng): from invenio_knowledge.api import get_kb_mappings mappings = dict( map( lambda item: (item['key'], item['value']), get_kb_mappings('JOURNALS') ) ) ws = WorldScientific(mappings) target_folder_full = get_storage_path(suffix=target_folder) args = obj.extra_data['args'] # By default, we set the from date as today to_date = args.get("to_date") or datetime.now().strftime('%Y-%m-%d') # By last resort, we set the from date a week before from_date = args.get("from_date") or cache.get(date_key) \ or (datetime.now() - timedelta(days=7)).strftime('%Y-%m-%d') obj.extra_data['args']["to_date"] = to_date obj.extra_data['args']["from_date"] = from_date insert_files = [] filenames = obj.data['extracted_files'] for filename in filenames: date = ws.get_date(filename) if from_date <= date <= to_date: marc = ws.get_record(filename) if marc: filename = basename(filename) filename = join(target_folder_full, filename) insert_files.append(filename) with open(filename, 'w') as outfile: outfile.write(marc) obj.log.info("Converted {0} articles between {1} to {2}".format( len(insert_files), from_date, to_date )) obj.data['insert'] = insert_files obj.data["result_path"] = target_folder_full obj.log.debug("Saved converted files to {0}".format(target_folder_full)) obj.log.debug("{0} files to add".format( len(obj.data["insert"]), ))
def _convert_files(obj, eng): from invenio_knowledge.api import get_kb_mappings mappings = dict( map( lambda item: (item['key'], item['value']), get_kb_mappings('JOURNALS') ) ) ws = WorldScientific(mappings) target_folder_full = get_storage_path(suffix=target_folder) args = obj.extra_data['args'] # By default, we set the from date as today to_date = args.get("to_date") or datetime.now().strftime('%Y-%m-%d') # By last resort, we set the from date months before from_date = args.get("from_date") if not from_date: if args.get("reharvest"): # Since "beginning" of time when not specified from_date = datetime.strptime("1900-01-01", "%Y-%m-%d") else: # Dynamic date in the past when not specified and not reharvest from_date = datetime.now() - timedelta(weeks=weeks_threshold)\ .strftime('%Y-%m-%d') obj.extra_data['args']["to_date"] = to_date obj.extra_data['args']["from_date"] = from_date insert_files = [] if args.get("reharvest"): filenames = obj.data['all_extracted_files'] else: filenames = obj.data['newly_extracted_files'] for filename in filenames: date = ws.get_date(filename) if date is None or (from_date <= date <= to_date): marc = ws.get_record(filename) if marc: filename = basename(filename) filename = join(target_folder_full, filename) insert_files.append(filename) with open(filename, 'w') as outfile: outfile.write(marc) else: obj.log.info("Filtered out {0} ({1})".format(filename, date)) obj.log.info("Converted {0}/{1} articles between {2} to {3}".format( len(insert_files), len(filenames), from_date, to_date )) obj.data['insert'] = insert_files obj.data["result_path"] = target_folder_full obj.log.debug("Saved converted files to {0}".format(target_folder_full)) obj.log.debug("{0} files to add".format( len(obj.data["insert"]), ))
def setUp(self): self.ws = WorldScientific(journal_mappings) self.ws.document = parse(join(dirname(folder), ws_test_record))
class WorldScientificTests(unittest.TestCase): """Test WorldScientific package.""" def setUp(self): self.ws = WorldScientific(journal_mappings) self.ws.document = parse(join(dirname(folder), ws_test_record)) def test_abstract(self): abstract = ( u"<p><roman>CH</roman><sub>3</sub><roman>NH</roman><sub>3</sub><roman>PbX</roman>(<roman>X</roman> = <roman>Br</roman>," u" <roman>I</roman>, <roman>Cl</roman>) perovskites have recently been used as light absorbers in hybrid organic-inorganic" u" solid-state solar cells, with efficiencies above 15%. To date, it is essential to add Lithium bis(Trifluoromethanesulfonyl)Imide" u" (<roman>LiTFSI</roman>) to the hole transport materials (HTM) to get a higher conductivity. However, the detrimental effect of high" u" <roman>LiTFSI</roman> concentration on the charge transport, DOS in the conduction band of the <roman>TiO</roman><sub>2</sub> substrate" u" and device stability results in an overall compromise for a satisfactory device. Using a higher mobility hole conductor to avoid lithium" u" salt is an interesting alternative. Herein, we successfully made an efficient perovskite solar cell by applying a hole conductor PTAA" u" (Poly[bis(4-phenyl) (2,4,6-trimethylphenyl)-amine]) in the absence of <roman>LiTFSI</roman>. Under AM 1.5 illumination of 100 mW/cm<sup>2</sup>," u" an efficiency of 10.9% was achieved, which is comparable to the efficiency of 12.3% with the addition of 1.3 mM <roman>LiTFSI</roman>." u" An unsealed device without <roman>Li</roman><sup>+</sup> shows interestingly a promising stability.</p>" ) self.assertEqual(self.ws._get_abstract(), abstract) def test_journal(self): self.assertEqual(self.ws._get_journal(), 'NANO') def test_publisher(self): self.assertEqual(self.ws._get_publisher(), 'World Scientific Publishing Company') def test_date(self): self.assertEqual(self.ws._get_date(), '2014-06-05') def test_title(self): title = ( u'HIGH-EFFICIENT SOLID-STATE PEROVSKITE SOLAR CELL WITHOUT LITHIUM SALT IN THE HOLE TRANSPORT MATERIAL', '', []) self.assertEqual(self.ws._get_title(), title) def test_doi(self): self.assertEqual(self.ws._get_doi(), u'10.1142/S1793292014400013') def test_page_count(self): self.assertEqual(self.ws._get_page_count(), u'7') def test_authors(self): authors = [ ('Bi, Dongqin', [ 'Department of Chemistry-Angstrom Laboratory, Uppsala University, Box 532, SE 751 20 Uppsala, Sweden' ], [], []), ('Boschloo, Gerrit', [ 'Department of Chemistry-Angstrom Laboratory, Uppsala University, Box 532, SE 751 20 Uppsala, Sweden' ], [], []), ('Hagfeldt, Anders', [ 'Department of Chemistry-Angstrom Laboratory, Uppsala University, Box 532, SE 751 20 Uppsala, Sweden', 'School of Chemical Engineering, Sungkyunkwan University, Suwon 440-746, Korea' ], ['*****@*****.**'], ['for the Belle Collaboration']) ] self.assertEqual(self.ws._get_authors(), authors) def test_pacscodes(self): self.assertEqual(self.ws._get_pacscodes(), []) def test_subject(self): self.assertEqual(self.ws._get_subject(), '') def test_copyright(self): self.assertEqual(self.ws._get_copyright(), ('World Scientific Publishing Company', '2014', '')) def test_publication_information(self): publication_information = ('NANO', '9', '05', '2014', '2014-06-05', u'10.1142/S1793292014400013', '1440001', '', '') self.assertEqual(self.ws._get_publication_information(), publication_information) def test_keywords(self): self.assertEqual( self.ws._get_keywords(), ['Perovskite CH 3 NH 3 PbI 3', 'solar cell', 'lithium']) def test_article_type(self): self.assertEqual(self.ws._get_article_type(), 'research-article') def test_related_article(self): self.ws.document = parse(join(dirname(folder), ws_erratum_test_record)) related_article = '10.1142/S0129183108012303' self.assertEqual(self.ws._get_related_article(), related_article) def test_get_record(self): source_file = join(dirname(folder), ws_test_record) marc_file = join(dirname(folder), ws_output) xml = self.ws.get_record(source_file) with open(marc_file) as marc: result = marc.read() self.assertEqual(xml.strip(), result.strip()) source_file_erratum = join(dirname(folder), ws_erratum_test_record) marc_file_erratum = join(dirname(folder), ws_erratum_output) erratum_xml = self.ws.get_record(source_file_erratum) with open(marc_file_erratum) as marc: result = marc.read() self.assertEqual(erratum_xml.strip(), result.strip())
def setUp(self): self.ws = WorldScientific(journal_mappings) self.ws.document = parse(join(dirname(folder), ws_test_record))
class WorldScientificTests(unittest.TestCase): def setUp(self): self.ws = WorldScientific(journal_mappings) self.ws.document = parse(join(dirname(folder), ws_test_record)) def test_abstract(self): abstract = ( u"<p><roman>CH</roman><sub>3</sub><roman>NH</roman><sub>3</sub><roman>PbX</roman>(<roman>X</roman> = <roman>Br</roman>," u" <roman>I</roman>, <roman>Cl</roman>) perovskites have recently been used as light absorbers in hybrid organic-inorganic" u" solid-state solar cells, with efficiencies above 15%. To date, it is essential to add Lithium bis(Trifluoromethanesulfonyl)Imide" u" (<roman>LiTFSI</roman>) to the hole transport materials (HTM) to get a higher conductivity. However, the detrimental effect of high" u" <roman>LiTFSI</roman> concentration on the charge transport, DOS in the conduction band of the <roman>TiO</roman><sub>2</sub> substrate" u" and device stability results in an overall compromise for a satisfactory device. Using a higher mobility hole conductor to avoid lithium" u" salt is an interesting alternative. Herein, we successfully made an efficient perovskite solar cell by applying a hole conductor PTAA" u" (Poly[bis(4-phenyl) (2,4,6-trimethylphenyl)-amine]) in the absence of <roman>LiTFSI</roman>. Under AM 1.5 illumination of 100 mW/cm<sup>2</sup>," u" an efficiency of 10.9% was achieved, which is comparable to the efficiency of 12.3% with the addition of 1.3 mM <roman>LiTFSI</roman>." u" An unsealed device without <roman>Li</roman><sup>+</sup> shows interestingly a promising stability.</p>") self.assertEqual(self.ws._get_abstract(), abstract) def test_journal(self): self.assertEqual(self.ws._get_journal(), 'NANO') def test_publisher(self): self.assertEqual(self.ws._get_publisher(), 'World Scientific Publishing Company') def test_date(self): self.assertEqual(self.ws._get_date(), '2014-06-05') def test_title(self): title = (u'HIGH-EFFICIENT SOLID-STATE PEROVSKITE SOLAR CELL WITHOUT LITHIUM SALT IN THE HOLE TRANSPORT MATERIAL', '', []) self.assertEqual(self.ws._get_title(), title) def test_doi(self): self.assertEqual(self.ws._get_doi(), u'10.1142/S1793292014400013') def test_page_count(self): self.assertEqual(self.ws._get_page_count(), u'7') def test_authors(self): authors = [('Bi, Dongqin', ['Department of Chemistry-Angstrom Laboratory, Uppsala University, Box 532, SE 751 20 Uppsala, Sweden'], []), ('Boschloo, Gerrit', ['Department of Chemistry-Angstrom Laboratory, Uppsala University, Box 532, SE 751 20 Uppsala, Sweden'], []), ('Hagfeldt, Anders', ['Department of Chemistry-Angstrom Laboratory, Uppsala University, Box 532, SE 751 20 Uppsala, Sweden', 'School of Chemical Engineering, Sungkyunkwan University, Suwon 440-746, Korea'], ['*****@*****.**']) ] self.assertEqual(self.ws._get_authors(), authors) def test_pacscodes(self): self.assertEqual(self.ws._get_pacscodes(), []) def test_subject(self): self.assertEqual(self.ws._get_subject(), '') def test_copyright(self): self.assertEqual(self.ws._get_copyright(), ('World Scientific Publishing Company', '2014', '')) def test_publication_information(self): publication_information = ('NANO', '9', '05', '2014', '2014-06-05', u'10.1142/S1793292014400013', '1440001', '', '') self.assertEqual(self.ws._get_publication_information(), publication_information) def test_keywords(self): self.assertEqual(self.ws._get_keywords(), ['Perovskite CH 3 NH 3 PbI 3', 'solar cell', 'lithium']) def test_article_type(self): self.assertEqual(self.ws._get_article_type(), 'research-article') def test_related_article(self): self.ws.document = parse(join(dirname(folder), ws_erratum_test_record)) related_article = '10.1142/S0129183108012303' self.assertEqual(self.ws._get_related_article(), related_article) def test_get_record(self): source_file = join(dirname(folder), ws_test_record) marc_file = join(dirname(folder), ws_output) with open(marc_file) as marc: result = marc.read() self.assertEqual(self.ws.get_record(source_file), result) source_file_erratum = join(dirname(folder), ws_erratum_test_record) marc_file_erratum = join(dirname(folder), ws_erratum_output) with open(marc_file_erratum) as marc: result = marc.read() self.assertEqual(self.ws.get_record(source_file_erratum), result)