def test_generate_csv_titles(self): """Given some dummy data, check to make sure that the titles are inserted correctly""" test_pub_data = [{'id':101571224, 'type':'research-output', 'attributes':{'title':'Inequality and the Partisan Political Economy', 'identifiers':{'dois':['10.1080/00344893.2021.1883100']}, 'readers':{'mendeley':0}, 'dimensions':{'citations':0}, 'mentions':{'tweet':10, 'wikipedia':1}, 'altmetric-score':9, 'output-type':'article', 'historical-mentions':{'1d':0, '3d':0, '1w':0, '1m':11, '3m':11, '6m':11, '1y':11, 'at':11}, 'publication-date':'2021-03-06', 'badge-url':'https://api.altmetric.com/v1/donut/101571224_240.png', 'oa-status':'false', 'oa-type':'closed', 'institution':{'verified':'true'}}, 'relationships':{'journal':{'id':'4f6fa4d93cf058f61000143d', 'type':'journal'}, 'institutional-authors':[{'id':'cuboulder:person:4758', 'type':'author'}], 'institutional-departments':[{'id':'cuboulder:group:1', 'type':'department'}, {'id':'cuboulder:group:11', 'type':'department'}, {'id':'cuboulder:group:112', 'type':'department'}, {'id':'cuboulder:group:277', 'type':'department'}, {'id':'cuboulder:group:40', 'type':'department'}, {'id':'cuboulder:group:497', 'type':'department'}, {'id':'cuboulder:group:58', 'type':'department'}], 'affiliations':[{'id':'grid.266190.a', 'type':'grid-affiliation'}], 'fields-of-research':[{'id':'16', 'type':'field-of-research'}, {'id':'1606', 'type':'field-of-research'}]}}] test_include_map = {'id': '4f6fa4d93cf058f61000143d', 'title': 'Representation', 'issns': ['00344893', '17494001']} csv_data, _ = api_parser.generate_csv(test_pub_data, test_include_map) test_titles = api_parser.csv_titles() self.assertEqual(csv_data[0], test_titles)
# list of emails to send test emails to. Will only use this list if the 'DEV' environment # variable is set to any value. SEND_DEV_REPORTS_TO_EMAILS = ['*****@*****.**'] # Let's get the email addresses based on our environment EMAILS = gmail.get_emails(SEND_REPORTS_TO_EMAILS, SEND_DEV_REPORTS_TO_EMAILS) # go get our altmetric URL for our department ID ALTMETRIC_URL = altmetric_url(ALTMETRICS_DEPT_ID) # Replace 'Institute of Behavioral Science(IBS)' with the friendly name of your institute or # department if you don't want to see it for every result. DEPARTMENT_EXCLUSIONS = ['Institute of Behavioral Science (IBS)', 'Research Professors', 'Other Faculty Titles', 'Regular Faculty', 'Rostered Tenure Track Faculty', 'Postdocs', 'Organisation'] # Get data from the API and put it into python datastructures for processing PUB_DATA, INCLUDE_MAP = get_altmetric_data(ALTMETRIC_URL, TIMEFRAME_DAYS, DEPARTMENT_EXCLUSIONS) CSV_DATA, EMAIL_DATA = generate_csv(PUB_DATA, INCLUDE_MAP, TIMEFRAME_DAYS, EMAIL_TIMEFRAME_DAYS) # Get the current YYYY-mm-dd date and create a filename out of it DATE = datetime.now().strftime("%Y-%m-%d") FILENAME = 'Altmetric Pubs ' + DATE + '.csv' # Generate the email body in HTML with the data we gathered from the API EMAIL_BODY = generate_body(EMAIL_DATA, EMAIL_TIMEFRAME_DAYS, EMAIL_ADDRESS) def main(email_address, email_friendly_name, email_subject): """Writes the CSV data to the csv file, then opens a connection to gmail and sends the email with that attachment""" with open(FILENAME, 'w', newline='', encoding='utf-8-sig') as csvfile: writer = csv.writer(csvfile) writer.writerows(CSV_DATA) service = gmail.setup()
def test_generate_csv_email_data_two_authors(self): """Given some dummy data with two authors, make sure that they get properly capitalized and output for email data""" test_pub_data = [{'id':101571224, 'type':'research-output', 'attributes':{'title':'Inequality and the Partisan Political Economy', 'identifiers':{'dois':['10.1080/00344893.2021.1883100']}, 'readers':{'mendeley':0}, 'dimensions':{'citations':0}, 'mentions':{'tweet':10, 'wikipedia':1}, 'altmetric-score':9, 'output-type':'article', 'historical-mentions':{'1d':0, '3d':0, '1w':0, '1m':11, '3m':11, '6m':11, '1y':11, 'at':11}, 'publication-date':'2021-03-06', 'badge-url':'https://api.altmetric.com/v1/donut/101571224_240.png', 'oa-status':'false', 'oa-type':'closed', 'institution':{'verified':'true'}}, 'relationships':{'journal':{'id':'4f6fa4d93cf058f61000143d', 'type':'journal'}, 'institutional-authors':[{'id':'cuboulder:person:4758', 'type':'author'}, {'id':'cuboulder:person:12345', 'type':'author'}], 'institutional-departments':[{'id':'cuboulder:group:1', 'type':'department'}, {'id':'cuboulder:group:11', 'type':'department'}, {'id':'cuboulder:group:112', 'type':'department'}, {'id':'cuboulder:group:277', 'type':'department'}, {'id':'cuboulder:group:40', 'type':'department'}, {'id':'cuboulder:group:497', 'type':'department'}, {'id':'cuboulder:group:58', 'type':'department'}], 'affiliations':[{'id':'grid.266190.a', 'type':'grid-affiliation'}], 'fields-of-research':[{'id':'16', 'type':'field-of-research'}, {'id':'1606', 'type':'field-of-research'}]}}] test_include_map = {'4f6fa4d93cf058f61000143d': {'title': 'Representation', 'issns': ['00344893', '17494001']}, 'cuboulder:person:4758': {'name': 'PERSON, Test'}, 'cuboulder:person:12345': {'name': 'TEST, Person'}} _, email_data = api_parser.generate_csv(test_pub_data, test_include_map, 999999, 999999) self.assertEqual(email_data[0], {'Author': 'Person, Test; Test, Person', 'Journal': 'Representation', 'PubDate': datetime.date(2021, 3, 6), 'Title': 'Inequality and the Partisan Political Economy', 'Link': 'https://www.altmetric.com/details/101571224'})