A second commit
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,4 +1,4 @@
|
||||
cachefile.doir
|
||||
index.html
|
||||
links/
|
||||
.idea/
|
||||
links
|
||||
.idea
|
||||
|
||||
28
doir.py
28
doir.py
@@ -8,14 +8,15 @@ import socketserver
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
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,
|
||||
default="cachefile.doir", nargs='?')
|
||||
parser.add_argument("htmlfile", help="path to the html result file", type=str, default="index.html", nargs='?')
|
||||
parser.add_argument("port", help="port on which the result will be served", type=int, default=8888, nargs='?')
|
||||
args = parser.parse_args()
|
||||
|
||||
if os.path.exists("links"):
|
||||
os.remove("links")
|
||||
|
||||
cr = Crossref()
|
||||
results = {}
|
||||
# Fifty days
|
||||
# Fifty days in seconds - seconds * minutes * hours * days
|
||||
fifty_days = 60 * 60 * 24 * 50
|
||||
|
||||
|
||||
@@ -86,20 +87,20 @@ def walk_files(dir, prefix):
|
||||
|
||||
|
||||
def write_cache(file):
|
||||
with open(file, 'w') as cache_file:
|
||||
with open(file, "w") as cache_file:
|
||||
cache_file.write(json.dumps(results))
|
||||
|
||||
|
||||
def read_cache(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())
|
||||
else:
|
||||
return {}
|
||||
|
||||
|
||||
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>")
|
||||
for result in results:
|
||||
html_file.write("<tr>")
|
||||
@@ -119,13 +120,16 @@ def write_html(file):
|
||||
html_file.write("</table></body>")
|
||||
|
||||
|
||||
results = read_cache(file=args.cachefile)
|
||||
results = read_cache(file="cachefile.doir")
|
||||
walk_files(dir=args.directory, prefix=None)
|
||||
write_cache(file=args.cachefile)
|
||||
write_html(file=args.htmlfile)
|
||||
write_cache(file="cachefile.doir")
|
||||
write_html(file="index.html")
|
||||
|
||||
os.symlink(args.directory, 'links')
|
||||
os.symlink(args.directory, "links")
|
||||
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user