-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddArticle.py
53 lines (42 loc) · 1.43 KB
/
addArticle.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
import pymongo
from pymongo.collection import Collection
def add_an_article(dblp:Collection):
print('We are now going to ask you a few details to add an article.')
"""Collecting all Ids"""
Ids = []
for x in dblp.find({}, {'id': 1}):
Ids.append(x['id'])
print('So let\'s begin..')
print()
print('------------------------------')
"""Getting Unique Ids from user"""
UniqueId = input('UniqueId: ')
while True:
if UniqueId in Ids:
print('Id is not unique. Enter again')
UniqueId = input('UniqueId: ')
else:
break
"""Input required fields from user """
Title = input('Title: ')
NumofAuthors = int(input('Number of Authors: '))
Authors = []
for i in range(NumofAuthors):
AuthName = input('Authors Name: ')
Authors.append(AuthName)
Year = int(input('Year: '))
Venue = None
Abstract = None
References = []
n_citation = 0
print()
"""Inserting document in the collection"""
try:
mydict = {'abstract': Abstract, 'authors': Authors, 'n_citation': n_citation, 'references': References, 'title': Title, 'venue': Venue, 'year': Year, 'id': UniqueId}
dblp.insert_one(mydict)
except:
pass
else:
print('Successfully inserted a new article in the collection')
print('------------------------------')
print()