dots


commit
2efcec6
parent
57194e3
author
chasinglightning
date
2025-01-05 16:36:43 -0500 EST
add phantomjs scripts from server
7 files changed,  +109, -3
A home/scripts/phantomjs-wttr/Dockerfile
+40, -0
 1@@ -0,0 +1,40 @@
 2+#FROM - an alpine image or any image that you may use and are facing the issue
 3+FROM node:6-alpine
 4+
 5+# WORKDIR - any workdir that you may use
 6+# RUN some other commands if needed
 7+
 8+# If you also need fonts then add this - Select any fonts from here https://wiki.alpinelinux.org/wiki/Fonts#List_of_fonts_in_Alpine_Linux:~:text=ttf%2Dubuntu%2Dfont%2Dfamily
 9+# Just replace ttf-ubuntu-font-family with fonts that you need
10+RUN apk --update add ttf-ubuntu-font-family fontconfig && rm -rf /var/cache/apk/*
11+
12+RUN apk add imagemagick
13+
14+# if ever you need to change phantom js version number in future ENV comes handy as it can be used as a dynamic variable
15+ENV PHANTOMJS_VERSION=2.1.1
16+
17+RUN apk add --no-cache curl && \
18+    cd /tmp && curl -Ls https://github.com/topseom/phantomized/releases/download/2.1.1/dockerized-phantomjs.tar.gz | tar xz && \
19+    cp -R lib lib64 / && \
20+    cp -R usr/lib/x86_64-linux-gnu /usr/lib && \
21+    cp -R usr/share /usr/share && \
22+    cp -R etc/fonts /etc && \
23+    curl -k -Ls https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 | tar -jxf - &&\
24+    cp phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs && \
25+    rm -fR phantomjs-2.1.1-linux-x86_64 && \
26+    apk del curl
27+
28+# RUN any other commands still pending
29+# ENTRYPOINT 
30+# CMD
31+
32+RUN mkdir -p /raster-root \
33+        && mkdir -p /raster-output
34+COPY rasterize.js /raster-root/
35+WORKDIR /raster-root
36+
37+COPY . .
38+# These line for /entrypoint.sh
39+COPY entrypoint.sh /entrypoint.sh
40+RUN chmod +x /entrypoint.sh
41+entrypoint "/entrypoint.sh"
A home/scripts/phantomjs-wttr/README.md
+7, -0
1@@ -0,0 +1,7 @@
2+## for optiplex 9020 server
3+
4+run with following cron job on the server:
5+
6+```bash
7+*/30 * * * * cd /home/kat/pjs && /usr/bin/docker compose run --rm pjs /home/kat/pjs/entrypoint.sh && /home/kat/pjs/rsync.sh >> /home/kat/pjs/test2.log 2>&1
8+```
A home/scripts/phantomjs-wttr/docker-compose.yml
+8, -0
1@@ -0,0 +1,8 @@
2+services:
3+  pjs:
4+    build: .
5+    ports:
6+      - "9283:5000"
7+    command: /bin/sh -c "entrypoint.sh"
8+    volumes:
9+      - /home/kat/pjs/output:/raster-output
A home/scripts/phantomjs-wttr/entrypoint.sh
+3, -0
1@@ -0,0 +1,3 @@
2+#!/bin.bash
3+
4+phantomjs --ignore-ssl-errors=true --ssl-protocol=any --web-security=true /raster-root/rasterize.js http://wttr.in/New_York?0pqT /raster-output/wttr.png && magick /raster-output/wttr.png -crop 460x460+0+0 -transparent black /raster-output/wttr.png
A home/scripts/phantomjs-wttr/rasterize.js
+50, -0
 1@@ -0,0 +1,50 @@
 2+"use strict";
 3+var page = require('webpage').create(),
 4+    system = require('system'),
 5+    address, output, size, pageWidth, pageHeight;
 6+
 7+if (system.args.length < 3 || system.args.length > 5) {
 8+    console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat] [zoom]');
 9+    console.log('  paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"');
10+    console.log('  image (png/jpg output) examples: "1920px" entire page, window width 1920px');
11+    console.log('                                   "800px*600px" window, clipped to 800x600');
12+    phantom.exit(1);
13+} else {
14+    address = system.args[1];
15+    output = system.args[2];
16+    page.viewportSize = { width: 1024, height: 2000};
17+    if (system.args.length > 3 && system.args[2].substr(-4) === ".pdf") {
18+        size = system.args[3].split('*');
19+        page.paperSize = size.length === 2 ? { width: size[0], height: size[1], margin: '0px' }
20+                                           : { format: system.args[3], orientation: 'portrait', margin: '1cm' };
21+    } else if (system.args.length > 3 && system.args[3].substr(-2) === "px") {
22+        size = system.args[3].split('*');
23+        if (size.length === 2) {
24+            var pageWidth = parseInt(size[0], 10),
25+                pageHeight = parseInt(size[1], 10);
26+            page.viewportSize = { width: pageWidth, height: pageHeight };
27+            page.clipRect = { top: 0, left: 0, width: pageWidth, height: pageHeight };
28+        } else {
29+            console.log("size:", system.args[3]);
30+            var pageWidth = parseInt(system.args[3], 10),
31+                pageHeight = parseInt(pageWidth * 3/4, 10); // it's as good an assumption as any
32+            console.log ("pageHeight:",pageHeight);
33+            page.viewportSize = { width: pageWidth, height: pageHeight };
34+        }
35+    }
36+    if (system.args.length > 4) {
37+        page.zoomFactor = system.args[4];
38+    }
39+    page.open(address, function (status) {
40+        if (status !== 'success') {
41+            console.log('Unable to load the address!');
42+            phantom.exit(1);
43+        } else {
44+            window.setTimeout(function () {
45+                page.render(output);
46+                console.log("Success");
47+                phantom.exit();
48+            }, 200);
49+        }
50+    });
51+}
A home/scripts/phantomjs-wttr/rsync.sh
+1, -0
1@@ -0,0 +1 @@
2+rsync -ave 'ssh' /home/kat/pjs/output/wttr.png kat@192.168.1.123:/home/kat/.config/conky
D home/scripts/wttr-conky.sh
+0, -3
1@@ -1,3 +0,0 @@
2-phantomjs --ignore-ssl-errors=true --ssl-protocol=any --web-security=true /usr/local/share/phantomjs-1.9.8-linux-x86_64/examples/rasterize.js http://wttr.in/New_York?0pqT /tmp/wttr.png
3-
4-magick /tmp/wttr.png -crop 460x460+0+0 -transparent black /tmp/wttr.png