In [1]:
from pyzotero import zotero
import datetime
import re
import os
Input the following variables
In [ ]:
api_key = ""
pth = ""
title = ""
pdfname = ''
MyTitle = ''
presenter = ""
email_acc = ""
email_password = "" # warning this is not 'safe'
In [2]:
library_id = 5473189
library_type = "user"
def next_weekday(d, weekday):
days_ahead = weekday - d.weekday()
if days_ahead <= 0: # Target day already happened this week
days_ahead += 7
return d + datetime.timedelta(days_ahead)
d = datetime.datetime.now().date()
next_monday = next_weekday(d, 0) # 0 = Monday, 1=Tuesday, 2=Wednesday...
In [3]:
zot = zotero.Zotero(library_id, library_type, api_key)
query = zot.top(format="json",q=title, limit=7)[0]
title = title.replace('\"','').replace('\'','')
In [4]:
date = next_monday
In [5]:
next_monday = next_monday.strftime("%B %d, %Y")
In [6]:
auths = []
firstauth = query['data']['creators'][0]['lastName']
for creator in query['data']['creators']:
auths+= [creator['firstName'],' ',creator['lastName'],', ']
auths = "".join(auths)[:-2]
In [7]:
abstract = query['data']['abstractNote']
abstract = abstract.encode("windows-1252").decode("utf-8","ignore")
year = re.search("(19[0-9][0-9])|(20[0-1][0-9])|9999$",query['data']['date']).group()#string
url = query['data']['url']
journal = query['data']['publicationTitle']
JCpaperspth = "/journalclub/JCpapers/"+pdfname
In [8]:
contents = "---\nlayout: post\ntitle: {} ({})\ncategory: journalclub\nolddate: {}\n---\n \n*{}*. {} ({}) \n[({})]({})\n[(local cache)]({{{{site.url}}}}{})\n\n#### Abstract\n{}".format(title,year,next_monday,auths,journal,year,journal,url,JCpaperspth,abstract)
print(contents)
In [9]:
with open(os.path.join(pth,"".join([str(date),"-",firstauth,"-",MyTitle,'.md'])), "w") as text_file:
text_file.write(contents)
In [10]:
import smtplib
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
s.login(email_acc, email_password)
Out[10]:
In [11]:
if len(query['data']['creators']) > 1:
firstauth_email=firstauth+" et al"
else:
firstauth_email=firstauth
body ="Dear all,\n Our next Computational Neuroscience Journal Club meeting will be *Monday,{}, at 1:00 pm in the IACS Seminar Room*. {} will be presenting the paper \"{}\" by {}. \n(You can download the paper from the Catnip Lab web page <https://catniplab.github.io/{}/>)\n>{}\n\nSincerely,\nPiotr".format(date.strftime("%b %d"), presenter, title, firstauth_email, "-".join([firstauth,MyTitle]),abstract.replace("\n","\n>"))
In [12]:
to = 'piotr.sokol@stonybrook.edu'
to = 'sbu-computational-neuroscience@googlegroups.com'
In [13]:
sent_from = email_acc
subject = "Comp. Neuroscience Journal Club Meeting on {} at 1:00 PM".format(date.strftime("%b %d"))
In [14]:
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import base64
In [15]:
body_html = """\
Dear all,<div><br></div><div>Our next Computational Neuroscience Journal Club meeting will be <b>Monday, {}, at 1:00 pm in the IACS Seminar Room</b>. {} will be presenting the paper "{}" by {}. (You can download the paper from the Catnip Lab <font color=3D"#1155cc"><a href="https://catniplab.github.io/{}/">web page</a></font>)<div></div></div><blockquote style=3D"margin:0px 0px 0px 40px;border:medium none;padding:0px">
{}
</blockquote>Sincerely, <br>{}""".format(date.strftime("%b %d"), presenter, title, firstauth_email, "-".join([firstauth,MyTitle]),abstract, sender)
In [16]:
import ipywidgets as widgets
from IPython.display import display, HTML
import threading
out = widgets.Output()
display(HTML(body_html))
In [17]:
msg = MIMEMultipart('alternative')
msg['Subject'] = subject
msg['From'] = sent_from
msg['To'] = to
part1 = MIMEText(body, 'plain')
part2 = MIMEText(body_html, 'html')
msg.attach(part1)
msg.attach(part2)
s.sendmail(sent_from, to, msg.as_string())
s.quit()
Out[17]:
In [ ]: