scripts/pacplot

39 lines
883 B
Python
Executable file

#!/usr/bin/python
# Graph the number of installed packages over time by parsing /var/log/pacman.log
from datetime import datetime
from matplotlib import pyplot as plt
with open('/var/log/pacman.log', 'r') as f:
cnt = 0
installed = 0
removed = 0
x = []
y = []
for line in f.readlines():
if '[ALPM]' not in line or 'warning' in line:
# Ignore operations
continue
if ' installed' in line:
cnt += 1
installed += 1
elif 'removed' in line:
cnt -= 1
removed += 1
else:
continue
x.append(datetime.fromisoformat(line[1:23] + ':00'))
y.append(cnt)
print('Currently installed packages:', cnt)
print('Total installed packages:', installed)
print('Total removed packages:', removed)
plt.plot(x, y)
plt.savefig('pac.png')
plt.show()