Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/home/ounis/pyapps/bin/python
- # pastebin: https://pastebin.com/jynp5sBE
- #
- # created by OuNiS 07.2024
- #
- TEMP_FILE="inxi-v8azy~"
- #BATT_CAPTION="Battery:"
- import os
- import sys
- import re
- import tqdm
- def genTempFile(aFileName):
- print("Preparing data...")
- os.system(f'sudo inxi -v8azy > {aFileName}')
- return aFileName
- def getInfo(aCaptionName):
- print("Please wait while extracting data...")
- aFile = TEMP_FILE
- if not os.path.isfile(f'./{TEMP_FILE}'):
- aFile = genTempFile(TEMP_FILE)
- # os.system(f"sudo inxi -v8azy > {TEMP_FE}")
- with open(aFile) as file:
- can_print = False
- for line in file:
- if line.lower().startswith(aCaptionName.lower()):
- print(line, end="")
- can_print = True
- continue
- if can_print and not line[0].isalnum():
- print(line, end="")
- if can_print and not line.startswith(" "):
- break
- ...
- def extractSections(aFileName):
- result = ()
- lineSectF = re.compile(r'^[a-zA-Z]+\:')
- with open(aFileName) as file:
- for line in file:
- if flc := lineSectF.search(line):
- result += (flc.group(), )
- return result
- ...
- def main(args):
- # test tqdm
- # for i in tqdm.trange(1000):
- # pass
- # print(extractSections("./inxi-v8azy~"))
- if len(args) > 1:
- getInfo(args[1])
- else:
- print("Available sections:\n--------------------")
- for sect in extractSections(TEMP_FILE):
- print(sect, end=" ")
- print()
- selSect = input("Select: ")
- getInfo(selSect)
- # print("ERR: lack of parameter caption name (eg. Battery, Memory)")
- ...
- if __name__ == "__main__":
- sys.exit(main(sys.argv))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement