diff options
Diffstat (limited to 'uploader/publications/models.py')
-rw-r--r-- | uploader/publications/models.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/uploader/publications/models.py b/uploader/publications/models.py index 89da06c..e7f197a 100644 --- a/uploader/publications/models.py +++ b/uploader/publications/models.py @@ -13,3 +13,35 @@ def fetch_phenotype_publications( with conn.cursor(cursorclass=DictCursor) as cursor: cursor.execute(query, tuple(item for row in ids for item in row)) return tuple(dict(row) for row in cursor.fetchall()) + + +def create_new_publications(conn, publications) -> dict: + if len(publications) > 0: + with conn.cursor(cursorclass=DictCursor) as cursor: + cursor.executemany( + ("INSERT INTO " + "Publication( " + "PubMed_ID, Abstract, Authors, Title, Journal, Volume, Pages, " + "Month, Year" + ") " + "VALUES(" + "%(pubmed_id)s, %(abstract)s, %(authors)s, %(title)s, " + "%(journal)s, %(volume)s, %(pages)s, %(month)s, %(year)s" + ") " + "ON DUPLICATE KEY UPDATE " + "Abstract=VALUES(Abstract), Authors=VALUES(Authors), " + "Title=VALUES(Title), Journal=VALUES(Journal), " + "Volume=VALUES(Volume), Pages=VALUES(pages), " + "Month=VALUES(Month), Year=VALUES(Year) " + "RETURNING "), + publications) + + paramstr = ", ".join(["%s"] * len(pubmed_ids)) + cursor.execute( + ("SELECT Id, PubMed_ID FROM Publication " + f"WHERE PubMed_ID IN ({paramstr})"), + pubmed_ids) + return { + row["PubMed_ID"]: row["Id"] for row in cursor.fetchall() + } + return {} |