Skip to content

Commit a959082

Browse files
committed
Adding dataset images
1 parent 0369446 commit a959082

9 files changed

Lines changed: 376 additions & 2 deletions

File tree

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ LICENSE
2222
README.md
2323
tox.ini
2424
*.secret.env
25+
./data/
26+
node_modules/

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
FROM frictionlessdata/datapackage-pipelines:2.1.8
22

3-
RUN apk --update --no-cache add bash wget
3+
RUN apk --update --no-cache add bash wget nodejs npm
4+
RUN npm install -g npm@latest
5+
RUN cd /pipelines/ && npm install puppeteer
46

57
COPY docker-dpp-run.sh /dpp/docker/run.sh
68

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import os
2+
import subprocess
3+
4+
import dataflows as DF
5+
6+
SCREENSHOT = os.path.join(os.path.dirname(__file__), 'node', 'screenshot.js')
7+
8+
9+
def do_screenshot():
10+
def func(row):
11+
doc_id = row['doc_id']
12+
url = f'https://yodaat.org/card/{doc_id}'
13+
outpath = os.path.join('data', os.path.dirname(doc_id))
14+
os.makedirs(outpath, exist_ok=True)
15+
outpath = os.path.join('data', doc_id + '.png')
16+
print('running', doc_id)
17+
subprocess.call(['node', SCREENSHOT, url, outpath, '.card'])
18+
return func
19+
20+
21+
def flow(*_, path='data/datasets_in_es'):
22+
return DF.Flow(
23+
DF.load('{}/datapackage.json'.format(path)),
24+
do_screenshot()
25+
)
26+
27+
28+
if __name__ == '__main__':
29+
flow(path='https://api.yodaat.org/data/datasets_in_es').process()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/
29.6 KB
Loading

datapackage_pipelines_migdar/flows/node/package-lock.json

Lines changed: 315 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const puppeteer = require('puppeteer');
2+
3+
(async () => {
4+
const [url, filename, selector] = process.argv.slice(2);
5+
6+
const browser = await puppeteer.launch();
7+
const page = await browser.newPage();
8+
page.setViewport({width: 1300, height: 1200});
9+
await page.goto(url);
10+
await page.waitForSelector(selector);
11+
12+
const rect = await page.evaluate(selector => {
13+
const element = document.querySelector(selector);
14+
const {x, y, width, height} = element.getBoundingClientRect();
15+
return {x, y, width, height};
16+
}, selector);
17+
await page.screenshot({path: filename, clip: rect});
18+
await browser.close();
19+
})();

0 commit comments

Comments
 (0)