###############################################################################
# create.many.pubs.py - reads in a file of paper metadata and generates
# a directory for each paper. This code assumes papers are stored in the
# following directory structure:
# publications/year/short_name_of_paper
#
# Reads in a file with the following input
# dirname
# title
# author list
# abstract (must be on one line)
# url to paper
#
# and then it repeats
###############################################################################
import os
import sys
import re
import string
import shutil
def create_page(title, author_list, conference, abstract, file):
page = """
""" + title + """
""" + title + """
""" + author_list + """
""" + conference + """
"""+ abstract + """
Download Paper in PDF
"""
return page
def write_file(dirname, pagetext):
f = open(dirname + "/index.html", 'w')
f.write(pagetext)
f.close()
return
def download_paper(dirname, url):
os.system("wget -nv " + url)
#get the file name from the url
filename = re.match('.*/(.*)$',url).group(1)
print("filename is: " + filename)
cmd = "mv " + filename + " " + dirname + "/" + filename
os.system(cmd)
return filename
def create_directory(dirname):
os.mkdir(dirname)
return
# main program begins here
f = open(sys.argv[1],"r")
lines = f.readlines()
count = 0
while count < len(lines):
dirname = lines[count]
dirname = dirname.rstrip("\r\n")
title = lines[count+1]
title = title.rstrip("\r\n")
authors = lines[count+2]
authors = authors.rstrip("\r\n")
conf = lines[count+3]
conf = conf.rstrip("\r\n")
abstract = lines[count+4]
abstract = abstract.rstrip("\r\n")
url = lines[count+5]
url = url.rstrip("\r\n")
count += 7 # skip over blank line
create_directory(dirname)
filename = download_paper(dirname, url)
write_file(dirname, create_page(title, authors, conf, abstract, filename))