forked from CenterForOpenScience/cos.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport_json.py
63 lines (53 loc) · 2 KB
/
export_json.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import json
import django
from django.core.exceptions import ObjectDoesNotExist
django.setup()
from common.models import Journal, Organization
import io
def save_to_journal_json(file_name, para_name, file_option):
bulk = []
get_entries = 'Journal.objects.filter(is_' + para_name + '_journal=True)'
entries = eval(get_entries)
if file_option == 1:
for e in entries:
title = e.title
url = e.url_link
notes = []
for i in e.notes.stream_data:
notes.append({'Link': i['value']['link'], 'Description': i['value']['description']})
x = {'Title': title, 'URL': url, 'Notes': notes}
bulk.append(x)
elif file_option == 2:
for e in entries:
x = {"Title": e.title, "Publisher": e.publisher, "Association": e.association, "Subject Area": e.area}
bulk.append(x)
file_path = './cos/static/' + file_name + '.json'
with open(file_path, 'w', encoding='utf8') as data_file:
json.dump(bulk, data_file, indent=1, ensure_ascii=False)
def export_json():
print('Exporting json')
# organization json file
bulk = []
entries = Organization.objects.all()
for e in entries:
x = {'Organization': e.name}
bulk.append(x)
with io.open('./cos/static/toporgs.json', 'w', encoding='utf8') as data_file:
json.dump(bulk, data_file, indent=1, ensure_ascii=False)
print('Finished exporting toporgs.json')
# journal first json file
save_to_journal_json('rrjournals', 'registered', 1)
# second json file
save_to_journal_json('rrjournalssome', 'featured', 1)
# third json file
save_to_journal_json('rrjournalsspecial', 'special', 1)
# fourth json file
save_to_journal_json('preregjournals', 'preregistered', 2)
# fifth json file
save_to_journal_json('topjournals', 'top', 2)
print('Finished exporting journal json files')
print("Completed exporting json")
def main():
export_json()
if __name__ == '__main__':
main()