Introduction
Introduction Statistics Contact Development Disclaimer Help
ttxt2ics - ics2txt - convert icalendar .ics file to plain text
git clone git://bitreich.org/ics2txt git://hg6vgqziawt5s4dj.onion/ics2txt
Log
Files
Refs
Tags
README
---
ttxt2ics (2111B)
---
1 #!/usr/bin/awk -f
2
3 function prompt(msg)
4 {
5 if (TTY)
6 printf("%s", msg) >"/dev/stderr";
7 if (!getline str)
8 exit(1);
9 return str;
10 }
11
12 function parse_date(str, tm)
13 {
14 if (length(str) == 5) {
15 "date +%Y/%m/%d" | getline date
16 str = date " " str ;
17 close("date +%Y/%m/%d");
18 }
19
20 if (length(str) != 16) {
21 print("invalid date length") >"/dev/stderr";
22 return -1;
23 }
24
25 tm["yrs"] = substr(str, 1, 4);
26 if (! match(tm["yrs"], "^[0-9]+$")) {
27 print("invalid year: " tm["yrs"]) >"/dev/stderr";
28 return -1;
29 }
30
31 tm["mth"] = substr(str, 6, 2);
32 if (! match(tm["mth"], "^[0-1][0-9]$")) {
33 print("invalid month: " tm["mth"]) >"/dev/stderr";
34 return -1;
35 }
36
37 tm["day"] = substr(str, 9, 2);
38 if (! match(tm["day"], "^[0-3][0-9]$")) {
39 print("invalid day: " tm["day"]) >"/dev/stderr";
40 return -1;
41 }
42
43 tm["hrs"] = substr(str, 12, 2);
44 if (! match(tm["hrs"], "^[0-2][0-9]$")) {
45 print("invalid hours: " tm["hrs"]) >"/dev/stderr";
46 return -1;
47 }
48
49 tm["min"] = substr(str, 15, 2);
50 if (! match(tm["min"], "^[0-6][0-9]$")) {
51 print("invalid minutes: " tm["min"]) >"/dev/stderr";
52 return -1;
53 }
54
55 return 0;
56 }
57
58 BEGIN {
59 TTY = !system("tty >/dev/null");
60
61 if (TTY) {
62 "date +%Y" | getline yrs
63 close("date +%Y");
64 system("cal " yrs ">/dev/stderr");
65 system("date >/dev/stderr");
66 system("date +'%Y/%m/%d %H:%M' >/dev/stderr");
67 print("") >"/dev/stderr";
68 }
69
70 do beg = prompt("Start [YYYY/MM/DD HH:MM] or [HH:MM] for today: …
71 while (parse_date(beg, tm_beg) == -1);
72
73 do end = prompt("End [YYYY/MM/DD HH:MM] or [HH:MM] for same da…
74 while (parse_date(end, tm_end) == -1);
75
76 sum = prompt("Summary: ");
77 cat = prompt("Category: ");
78 loc = prompt("Location: ");
79 des = prompt("Description: ");
80
81 print("BEGIN:VEVENT");
82 print("DTSTART:" \
83 tm_beg["yrs"] tm_beg["mth"] tm_beg["day"] "T" \
84 tm_beg["hrs"] tm_beg["min"] "00");
85 print("DTEND:" \
86 tm_end["yrs"] tm_end["mth"] tm_end["day"] "T" \
87 tm_end["hrs"] tm_end["min"] "00");
88 if (cat) print("CATEGORIES:" cat);
89 if (sum) print("SUMMARY:" sum);
90 if (des) print("DESCRIPTION:" des);
91 if (loc) print("LOCATION:" loc);
92 print("END:VEVENT");
93 }
You are viewing proxied material from bitreich.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.