diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2019-07-30 21:29:39 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2019-07-30 21:29:39 -0700 |
commit | 3f3f02bc883b9b6e9cbb565b4734e9febfbe7b4e (patch) | |
tree | 39c2ea982b7ff68ffacaf8333341c14ce96bcc62 /extra | |
parent | 1996b0b95bb1d1f53154e75508688079dd51ada7 (diff) | |
download | fatcat-3f3f02bc883b9b6e9cbb565b4734e9febfbe7b4e.tar.gz fatcat-3f3f02bc883b9b6e9cbb565b4734e9febfbe7b4e.zip |
chocula: json export
Diffstat (limited to 'extra')
-rwxr-xr-x | extra/journal_metadata/chocula.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/extra/journal_metadata/chocula.py b/extra/journal_metadata/chocula.py index 4c50d55e..2dea62c2 100755 --- a/extra/journal_metadata/chocula.py +++ b/extra/journal_metadata/chocula.py @@ -14,6 +14,7 @@ Commands: everything init_db summarize + export index_doaj index_road @@ -1206,6 +1207,19 @@ class ChoculaDatabase(): self.summarize(args) print("### Done with everything!") + def export(self, args): + def dict_factory(cursor, row): + d = {} + for idx, col in enumerate(cursor.description): + d[col[0]] = row[idx] + return d + counts = Counter() + self.db.row_factory = dict_factory + self.c = self.db.cursor() + for row in self.c.execute('SELECT * FROM journal'): + print(json.dumps(row)) + counts['total'] += 1 + def init_db(self, args): print("### Creating Database...") self.db.executescript(""" @@ -1240,6 +1254,9 @@ def main(): sub = subparsers.add_parser('summarize') sub.set_defaults(func='summarize') + sub = subparsers.add_parser('export') + sub.set_defaults(func='export') + # TODO: 'jurn' for ind in ('doaj', 'road', 'crossref', 'entrez', 'norwegian', 'szczepanski', 'ezb', 'gold_oa', 'wikidata', 'openapc'): sub = subparsers.add_parser('index_{}'.format(ind)) |