-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
executable file
·95 lines (74 loc) · 2.52 KB
/
main.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python3
import argparse
import pandas as pd
from os.path import exists
months = {1:'January', 2:'Feburary', 3:'March', 4:'April', 5:'May', 6:'June', 7:'July',8:'Auguest', 9:'September', 10:'October', 11:'November', 12:'December'}
years = {2021:'2021', 2022:'2022'}
def query(all, keyword, month, year, csv):
index = []
final_df = pd.DataFrame()
if all:
for y in years.values():
for m in months.values():
file_name = 'csv/' +y +' '+m + '.csv'
if not exists(file_name):
# print('No month is in the database')
continue
index = []
df = pd.read_csv(file_name)
for title in df['title']:
try:
if keyword in title:
index.append(df[df['title']==title].index[0])
except:
pass
cur = df.iloc[index]
final_df = final_df.append(cur)
else:
df = pd.read_csv('csv/' + year + ' '+ month + '.csv')
for title in df['title']:
try:
if keyword in title:
index.append(df[df['title']==title].index[0])
except:
pass
final_df = final_df.append(df.iloc[index])
final_df['pdf'] = 'https://openreview.net'+final_df['pdf']
final_df['software'] = 'https://openreview.net' + final_df['software']
final_df['data'] = 'https://openreview.net' + final_df['data']
final_df['forum'] = 'https://openreview.net/forum?id=' + final_df['id']
print(final_df[['title', 'forum']].to_string())
if csv=='Y':
final_df.to_csv('result.csv')
print('saving the result to result.csv')
my_parser = argparse.ArgumentParser(description='Get the related links to the keyword papers')
# ./main.py -year 2021 -month None -keyword Translation
my_parser.add_argument('-year', metavar='(2021-2022) | none = all', type=int, help='Year searching', default=2021)
my_parser.add_argument('-month', metavar='(1-12) | none = all', type=int, help='Month searching', default = None)
my_parser.add_argument('-keyword', metavar='keyword', nargs='+', type=str, help='keyword', required=True)
my_parser.add_argument('-csv', metavar='y or n', type=str, help='save csv')
args = my_parser.parse_args()
all = True
# parse the keyword arg
keyword = ''
if not args.keyword:
print("You didn't input keyword!")
for word in args.keyword:
keyword += word.capitalize() + ' '
# parse the year arg
year = args.year
# parse the month arg
month = ''
if args.month == None:
all = True
else:
all = False
month = months[args.month]
# parse the csv arg
csv = None
if args.csv:
csv = args.csv.capitalize()
else:
csv = None
print('looking for matching result...')
query(all, keyword, month, year, csv)