text stringlengths 1 93.6k |
|---|
# render the recommendations
|
final = '<table>' + ''.join(parts) + '</table>'
|
out = out.replace('__CONTENT__', final)
|
# render the stats
|
num_papers_tagged = len(set().union(*tags.values()))
|
tags_str = ', '.join(['"%s" (%d)' % (t, len(pids)) for t, pids in tags.items()])
|
stats = f"We took the {num_papers_tagged} papers across your {len(tags)} tags ({tags_str}) and \
|
ranked {len(pids)} papers that showed up on arxiv over the last \
|
{args.time_delta} days using tfidf SVMs over paper abstracts. Below are the \
|
top {args.num_recommendations} papers. Remember that the more you tag, \
|
the better this gets:"
|
out = out.replace('__STATS__', stats)
|
# render the account
|
out = out.replace('__ACCOUNT__', user)
|
return out
|
# -----------------------------------------------------------------------------
|
# send the actual html via sendgrid
|
def send_email(to, html):
|
# init the api
|
assert os.path.isfile('sendgrid_api_key.txt')
|
api_key = open('sendgrid_api_key.txt', 'r').read().strip()
|
sg = sendgrid.SendGridAPIClient(api_key=api_key)
|
# construct the email
|
from_email = Email("admin@arxiv-sanity-lite.com")
|
to_email = To(to)
|
subject = tnow_str + " Arxiv Sanity Lite recommendations"
|
content = Content("text/html", html)
|
mail = Mail(from_email, to_email, subject, content)
|
# hope for the best :)
|
if not args.dry_run:
|
response = sg.client.mail.send.post(request_body=mail.get())
|
print(response.status_code)
|
pass
|
# -----------------------------------------------------------------------------
|
if __name__ == "__main__":
|
parser = argparse.ArgumentParser(description='Sends emails with recommendations')
|
parser.add_argument('-n', '--num-recommendations', type=int, default=20, help='number of recommendations to send per person')
|
parser.add_argument('-t', '--time-delta', type=int, default=3, help='how recent papers to recommended, in days')
|
parser.add_argument('-d', '--dry-run', type=int, default=0, help='if set to 1 do not actually send the emails')
|
parser.add_argument('-u', '--user', type=str, default='', help='restrict recommendations only to a single given user (used for debugging)')
|
parser.add_argument('-m', '--min-papers', type=int, default=1, help='user must have at least this many papers for us to send recommendations')
|
args = parser.parse_args()
|
print(args)
|
tnow = time.time()
|
tnow_str = time.strftime('%b %d', time.localtime(tnow)) # e.g. "Nov 27"
|
# read entire db simply into RAM
|
with get_tags_db() as tags_db:
|
tags = {k:v for k,v in tags_db.items()}
|
# read entire db simply into RAM
|
with get_metas_db() as mdb:
|
metas = {k:v for k,v in mdb.items()}
|
# read entire db simply into RAM
|
with get_email_db() as edb:
|
emails = {k:v for k,v in edb.items()}
|
# read tfidf features into RAM
|
features = load_features()
|
# keep the papers as only a handle, since this can be larger
|
pdb = get_papers_db()
|
# iterate all users, create recommendations, send emails
|
num_sent = 0
|
for user, tags in tags.items():
|
# verify that we have an email for this user
|
email = emails.get(user, None)
|
if not email:
|
print("skipping user %s, no email" % (user, ))
|
continue
|
if args.user and user != args.user:
|
print("skipping user %s, not %s" % (user, args.user))
|
continue
|
# verify that we have at least one positive example...
|
num_papers_tagged = len(set().union(*tags.values()))
|
if num_papers_tagged < args.min_papers:
|
print("skipping user %s, only has %d papers tagged" % (user, num_papers_tagged))
|
continue
|
# insert a fake entry in tags for the special "all" tag, which is the union of all papers
|
# tags['all'] = set().union(*tags.values())
|
# calculate the recommendations
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.