Implemented publish script so put my solutions on server and render automatically.
This commit is contained in:
259
ipython/EulerProblem001.html
Normal file
259
ipython/EulerProblem001.html
Normal file
File diff suppressed because one or more lines are too long
353
ipython/EulerProblem002.html
Normal file
353
ipython/EulerProblem002.html
Normal file
File diff suppressed because one or more lines are too long
@@ -112,7 +112,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"execution_count": 1,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
@@ -127,9 +127,12 @@
|
||||
],
|
||||
"source": [
|
||||
"r, a, b = 0, 0, 1\n",
|
||||
"\n",
|
||||
"while b <= 4000000:\n",
|
||||
" if b % 2 == 0: r += b\n",
|
||||
" if b % 2 == 0:\n",
|
||||
" r += b\n",
|
||||
" a, b = b, a + b\n",
|
||||
" \n",
|
||||
"print(r)"
|
||||
]
|
||||
}
|
||||
|
||||
6
ipython/EulerProblem003.ipynb
Normal file
6
ipython/EulerProblem003.ipynb
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"cells": [],
|
||||
"metadata": {},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 0
|
||||
}
|
||||
59
ipython/publish.py
Normal file
59
ipython/publish.py
Normal file
@@ -0,0 +1,59 @@
|
||||
import jinja2
|
||||
import os
|
||||
import subprocess
|
||||
from operator import itemgetter
|
||||
from collections import namedtuple
|
||||
from os.path import getmtime
|
||||
|
||||
|
||||
def file_name_to_solution(name):
|
||||
Solution = namedtuple('Solution', ["number", "ipynb", "html", "name"])
|
||||
number = int(name.replace("EulerProblem", "").replace(".ipynb", ""))
|
||||
ipynb = name
|
||||
html = name.replace(".ipynb", ".html")
|
||||
name = name.replace("EulerProblem", "Problem ").replace(".ipynb", "")
|
||||
return Solution(number, ipynb, html, name)
|
||||
|
||||
|
||||
def get_solution_list(directory="./"):
|
||||
l = [file_name_to_solution(f) for f in os.listdir(directory)
|
||||
if f.endswith(".ipynb") and f.startswith("EulerProblem")]
|
||||
l.sort(key=itemgetter(0))
|
||||
return l
|
||||
|
||||
|
||||
def convert_solutions_to_html(solutions):
|
||||
for s in solutions:
|
||||
if getmtime(s.html) < getmtime(s.ipynb):
|
||||
args = ["ipython", "nbconvert", s.ipynb]
|
||||
subprocess.call(args)
|
||||
|
||||
|
||||
def render_solutions(solutions):
|
||||
loader = jinja2.FileSystemLoader(searchpath="./")
|
||||
env = jinja2.Environment(loader=loader)
|
||||
template = env.get_template("template.html")
|
||||
d = {"solutions": solutions}
|
||||
with open("index.html", 'w') as f:
|
||||
f.write(template.render(**d))
|
||||
|
||||
|
||||
def convert_solutions_to_html(solutions):
|
||||
for s in solutions:
|
||||
if getmtime(s.html) < getmtime(s.ipynb):
|
||||
args = ["ipython", "nbconvert", s.ipynb]
|
||||
subprocess.call(args)
|
||||
|
||||
|
||||
def ship_to_failx():
|
||||
for f in os.listdir():
|
||||
if f.endswith(".html"):
|
||||
args = ["scp", f, "failx@felixm.de:~/html/euler/"]
|
||||
subprocess.call(args)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
solutions = get_solution_list()
|
||||
convert_solutions_to_html(solutions)
|
||||
render_solutions(solutions)
|
||||
ship_to_failx()
|
||||
53
ipython/template.html
Normal file
53
ipython/template.html
Normal file
@@ -0,0 +1,53 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<!-- Required meta tags -->
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
|
||||
<!-- Bootstrap CSS -->
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
|
||||
|
||||
<title>Project Euler Solutions</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<header>
|
||||
<div class="navbar navbar-dark bg-dark box-shadow">
|
||||
<div class="container d-flex justify-content-between">
|
||||
<a href="#" class="navbar-brand d-flex align-items-center">
|
||||
<strong>My Project Euler Solutions</strong>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main role="main">
|
||||
<div class="container">
|
||||
|
||||
<div class="row" style="padding-top: 40px;">
|
||||
<div class="col">
|
||||
<ul>
|
||||
{% for s in solutions %}
|
||||
<li><a href="{{s.html}}">{{s.name}}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="row" style="padding-top: 40px;">
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</main>
|
||||
|
||||
|
||||
<!-- Optional JavaScript -->
|
||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user