Skip to content

Commit 1e37851

Browse files
committed
Modified scripts to produce live preview of code being run
1 parent 9a75571 commit 1e37851

File tree

8 files changed

+110
-13
lines changed

8 files changed

+110
-13
lines changed

spark/.gitignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.ipynb_checkpoints/
2-
live/
3-
live.html
2+
live/live.html
3+
live/live_mod.py
44
_work.py
5-

spark/live.ipynb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"name": "stdout",
10+
"output_type": "stream",
11+
"text": [
12+
"hello world!\n"
13+
]
14+
}
15+
],
16+
"source": [
17+
"print(\"hello world!\")"
18+
]
19+
}
20+
],
21+
"metadata": {
22+
"kernelspec": {
23+
"display_name": "Python 3",
24+
"language": "python",
25+
"name": "python3"
26+
},
27+
"language_info": {
28+
"codemirror_mode": {
29+
"name": "ipython",
30+
"version": 3
31+
},
32+
"file_extension": ".py",
33+
"mimetype": "text/x-python",
34+
"name": "python",
35+
"nbconvert_exporter": "python",
36+
"pygments_lexer": "ipython3",
37+
"version": "3.7.2"
38+
}
39+
},
40+
"nbformat": 4,
41+
"nbformat_minor": 2
42+
}

spark/live.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@
33
spark = SparkSession.builder.master("local").appName("SQL").getOrCreate()
44
df = spark.read.load('data/containers_tiny.parquet')
55
df.select("ship_imo", "container_id", "net_weight").show()
6-

spark/live.sh

Lines changed: 0 additions & 9 deletions
This file was deleted.

spark/live/live.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
fswatch ../live.py | while read -r fpath; do \
5+
echo -e "\033[0;36mRELOAD\033[0m $fpath $(date +"%H%M%S")"
6+
echo -e "# $(date +"%H:%M:%S")\n" | cat - ../live.py > live_mod.py
7+
sed -e '/-python">/r./live_mod.py' live_template.html > live.html
8+
gsutil cp live.html gs://bigdata.luisbelloch.es/live.html
9+
10+
# echo -e "# $(date +"%H:%M:%S")\n" | cat - live.py | pygmentize -f html -O full,linenos=1 -o live.html
11+
# scp live.html [email protected]:/var/www/html/index.html
12+
done
13+

spark/live/live_jupyter.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
set -eou pipefail
3+
4+
fswatch ../live.ipynb | while read -r fpath; do \
5+
echo -e "\033[0;36mRELOAD\033[0m $fpath $(date +"%H%m%S")"
6+
jupyter nbconvert ../live.ipynb --to html --output-dir="$(pwd)"
7+
gsutil cp live.html gs://bigdata.luisbelloch.es/live.html
8+
# scp live/live.html [email protected]:/var/www/html/index.html
9+
done
10+

spark/live/live_template.html

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
7+
<title>#bidataupv - live</title>
8+
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Fira+Mono:400,500,700|Roboto:300,400,500,700,900" />
9+
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.14.2/styles/dracula.min.css" />
10+
<style>
11+
body {
12+
background: #282a36;
13+
}
14+
pre {
15+
font-size: 0.875rem;
16+
line-height: 1.4;
17+
overflow-x: auto;
18+
}
19+
code {
20+
font-family: "Fira Mono", Menlo, Consolas, "Courier New", Courier, monospace;
21+
}
22+
</style>
23+
</head>
24+
<body>
25+
<div>
26+
<pre><code class="language-python">
27+
</code></pre>
28+
</div>
29+
<script src="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.14.2/highlight.min.js"></script>
30+
<script>
31+
hljs.initHighlightingOnLoad();
32+
</script>
33+
</body>
34+
</html>

spark/reload.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
fswatch live.py | while read -r fpath; do \
5+
clear
6+
echo -e "\033[0;36mRELOAD\033[0m $fpath $(date +"%H%M%S")"
7+
spark-submit live.py
8+
done
9+

0 commit comments

Comments
 (0)