A second commit
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,4 +1,4 @@
|
|||||||
cachefile.doir
|
cachefile.doir
|
||||||
index.html
|
index.html
|
||||||
links/
|
links
|
||||||
.idea/
|
.idea
|
||||||
|
|||||||
28
doir.py
28
doir.py
@@ -8,14 +8,15 @@ import socketserver
|
|||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("directory", help="directory which contains the files to resolve", type=str, default=".")
|
parser.add_argument("directory", help="directory which contains the files to resolve", type=str, default=".")
|
||||||
parser.add_argument("cachefile", help="path to the cache file containing already resolved DOIs", type=str,
|
parser.add_argument("port", help="port on which the result will be served", type=int, default=8888, nargs='?')
|
||||||
default="cachefile.doir", nargs='?')
|
|
||||||
parser.add_argument("htmlfile", help="path to the html result file", type=str, default="index.html", nargs='?')
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if os.path.exists("links"):
|
||||||
|
os.remove("links")
|
||||||
|
|
||||||
cr = Crossref()
|
cr = Crossref()
|
||||||
results = {}
|
results = {}
|
||||||
# Fifty days
|
# Fifty days in seconds - seconds * minutes * hours * days
|
||||||
fifty_days = 60 * 60 * 24 * 50
|
fifty_days = 60 * 60 * 24 * 50
|
||||||
|
|
||||||
|
|
||||||
@@ -86,20 +87,20 @@ def walk_files(dir, prefix):
|
|||||||
|
|
||||||
|
|
||||||
def write_cache(file):
|
def write_cache(file):
|
||||||
with open(file, 'w') as cache_file:
|
with open(file, "w") as cache_file:
|
||||||
cache_file.write(json.dumps(results))
|
cache_file.write(json.dumps(results))
|
||||||
|
|
||||||
|
|
||||||
def read_cache(file):
|
def read_cache(file):
|
||||||
if os.path.isfile(file):
|
if os.path.isfile(file):
|
||||||
with open(file, 'r') as cache_file:
|
with open(file, "r") as cache_file:
|
||||||
return json.loads(cache_file.read())
|
return json.loads(cache_file.read())
|
||||||
else:
|
else:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
def write_html(file):
|
def write_html(file):
|
||||||
with open(file, 'w') as html_file:
|
with open(file, "w") as html_file:
|
||||||
html_file.write("<html><head></head><body><table><tr><th>Title</th><th>Year</th><th>Link</th></tr>")
|
html_file.write("<html><head></head><body><table><tr><th>Title</th><th>Year</th><th>Link</th></tr>")
|
||||||
for result in results:
|
for result in results:
|
||||||
html_file.write("<tr>")
|
html_file.write("<tr>")
|
||||||
@@ -119,13 +120,16 @@ def write_html(file):
|
|||||||
html_file.write("</table></body>")
|
html_file.write("</table></body>")
|
||||||
|
|
||||||
|
|
||||||
results = read_cache(file=args.cachefile)
|
results = read_cache(file="cachefile.doir")
|
||||||
walk_files(dir=args.directory, prefix=None)
|
walk_files(dir=args.directory, prefix=None)
|
||||||
write_cache(file=args.cachefile)
|
write_cache(file="cachefile.doir")
|
||||||
write_html(file=args.htmlfile)
|
write_html(file="index.html")
|
||||||
|
|
||||||
os.symlink(args.directory, 'links')
|
os.symlink(args.directory, "links")
|
||||||
|
|
||||||
Handler = http.server.SimpleHTTPRequestHandler
|
Handler = http.server.SimpleHTTPRequestHandler
|
||||||
httpd = socketserver.TCPServer(("", 8888), Handler)
|
httpd = socketserver.TCPServer(("", args.port), Handler)
|
||||||
|
|
||||||
|
print("Start serving on localhost:" + args.port)
|
||||||
|
|
||||||
httpd.serve_forever()
|
httpd.serve_forever()
|
||||||
|
|||||||
Reference in New Issue
Block a user