-
Notifications
You must be signed in to change notification settings - Fork 9
/
gca-cat
executable file
·37 lines (28 loc) · 1.03 KB
/
gca-cat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
import argparse
import codecs
import sys
from gca.core import Abstract
from collections import OrderedDict
class LastUpdatedOrderedDict(OrderedDict):
'''Store items in the order the keys were last added'''
def __setitem__(self, key, value):
if key in self:
del self[key]
OrderedDict.__setitem__(self, key, value)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='GCA Filter - filter list of abstract by files')
parser.add_argument('files', type=str, nargs='+')
args = parser.parse_args()
abstracts = LastUpdatedOrderedDict()
for f in args.files:
fd = codecs.open(f, 'r', encoding='utf-8') if f != '-' else sys.stdin
for a in Abstract.from_data(fd.read()):
abstracts[a.uuid] = a
fd.close()
abstracts = [a for a in abstracts.values()]
data = Abstract.to_json(abstracts)
sys.stdout.write(data)