Implemented publish script so put my solutions on server and render automatically.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,29 +0,0 @@
|
|||||||
import jinja2
|
|
||||||
import os
|
|
||||||
from operator import itemgetter
|
|
||||||
|
|
||||||
|
|
||||||
def file_name_to_solution(name):
|
|
||||||
number = int(name.replace("EulerProblem", "").replace(".html", ""))
|
|
||||||
file_name = name
|
|
||||||
display_name = name.replace("EulerProblem", "Problem ").replace(".html", "")
|
|
||||||
return (number, file_name, display_name)
|
|
||||||
|
|
||||||
|
|
||||||
def get_solution_list(directory="./"):
|
|
||||||
l = [file_name_to_solution(f) for f in os.listdir(directory)
|
|
||||||
if f.endswith(".html") and f.startswith("EulerProblem")]
|
|
||||||
l.sort(key=itemgetter(0))
|
|
||||||
return l
|
|
||||||
|
|
||||||
|
|
||||||
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))
|
|
||||||
|
|
||||||
|
|
||||||
render_solutions(get_solution_list())
|
|
||||||
259
ipython/EulerProblem001.html
Normal file
259
ipython/EulerProblem001.html
Normal file
File diff suppressed because one or more lines are too long
@@ -315,13 +315,16 @@ div#notebook {
|
|||||||
</div>
|
</div>
|
||||||
<div class="cell border-box-sizing code_cell rendered">
|
<div class="cell border-box-sizing code_cell rendered">
|
||||||
<div class="input">
|
<div class="input">
|
||||||
<div class="prompt input_prompt">In [5]:</div>
|
<div class="prompt input_prompt">In [1]:</div>
|
||||||
<div class="inner_cell">
|
<div class="inner_cell">
|
||||||
<div class="input_area">
|
<div class="input_area">
|
||||||
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">r</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span>
|
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">r</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span>
|
||||||
|
|
||||||
<span class="k">while</span> <span class="n">b</span> <span class="o"><=</span> <span class="mi">4000000</span><span class="p">:</span>
|
<span class="k">while</span> <span class="n">b</span> <span class="o"><=</span> <span class="mi">4000000</span><span class="p">:</span>
|
||||||
<span class="k">if</span> <span class="n">b</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> <span class="n">r</span> <span class="o">+=</span> <span class="n">b</span>
|
<span class="k">if</span> <span class="n">b</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
|
||||||
|
<span class="n">r</span> <span class="o">+=</span> <span class="n">b</span>
|
||||||
<span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="n">b</span><span class="p">,</span> <span class="n">a</span> <span class="o">+</span> <span class="n">b</span>
|
<span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="n">b</span><span class="p">,</span> <span class="n">a</span> <span class="o">+</span> <span class="n">b</span>
|
||||||
|
|
||||||
<span class="nb">print</span><span class="p">(</span><span class="n">r</span><span class="p">)</span>
|
<span class="nb">print</span><span class="p">(</span><span class="n">r</span><span class="p">)</span>
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 5,
|
"execution_count": 1,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"collapsed": false
|
"collapsed": false
|
||||||
},
|
},
|
||||||
@@ -127,9 +127,12 @@
|
|||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"r, a, b = 0, 0, 1\n",
|
"r, a, b = 0, 0, 1\n",
|
||||||
|
"\n",
|
||||||
"while b <= 4000000:\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",
|
" a, b = b, a + b\n",
|
||||||
|
" \n",
|
||||||
"print(r)"
|
"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()
|
||||||
@@ -28,8 +28,8 @@
|
|||||||
<div class="row" style="padding-top: 40px;">
|
<div class="row" style="padding-top: 40px;">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<ul>
|
<ul>
|
||||||
{% for _, a, t in solutions %}
|
{% for s in solutions %}
|
||||||
<li><a href="{{a}}">{{t}}</a></li>
|
<li><a href="{{s.html}}">{{s.name}}</a></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
Reference in New Issue
Block a user