Skip to content
Snippets Groups Projects
Commit bc5b0bf5 authored by nicolas.ollinger's avatar nicolas.ollinger
Browse files

fetch by Title

parent 25226511
Branches sjr
No related tags found
No related merge requests found
......@@ -7,6 +7,17 @@ from tqdm import tqdm
SCIMAGOURL = "https://www.scimagojr.com/journalrank.php?year={}&type=j&out=xls"
def fetchifneeded(f):
def wrapper(self, year, *args):
res = f(self, year, *args)
if res is None and not self.fetched(year):
self.fetch_scimago_year(year)
res = f(self, year, *args)
return res
return wrapper
class SJR:
def __init__(self, database):
self.con = sqlite3.connect(database)
......@@ -33,18 +44,19 @@ class SJR:
(title, issn, year, quartiles),
)
def raw_by_ISSN(self, issn, year):
@fetchifneeded
def by_ISSN(self, year, issn):
self.cursor.execute(
"SELECT * FROM sjr_journals WHERE ISSN=? AND Year=?", (issn, year)
)
return self.cursor.fetchone()
def by_ISSN(self, issn, year):
res = self.raw_by_ISSN(issn, year)
if res is None and not self.fetched(year):
self.fetch_scimago_year(year)
res = self.raw_by_ISSN(issn, year)
return res
@fetchifneeded
def by_Title(self, year, title):
self.cursor.execute(
"SELECT * FROM sjr_journals WHERE Title=? AND Year=?", (title, year)
)
return self.cursor.fetchone()
def fetched(self, year):
self.cursor.execute("SELECT Year FROM fetched WHERE Year=?", (year,))
......@@ -84,13 +96,15 @@ class SJR:
if __name__ == "__main__":
sjr = SJR("/tmp/lapin.db")
print("** A few rankings\n")
for pair in [("25206508", 2020), ("00045411", 2018)]:
for pair in [(2020, "25206508"), (2018, "00045411")]:
print(" ", "; ".join(map(str, sjr.by_ISSN(*pair))))
for pair in [(2020, "Journal of the ACM")]:
print(" ", "; ".join(map(str, sjr.by_Title(*pair))))
print("\n** Evolution from 2019 to 2021\n")
for issn in ["10902724", "03043975", "14627264", "22105379", "00045411"]:
q = []
for year in [2019, 2020, 2021]:
res = sjr.by_ISSN(issn, year)
res = sjr.by_ISSN(year, issn)
title = res[0]
q.append(res[3])
print(f" {title}: {', '.join(q)}")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment