Last active
November 15, 2019 12:57
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def update_num_citations(my_db, cursor): | |
# Get all articles from DB (doi_link is a unique key) | |
sql_get_articles = """SELECT doi_link, citations, last_name FROM authors;""" | |
cursor.execute(sql_get_articles) | |
articles = cursor.fetchall() | |
# Get the updated number of citations (Using requests and BeautifulSoup, open each URL of each doi_link and extract the number of citations) | |
articles_dict = [{'doi_link': articles[ind][0], 'citations': articles[ind][1]} for ind in range(len(authors_no_gen))] | |
articles_dict = get_citations(articles_dict) | |
# Update the data in the DB | |
for doi_link, citations in articles_dict: | |
sql_update = """ UPDATE articles SET citations = {0} WHERE (doi_link = '{1}');""".format(int(citations), doi_link) | |
cursor.execute(sql_update) | |
# The for loop can be replaced with: | |
# cur.executemany("UPDATE articles SET citations = {0} WHERE (doi_link = '{1}');".format(int(citations), doi_link),[--tuples of the data to be updated--]) | |
my_db.commit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment