-
Notifications
You must be signed in to change notification settings - Fork 1
/
dblpSearch.py
76 lines (62 loc) · 1.96 KB
/
dblpSearch.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
64
65
66
67
68
69
70
71
72
73
74
75
import scraps.dblpSearcher as db
import htmlBuilder as hb
import os
import webbrowser
from config import settings
import copy
from utils.path import slugify
# load parameters
PUBLISHERS = settings['publishers']
NUMBER_PER_PUBLISHER = int(settings['number_per_publisher'])
NUMBER_PER_SEARCH = int(settings['number_per_search'])
def get_saving_path(name):
abs_path = 'output/{}.html'.format(name)
abs_path = '{}/{}'.format(os.path.dirname(os.path.realpath(__file__)), abs_path)
abs_path = abs_path.replace('\\', '/')
return abs_path
# print(SAVE_FULL_PATH)
# target = "file:///{}".format(SAVE_FULL_PATH)
def search(terms):
# terms = input("Search for: ")
info_ = None
while True:
m = input("Search by publishers? [y/n]:")
if m == 'y':
info_ = db.search_by_conference(terms, PUBLISHERS, NUMBER_PER_PUBLISHER)
break
elif m == 'n':
info_ = db.search(terms, NUMBER_PER_SEARCH)
break
else:
continue
return info_
def merge_info(info1, info2):
info_ = copy.deepcopy(info1)
# get existed titles in info1
existed_titles = set()
for item in info1:
existed_titles.add(item['title'])
# append unseen info2 items to info1
for item in info2:
title = item['title']
if title not in existed_titles:
info_.append(item)
existed_titles.add(title)
return info_
# search
while True:
terms = [input("Search for: ")]
info = search(terms[-1])
while True:
mode = input("Continue searching for other terms? [y/n]:")
if mode == 'y':
terms.append(input("Search for: "))
info = merge_info(info, search(terms[-1]))
elif mode == 'n':
break
else:
continue
info = db.sort_by_year(info)
save_path = get_saving_path(slugify(terms))
hb.save_as_html(info, save_path, heading=str(terms))
webbrowser.open('file://' + save_path)