I'm not sure what is your problem but in this kind of string main problem can be splitting string to groups of lines which start at line with :
When string will be splitted then in every group will be easy to use : to create key and value
This example code splits text in lines and group lines
text = ''' rx / tx / total / estimated
br-int: Not enough data available yet.
eno1:
Oct '19 17.30 TiB / 18.22 TiB / 35.52 TiB / 78.89 TiB
yesterday 1.61 TiB / 1.70 TiB / 3.31 TiB
today 1.99 TiB / 2.05 TiB / 4.04 TiB / 5.50 TiB
eno3: Not enough data available yet.
eno2: Not enough data available yet.
eno4:
Oct '19 155.02 MiB / 5.16 MiB / 160.18 MiB / 355.00 MiB
yesterday 19.46 MiB / 1.08 MiB / 20.54 MiB
today 14.21 MiB / 650 KiB / 14.84 MiB / --'''
all_groups = [] # list for all groups
group = [] # create list for first group
for line in text.split('\n'):
if ':' in line: # line with `:` starts new group
all_groups.append(group) # add previous group to list of all groups
group = [] # create empty list for new group
group.append(line.strip()) # add line to current group
all_groups.append(group) # add last group to list of groups
# --- display groups ---
for group in all_groups:
text = '\n'.join(group)
print(text)
print('---')
Result
rx / tx / total / estimated
---
br-int: Not enough data available yet.
---
eno1:
Oct '19 17.30 TiB / 18.22 TiB / 35.52 TiB / 78.89 TiB
yesterday 1.61 TiB / 1.70 TiB / 3.31 TiB
today 1.99 TiB / 2.05 TiB / 4.04 TiB / 5.50 TiB
---
eno3: Not enough data available yet.
---
eno2: Not enough data available yet.
---
eno4:
Oct '19 155.02 MiB / 5.16 MiB / 160.18 MiB / 355.00 MiB
yesterday 19.46 MiB / 1.08 MiB / 20.54 MiB
today 14.21 MiB / 650 KiB / 14.84 MiB / --
---
Now it is easy to split evey group (which has :) into key and value.
Because you use nubmers as keys in your dictionares then you could use list instead of dictionary. And you could keep key and value together as tuple.
data = []
for group in all_groups:
text = '\n'.join(group)
if ':' in text:
key, value = text.split(':')
value = value.strip()
data.append((key, value))
#print('---', key, '---')
#print(value)
for item in data:
print(item)
Result
('br-int', 'Not enough data available yet.')
('eno1', "Oct '19 17.30 TiB / 18.22 TiB / 35.52 TiB / 78.89 TiB\nyesterday 1.61 TiB / 1.70 TiB / 3.31 TiB\ntoday 1.99 TiB / 2.05 TiB / 4.04 TiB / 5.50 TiB")
('eno3', 'Not enough data available yet.')
('eno2', 'Not enough data available yet.')
Eventually you could use br-int, eno1, etc. as a key in dictionary instead of numbers
data = {}
for group in all_groups:
text = '\n'.join(group)
if ':' in text:
key, value = text.split(':')
value = value.strip()
data[key] = value
#print('---', key, '---')
#print(value)
for item in data.items():
print(item)
EDIT: Eventually you can use regex to split text - re.split('\n(.*):', text)
text = ''' rx / tx / total / estimated
br-int: Not enough data available yet.
eno1:
Oct '19 17.30 TiB / 18.22 TiB / 35.52 TiB / 78.89 TiB
yesterday 1.61 TiB / 1.70 TiB / 3.31 TiB
today 1.99 TiB / 2.05 TiB / 4.04 TiB / 5.50 TiB
eno3: Not enough data available yet.
eno2: Not enough data available yet.
eno4:
Oct '19 155.02 MiB / 5.16 MiB / 160.18 MiB / 355.00 MiB
yesterday 19.46 MiB / 1.08 MiB / 20.54 MiB
today 14.21 MiB / 650 KiB / 14.84 MiB / --'''
import re
results = re.split('\n(.*:)', text)
results = results[1:] # skip first element (first line)
#for item in results:
# print('>', item)
data = []
for key, value in zip(results[0::2], results[1::2]):
data.append((key, value))
#print('---', key, '---')
#print(value)
for item in data:
print(item)
:. When lines are grouped then it is easy split group using:vnstat --jsonwhich is usually far more trivial to parse.