-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_gen.py
51 lines (42 loc) · 1.26 KB
/
file_gen.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
"""
I need
authors name
Title
Full title
Keywords
Year
Abstract
"""
import xml.etree.ElementTree as ET
tree = ET.parse('beautify.xml')
root = tree.getroot()
for i,record in enumerate(root.iter('record')):
# Author
a_name = []
for author in record.iter('author'):
a_name.append(author.text)
print (a_name)
# Title
title = record.find('titles').find('title').text
#Full Title
full_title = record.find('periodical').find('full-title').text
# Keyword
key = []
for keyword in record.iter('keyword'):
key.append(keyword.text)
print(key)
# Year
year = record.find('dates').find('year').text
# Abstract
if record.find('abstract') is None:
abstract = 'NO ABSTRACT FOUND'
else:
abstract = record.find('abstract').text
file_name = str(i+1)+"."+title+","+ year+".txt"
output = open(file_name,"w")
output.write("Name of authors:-\n%s\n\nTitle:-\n%s\n\nFull Title:-\n%s\n\nKeywords:-\n%s\n\nYear:-\n%s\n\nAbstract:-\n%s"%
("".join(a_name),title,full_title,"".join(key),year,abstract))
print("Name of authors:-\n%s\n\nTitle:-\n%s\n\nFull Title:-\n%s\n\nKeywords:-\n%s\n\nYear:-\n%s\n\nAbstract:-\n%s"%
("".join(a_name),title,full_title,"".join(key),year,abstract))
output.close()
print ('\n----------------------------------------------------------------\n')