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

fetch by Title

parent 25226511
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,17 @@ from tqdm import tqdm ...@@ -7,6 +7,17 @@ from tqdm import tqdm
SCIMAGOURL = "https://www.scimagojr.com/journalrank.php?year={}&type=j&out=xls" 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: class SJR:
def __init__(self, database): def __init__(self, database):
self.con = sqlite3.connect(database) self.con = sqlite3.connect(database)
...@@ -33,18 +44,19 @@ class SJR: ...@@ -33,18 +44,19 @@ class SJR:
(title, issn, year, quartiles), (title, issn, year, quartiles),
) )
def raw_by_ISSN(self, issn, year): @fetchifneeded
def by_ISSN(self, year, issn):
self.cursor.execute( self.cursor.execute(
"SELECT * FROM sjr_journals WHERE ISSN=? AND Year=?", (issn, year) "SELECT * FROM sjr_journals WHERE ISSN=? AND Year=?", (issn, year)
) )
return self.cursor.fetchone() return self.cursor.fetchone()
def by_ISSN(self, issn, year): @fetchifneeded
res = self.raw_by_ISSN(issn, year) def by_Title(self, year, title):
if res is None and not self.fetched(year): self.cursor.execute(
self.fetch_scimago_year(year) "SELECT * FROM sjr_journals WHERE Title=? AND Year=?", (title, year)
res = self.raw_by_ISSN(issn, year) )
return res return self.cursor.fetchone()
def fetched(self, year): def fetched(self, year):
self.cursor.execute("SELECT Year FROM fetched WHERE Year=?", (year,)) self.cursor.execute("SELECT Year FROM fetched WHERE Year=?", (year,))
...@@ -84,13 +96,15 @@ class SJR: ...@@ -84,13 +96,15 @@ class SJR:
if __name__ == "__main__": if __name__ == "__main__":
sjr = SJR("/tmp/lapin.db") sjr = SJR("/tmp/lapin.db")
print("** A few rankings\n") 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)))) 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") print("\n** Evolution from 2019 to 2021\n")
for issn in ["10902724", "03043975", "14627264", "22105379", "00045411"]: for issn in ["10902724", "03043975", "14627264", "22105379", "00045411"]:
q = [] q = []
for year in [2019, 2020, 2021]: for year in [2019, 2020, 2021]:
res = sjr.by_ISSN(issn, year) res = sjr.by_ISSN(year, issn)
title = res[0] title = res[0]
q.append(res[3]) q.append(res[3])
print(f" {title}: {', '.join(q)}") 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