Last active
August 29, 2015 14:07
-
-
Save agmarrugo/5dfb2fcea52f408429fe to your computer and use it in GitHub Desktop.
Generate acceptance letters for a list of papers downloaded from Easy Chair
This file contains hidden or 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
# This Python file uses the following encoding: utf-8 | |
import re, subprocess, os, shlex | |
from string import Template | |
class REMatcher(object): | |
def __init__(self, matchstring): | |
self.matchstring = matchstring | |
def match(self,regexp): | |
self.rematch = re.match(regexp, self.matchstring) | |
return bool(self.rematch) | |
def group(self,i): | |
return self.rematch.group(i) | |
def getFileList(path): | |
# Returns a list of filenames for all text files in directory | |
return [os.path.join(path,f) for f in os.listdir(path) if f.endswith('.txt')] | |
def superWrite(filename,content): | |
try: | |
if not os.path.exists(os.path.dirname(filename)): | |
os.makedirs(os.path.dirname(filename)) | |
with open(filename, "w") as f: | |
f.write(content) | |
return True | |
except: | |
print "Could not write file" | |
latex_source=Template(r'''\documentclass{article} | |
\usepackage[spanish,es-tabla]{babel} | |
\usepackage[utf8]{inputenc} | |
\usepackage{graphicx} | |
\usepackage{newunicodechar} | |
\newunicodechar{fi}{fi} | |
\usepackage{fancyhdr} | |
\pagestyle{fancy} | |
\renewcommand{\headrulewidth}{0pt} | |
\renewcommand{\footrulewidth}{0pt} | |
\setlength\headheight{100.0pt} | |
\addtolength{\textheight}{-80.0pt} | |
\chead{\includegraphics[width=\textwidth]{logo-ciima-2014-words-2.png}} | |
\usepackage[percent]{overpic} | |
\begin{document} | |
\pagenumbering{gobble} | |
\begin{center} | |
\huge\textbf{CARTA DE ACEPTACIÓN} | |
\end{center} | |
\begin{center} | |
III Congreso Internacional de Ingeniería Mecatrónica y Automatización \\ | |
Cartagena de Indias, Colombia, octubre 22 al 24 de 2014. | |
\end{center} | |
\begin{flushleft} | |
Cartagena de Indias, \today \\ | |
\vspace{1cm} | |
\textbf{Autores: $author} \\ | |
%\textbf{Docente Universidad De La Salle, D.C., Bogotá}\\ | |
%\textbf{Universidad de Pamplona, Pamplona, Norte de Santander}\\ | |
% \vspace{0.5cm} | |
\textbf{ID: $id} \\ | |
% \vspace{1.0cm} | |
\textbf{Título del trabajo: $title} \\ | |
\end{flushleft} | |
\vspace{0.5cm} | |
\noindent Estimado autor,\\ | |
Nos complace comunicarle que su trabajo fue aceptado para su presentación como \emph{ponencia oral} en el III Congreso Internacional de Ingeniería Mecatrónica y Automatización - CIIMA 2014. Los detalles sobre la programación y la duración de la presentación serán enviados en la siguiente comunicación. | |
\vspace{0.3cm} | |
\noindent Le recordamos que usted deberá registrarse y presentar el trabajo para que salga publicado en las memorias del evento. | |
Un mismo autor podrá presentar un máximo de dos trabajos. | |
Cualquier inquietud no dude en contactarnos. | |
\vspace{1cm} | |
\noindent Cordialmente, | |
\vspace{0.2cm} | |
\begin{flushleft} | |
% \includegraphics[width=0.4\textwidth]{firma-andre.png}\\ | |
% Andrés G. Marrugo, Ph.D.\\ | |
% Director comité científico CIIMA 2014 | |
% \begin{overpic}[width=0.4\textwidth,grid,tics=10]% | |
\begin{overpic}[width=0.4\textwidth]% | |
{firma-andre.png} | |
\put(1,17){Andrés G. Marrugo, Ph.D.} | |
\put(1,8){Director comité científico CIIMA 2014} | |
\end{overpic} | |
\end{flushleft} | |
\end{document} | |
''') | |
# Get all txt files | |
revList = getFileList('/Users/Andre/Downloads/down_temp/reviews/individual_reviews/') | |
# Get list of accepted papers (in html) | |
with open('/Users/Andre/Downloads/down_temp/accepted.html','r') as AList: | |
accepted = AList.read() | |
#print accepted | |
newPapers = [223] | |
for filePath in revList: | |
# print filePath | |
#with open('/Users/Andre/Downloads/down_temp/reviews/individual_reviews/submission_3.txt','r') as f: | |
with open(filePath,'r') as f: | |
# data = f.read() | |
# m = REMatcher(data) | |
for line in f: | |
m = REMatcher(line) | |
if m.match(r"^PAPER.*\s(\d+)"): | |
# print line | |
paperID = m.group(1) | |
# print paperID | |
if m.match(r"^TITLE.\s(.*\w)"): | |
paperTitle = m.group(1) | |
print accepted.find(paperTitle)>1 | |
# print m.group(1) | |
if m.match(r"^AUTHORS.\s(.*\w)"): | |
paperAuthor = m.group(1) | |
print paperAuthor | |
paperAuthorY = paperAuthor.replace(" and ", " y ") | |
# print paperAuthor | |
# print m.group(1) | |
# skip = True | |
# else: | |
# skip=False | |
#if skip: | |
try: | |
# if paper is in accepted list | |
# if accepted.find(paperTitle)>1 and (int(paperID) in paperLaSalle) : | |
# if paper is in accepted list | |
if accepted.find(paperTitle)>1 and (int(paperID) in newPapers) : | |
# Replace variables in latex_source | |
# latex_source %= (paperID,paperTitle,paperAuthor) | |
# latex_source = latex_source.format(paperID,paperTitle,paperAuthor) | |
# latex_source = latex_source.substitute(id=paperID,title=paperTitle,author=paperAuthor) | |
# print latex_source | |
# One tex file for every submission | |
# 274NK68052[*NUMBER*]58J49052/carta-aceptación-[*NUMBER*].pdf | |
path = ''.join(['20140913/274NK68052',paperID,'58J49052/']) | |
print path | |
letterName = ''.join([path,'carta-aceptacion-', paperID, '.tex']) | |
# letterName = + paperID + '.tex' | |
# print letterName | |
superWrite(letterName,latex_source.substitute(id=paperID,title=paperTitle,author=paperAuthorY)) | |
# with open(letterName,'w') as ftex: | |
# ftex.write(latex_source.substitute(id=paperID,title=paperTitle,author=paperAuthorY)) | |
proc=subprocess.Popen(shlex.split(''.join(['pdflatex ',letterName])), stdout=open(os.devnull, 'wb')) | |
proc.communicate() | |
# Remove aux files | |
os.unlink(letterName) | |
# os.unlink(''.join(['20140913/274NK68052',paperID,'58J49052/','carta-aceptacion-', paperID, '.log'])) | |
os.unlink(''.join(['carta-aceptacion-', paperID, '.log'])) | |
os.unlink(''.join(['carta-aceptacion-', paperID, '.aux'])) | |
# move pdfs | |
proc=subprocess.Popen(shlex.split(''.join(['mv ','carta-aceptacion-', paperID, '.pdf ', path]))) | |
proc.communicate() | |
except: | |
print "No reviews for this paper." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment