-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_qr.mjs
executable file
·122 lines (114 loc) · 4.07 KB
/
make_qr.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env node
/*
generate exihition qr codes
used 2021-10:
# for exhibition at MAK forum
./make_qr.mjs --daily '2021-10-13' 47
# no expiration:
./make_qr.mjs --single
used 2022-02:
# for exhibition at AIT
./make_qr.mjs --single '2022-02-20 00:00' '2022-10-01 00:00'
used 2022-05:
# for swiss media design day talk
./make_qr.mjs --single '2022-05-10 00:00' '2022-05-16 00:00'
./make_qr.mjs --single '2022-05-10 00:00' '2022-05-23 00:00'
used 2022-11:
# for fh salzburg gastvvortrag
./make_qr.mjs --single '2022-11-29 00:00' '2022-12-07 00:00'
used 2022-11:
# for supsi mendrisio
./make_qr.mjs --single '2022-12-13 00:00' '2022-12-20 00:00'
used 2023-02:
# for HSLU hochschule luzern (online talk)
./make_qr.mjs --single '2023-02-28 00:00' '2023-03-13 00:00'
used 2023-05:
# for Wix Tel Aviv
./make_qr.mjs --single '2023-05-14 00:00' '2023-05-29 00:00'
used 2023-09:
# for Forward Vienna 2023
./make_qr.mjs --single '2023-09-29 00:00' '2023-10-16 00:00'
used 2024-01:
# for Forward Creatives
./make_qr.mjs --single '2024-01-29 00:00' '2024-02-15 00:00'
used 2024-04:
# for Klimabiennale
./make_qr.mjs --single '2024-04-05 00:00' '2024-08-01 00:00'
*/
import url from 'url';
import { make, verify, save_qr, from_unix_seconds } from './make_jwt.mjs';
function date_str(date) {
return date.getFullYear() + '-'
+ String(date.getMonth() + 1).padStart(2, '0') + '-'
+ String(date.getDate()).padStart(2, '0')
}
export function make_qr(nbf=null, exp=null, filename_prefix='qr ', subject='exhibition', base_url='https://tokensforclimate.care/create/?auth=') {
const jwt = make(subject, nbf, exp);
const payload = verify(jwt);
console.log(payload);
if (payload.iat) console.log('iat:', from_unix_seconds(payload.iat));
if (payload.nbf) console.log('nbf:', from_unix_seconds(payload.nbf));
if (payload.exp) console.log('exp:', from_unix_seconds(payload.exp));
console.log(jwt);
save_qr(jwt, base_url, nbf, exp, filename_prefix, 'txt');
save_qr(jwt, base_url, nbf, exp, filename_prefix, 'transparent-png');
save_qr(jwt, base_url, nbf, exp, filename_prefix, 'png');
return save_qr(jwt, base_url, nbf, exp, filename_prefix, 'svg');
}
function usage() {
console.log(`Usage:`);
console.log(` ./make_qr.mjs --single [ <from> [<to>] ]`);
console.log(`Examples:`);
console.log(` ./make_qr.mjs --single`);
console.log(` ./make_qr.mjs --single '2021-10-13 00:00' '2021-12-01 00:00'`);
console.log();
console.log(`Usage:`);
console.log(` ./make_qr.mjs --daily <from_date> <days> [<timezone>]`);
console.log(`Examples:`);
console.log(` ./make_qr.mjs --daily '2021-05-17' 45 'GMT+1'`);
console.log(` ./make_qr.mjs --daily '2021-10-13' 47`);
process.exit();
}
// if run as script
if ( url.fileURLToPath(import.meta.url) === process.argv[1] ) {
let args = process.argv.slice(2); // remove first two args (node binary, script path)
args = args.map(str => str.trim());
// console.log(args);
if (args.length >= 1) {
if (args[0] == '--single') {
console.log('single');
const from = args[1];
const to = args[2];
let url = make_qr(from, to);
console.log(url);
}
else if (args[0] == '--daily') {
console.log('daily');
if (args.length < 3) usage();
const from = args[1];
const days = parseInt(args[2]);
let timezone = args[3] ? ' ' + args[3] : '';
let fallback_from, fallback_to;
let date = new Date(from);
for (let i=0; i<days; i++) {
let from = date_str(date) + ' 00:00' + timezone;
if (i==0) fallback_from = from;
date.setDate(date.getDate() + 1);
let to = date_str(date) + ' 01:00' + timezone;
fallback_to = to;
let url = make_qr(from, to);
console.log(url);
console.log();
}
// generate fallback for whole duration
console.log(fallback_from, fallback_to);
let url = make_qr(fallback_from, fallback_to, 'qr whole ');
console.log(url);
}
else {
usage();
}
} else {
usage();
}
}