Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

37
LINES

< > BotCompany Repo | #1020624 // parse_vnstat

JavaX fragment (include)

1  
srecord VNStatData(
2  
  S lastMonthTotal,
3  
  S thisMonthTotal, S thisMonthEstimated,
4  
  S yesterdayTotal,
5  
  S todayTotal, S todayEstimated
6  
) {}
7  
8  
static VNStatData parse_vnstat(S output) {
9  
  LS lines = lines(output);
10  
  new VNStatData data;
11  
  
12  
  int i = indexOfContaining(lines, "monthly");
13  
  if (i >= 0) {
14  
    i = indexOfContaining(lines, i, "---")+1;
15  
    i = indexOfContaining(lines, i, "---")+1;
16  
    LS lastMonth = splitAtVerticalBar(get(lines, i-3));
17  
    LS thisMonth = splitAtVerticalBar(get(lines, i-2));
18  
    LS estimated = splitAtVerticalBar(get(lines, i));
19  
    data.lastMonthTotal = get(lastMonth, 2);
20  
    data.thisMonthTotal = get(thisMonth, 2);
21  
    data.thisMonthEstimated = get(estimated, 2);
22  
  }
23  
  
24  
  i = indexOfContaining(lines, "daily");
25  
  if (i >= 0) {
26  
    i = indexOfContaining(lines, i, "---")+1;
27  
    i = indexOfContaining(lines, i, "---")+1;
28  
    LS yesterday = splitAtVerticalBar(get(lines, i-3));
29  
    LS today = splitAtVerticalBar(get(lines, i-2));
30  
    LS estimated = splitAtVerticalBar(get(lines, i));
31  
    data.yesterdayTotal = get(yesterday, 2);
32  
    data.todayTotal = get(today, 2);
33  
    data.todayEstimated = get(estimated, 2);
34  
  }
35  
  
36  
  ret data;
37  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 9 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, jozkyjcghlvl, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1020624
Snippet name: parse_vnstat
Eternal ID of this version: #1020624/5
Text MD5: 58cd8346ca6523e6562a6061bdc244e9
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-12-28 21:27:17
Source code size: 1199 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 326 / 345
Version history: 4 change(s)
Referenced in: [show references]