Skip to content

Commit

Permalink
Merge pull request #2 from LSSTDESC/cmu_meeting
Browse files Browse the repository at this point in the history
Script to automatically generate badges from registration database
  • Loading branch information
EiffL authored Jul 15, 2022
2 parents 9f132d2 + ff96243 commit 4ce01fd
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,6 @@ TSWLatexianTemp*

# KBibTeX
*~[0-9]*

db_secret
latex/*
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@ You can preview how your badge would look like [on this page](https://lsstdesc.g
Leave the `boxed` option on to see how the badges would look like.


## Automated badge generation from registration database

We provide a script that can automagically query the registration database from
the [meetings-registration-form](https://github.com/LSSTDESC/meeting-registration-form)
repository to generate a `participants.tex` file.
To install the `sqlalchemy` requirement:
```
$ pip install sqlalchemy
```
Then copy the secret heroku database URL from the settings tab of the Heroku service
into a `db_secret` file at the root of this repo. Be careful not to commit or share this
file!
Finally, run the following command at the root of this repo:
```
$ python badges_from_db.py
```
And that's it, you now have a `participants.tex` file in the `latex` folder, ready to be
processed.


## Contributers

This template is designed and implemented by [Yao-Yuan Mao](https://yymao.github.io),
Expand Down
59 changes: 59 additions & 0 deletions badges_from_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env
from sqlalchemy import *
from io import open
from string import Template

with open('db_secret', encoding="utf-8") as f:
DATABASE_URL = f.read()

db = create_engine(DATABASE_URL)

# Last name of locals
list_of_locals = ['Kirk', 'McCoy']
list_of_locals = [n.lower() for n in list_of_locals]

# Last name of contact persons
list_of_contacts = ['Spock', 'Kirk']
list_of_contacts = [n.lower() for n in list_of_contacts]

# Email of people who have used the wrong slot for their last name
list_of_inverse_behavior = ['[email protected]']

sql_query = "select lname, sname, first_name, last_name, affiliation, pronoun, email from participants"
temp = Template('\participant{ $lname }{ $sname }{ $affiliation }{ $pronoun }{ $highlight }\n')

with open('latex/participants.tex', 'w', encoding="utf-8")as f:
for lname, sname, first_name, last_name, affiliation, pronoun, email in db.engine.execute(sql_query).fetchall():

# Defaulting for people who did not provide a preference
if email in list_of_inverse_behavior:
if lname == '':
lname = first_name
if sname == '':
sname = last_name
else:
if lname == '' and sname == '':
lname = first_name
sname = last_name

# Removing pronoun if blank space provided
if len(pronoun) < 2:
print('Warning, setting %s pronoun to empty'%pronoun)
pronoun = ''

# if in the list of locals, add flag
if last_name.lower() in list_of_contacts:
highlight = '\\contact'
elif last_name.lower() in list_of_locals:
highlight = '\\local'
else:
highlight = ''

s = temp.substitute(lname=lname, sname=sname, affiliation=affiliation,
pronoun=pronoun, highlight=highlight)

# Escaping problematic characters
s = s.replace('&', '\&')
#s = s.replace('@', '\@')
s = s.replace('_', '\_')
f.write(s)
32 changes: 14 additions & 18 deletions latex/main.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@

%% To include CJK character, one needs to use xelatex to compile
%% and also to have a CJK font installed (current set to `Noto Sans CJK TC`)
%% Otherwise, comment out the following two lines.
%% Otherwise, comment out the following two lines.
%\usepackage{xeCJK}
%\setCJKmainfont{Noto Sans CJK TC}

%% basic font settings
\usepackage[T1]{fontenc}
\usepackage[T1]{fontenc}
\usepackage[default]{raleway}
\providecommand{\raleway}{} % in case we are not using xeLaTex
\newcommand*{\latinfont}{\raleway}
\hyphenpenalty=10000

%% essential packages
\usepackage[boxed]{ticket} %when ready to print, remove the "boxed" option
\usepackage[usenames]{xcolor}
\usepackage[boxed]{ticket} %Remove the [boxed] option to remove the badge boundary for printing
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{graphicx} % provides \includegraphics
\usepackage{adjustbox} % provides \maxsizebox
\usepackage{adjustbox} % provides \maxsizebox

%% to use colored text for highlighting
\newcommand*{\highlight}{\textcolor}
%% OR, to use contour for highlighting, uncomment below
%\usepackage[outline]{contour}
%\usepackage[outline]{contour}
%\contourlength{5pt}
%\newcommand*{\highlight}{\contour}

Expand All @@ -36,7 +36,7 @@

%% page setting, currently set to match Avery Name Badges #74459
\hoffset=-0.75in %adjusting page margin
\voffset=-0.125in %adjusting page margin
\voffset=-0.125in %adjusting page margin
\unitlength=0.01in
\ticketSize{400}{300} % in unitlength
\ticketDistance{0}{0} %in unitlength
Expand All @@ -46,8 +46,8 @@
\renewcommand*{\ticketdefault}{%
\put(10,2){\lbox{\includegraphics[width=1in]{desc-logo}}}%
\put(380,14){\rbox{\includegraphics[width=0.7in]{lsstc-logo}}}%
\put(205,29){\cbox{\latinfont\scriptsize Collaboration Meeting, Feb.~5--9, 2018}}%
\put(205,15){\cbox{\latinfont\scriptsize SLAC National Accelerator Laboratory}}%
\put(205,29){\cbox{\latinfont\scriptsize Collaboration Meeting, July.~23--27, 2018}}% Update dates as needed
\put(205,15){\cbox{\latinfont\scriptsize Carnegie Mellon University}}% Update location as needed
}

%% participant style setting
Expand All @@ -63,22 +63,18 @@

%% local people or other highlight commands
\newcommand*{\local}{\highlight{orange}}
\newcommand*{\contact}{\highlight{CornflowerBlue}}

%% backside printing (comment out for front side)
%\hoffset=1.1in
%\backside

%% backside printing (comment out for front side)
\hoffset=1.1in
\backside

\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% insert below the participant list
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\participant{Large-font Name}{Small-font Name}{Affiliation}{Pronoun}{}
\participant{Uhura}{Nyota Uhura}{Starfleet}{she/human}{}
\emptyticket{}
\participant{Jim}{Kirk}{Starfleet}{he}{\local}
\participant{Bones}{Leonard McCoy}{Starfleet}{he/Doctor}{}
\emptyticket{}
\include{participants}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% end of the participant list
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down
6 changes: 6 additions & 0 deletions latex/participants.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
\participant{Large-font Name}{Small-font Name}{Affiliation}{Pronoun}{}
\participant{Uhura}{Nyota Uhura}{Starfleet}{she/human}{}
\emptyticket{}
\participant{Jim}{Kirk}{Starfleet}{he}{\local}
\participant{Bones}{Leonard McCoy}{Starfleet}{he/Doctor}{\contact}
\emptyticket{}

0 comments on commit 4ce01fd

Please sign in to comment.