#!/usr/bin/env python

from os import environ as env
from socket import gethostname
import glob, sys

def get_line(file, linenum):
    """Get the line of a file."""
    try:
        with open(file, "r") as f:
            return f.readlines()[linenum - 1].replace("\n", "")
    except:
        return f"[ERROR]: could not open '{file}'"

def get_distro():
    line = get_line("/etc/os-release", 3)
    return line.split('=')[1].replace('"', "")

def read_file(file):
    """Get the contents of a file."""
    try:
        with open(file, "r") as f:
            content = f.read().replace("\n", "")
            return content
    except:
        return f"[ERROR]: could not open '{file}'"

def get_music():
    import musicpd
    cli = musicpd.MPDClient()
    cli.connect()
    artist = cli.currentsong().get("artist")
    title = cli.currentsong().get("title")
    return f"{artist} - {title}"

def get_packages(mngr):
    if mngr != "portage":
        return("[ERROR]: sorry, only portage is supported right now")
    with open("/var/lib/portage/world", "r") as w:
        explicit = str(len(w.readlines()))
    total = str(len(glob.glob("/var/db/pkg/*/*")))
    return f"{explicit} (explicit) {total} (total)"

def get_uptime():
    raw_uptime = int(read_file("/proc/uptime").split('.')[0])
    if raw_uptime > 86400:
        days    = str(raw_uptime / 60 / 60 / 24).split('.')[0]   + 'd'
    else:
        days = ""
    if raw_uptime > 3600:
        hours   = str((raw_uptime / 60 / 60) % 24).split('.')[0] + 'h'
    else:
        hours = ""
    if raw_uptime > 60:
        minutes = str((raw_uptime / 60) % 60).split('.')[0]      + 'm'
    else:
        minutes = ""
    return f"{days} {hours} {minutes}".strip()

cpu      = get_line("/proc/cpuinfo", 5).split(':')[1][1:]
distro   = get_distro()
editor   = env['EDITOR']
hostname = gethostname()
kernel   = read_file("/proc/sys/kernel/osrelease")
packages = get_packages("portage")
shell    = env['SHELL']
uptime   = get_uptime()
user     = env['USER']
if ("-m" in sys.argv):
    music = get_music()
else:
    music = "[N/A]: -m was not not supplied"
    
print(f"""
cpu      = {cpu}
distro   = {distro}
editor   = {editor}
hostname = {hostname}
kernel   = {kernel}  
packages = {packages}
shell    = {shell}   
uptime   = {uptime}  
user     = {user}
music    = {music}
""")

ab1b09bf6b1167191cb82521693a38ea1e2e0e16
<mask token>


def get_distro():
    line = get_line('/etc/os-release', 3)
    return line.split('=')[1].replace('"', '')


def read_file(file):
    """Get the contents of a file."""
    try:
        with open(file, 'r') as f:
            content = f.read().replace('\n', '')
            return content
    except:
        return f"[ERROR]: could not open '{file}'"


def get_music():
    import musicpd
    cli = musicpd.MPDClient()
    cli.connect()
    artist = cli.currentsong().get('artist')
    title = cli.currentsong().get('title')
    return f'{artist} - {title}'


<mask token>


def get_uptime():
    raw_uptime = int(read_file('/proc/uptime').split('.')[0])
    if raw_uptime > 86400:
        days = str(raw_uptime / 60 / 60 / 24).split('.')[0] + 'd'
    else:
        days = ''
    if raw_uptime > 3600:
        hours = str(raw_uptime / 60 / 60 % 24).split('.')[0] + 'h'
    else:
        hours = ''
    if raw_uptime > 60:
        minutes = str(raw_uptime / 60 % 60).split('.')[0] + 'm'
    else:
        minutes = ''
    return f'{days} {hours} {minutes}'.strip()


<mask token>

<mask token>


def get_line(file, linenum):
    """Get the line of a file."""
    try:
        with open(file, 'r') as f:
            return f.readlines()[linenum - 1].replace('\n', '')
    except:
        return f"[ERROR]: could not open '{file}'"


def get_distro():
    line = get_line('/etc/os-release', 3)
    return line.split('=')[1].replace('"', '')


def read_file(file):
    """Get the contents of a file."""
    try:
        with open(file, 'r') as f:
            content = f.read().replace('\n', '')
            return content
    except:
        return f"[ERROR]: could not open '{file}'"


def get_music():
    import musicpd
    cli = musicpd.MPDClient()
    cli.connect()
    artist = cli.currentsong().get('artist')
    title = cli.currentsong().get('title')
    return f'{artist} - {title}'


def get_packages(mngr):
    if mngr != 'portage':
        return '[ERROR]: sorry, only portage is supported right now'
    with open('/var/lib/portage/world', 'r') as w:
        explicit = str(len(w.readlines()))
    total = str(len(glob.glob('/var/db/pkg/*/*')))
    return f'{explicit} (explicit) {total} (total)'


def get_uptime():
    raw_uptime = int(read_file('/proc/uptime').split('.')[0])
    if raw_uptime > 86400:
        days = str(raw_uptime / 60 / 60 / 24).split('.')[0] + 'd'
    else:
        days = ''
    if raw_uptime > 3600:
        hours = str(raw_uptime / 60 / 60 % 24).split('.')[0] + 'h'
    else:
        hours = ''
    if raw_uptime > 60:
        minutes = str(raw_uptime / 60 % 60).split('.')[0] + 'm'
    else:
        minutes = ''
    return f'{days} {hours} {minutes}'.strip()


<mask token>

<mask token>


def get_line(file, linenum):
    """Get the line of a file."""
    try:
        with open(file, 'r') as f:
            return f.readlines()[linenum - 1].replace('\n', '')
    except:
        return f"[ERROR]: could not open '{file}'"


def get_distro():
    line = get_line('/etc/os-release', 3)
    return line.split('=')[1].replace('"', '')


def read_file(file):
    """Get the contents of a file."""
    try:
        with open(file, 'r') as f:
            content = f.read().replace('\n', '')
            return content
    except:
        return f"[ERROR]: could not open '{file}'"


def get_music():
    import musicpd
    cli = musicpd.MPDClient()
    cli.connect()
    artist = cli.currentsong().get('artist')
    title = cli.currentsong().get('title')
    return f'{artist} - {title}'


def get_packages(mngr):
    if mngr != 'portage':
        return '[ERROR]: sorry, only portage is supported right now'
    with open('/var/lib/portage/world', 'r') as w:
        explicit = str(len(w.readlines()))
    total = str(len(glob.glob('/var/db/pkg/*/*')))
    return f'{explicit} (explicit) {total} (total)'


def get_uptime():
    raw_uptime = int(read_file('/proc/uptime').split('.')[0])
    if raw_uptime > 86400:
        days = str(raw_uptime / 60 / 60 / 24).split('.')[0] + 'd'
    else:
        days = ''
    if raw_uptime > 3600:
        hours = str(raw_uptime / 60 / 60 % 24).split('.')[0] + 'h'
    else:
        hours = ''
    if raw_uptime > 60:
        minutes = str(raw_uptime / 60 % 60).split('.')[0] + 'm'
    else:
        minutes = ''
    return f'{days} {hours} {minutes}'.strip()


<mask token>
if '-m' in sys.argv:
    music = get_music()
else:
    music = '[N/A]: -m was not not supplied'
print(
    f"""
cpu      = {cpu}
distro   = {distro}
editor   = {editor}
hostname = {hostname}
kernel   = {kernel}  
packages = {packages}
shell    = {shell}   
uptime   = {uptime}  
user     = {user}
music    = {music}
"""
    )

<mask token>


def get_line(file, linenum):
    """Get the line of a file."""
    try:
        with open(file, 'r') as f:
            return f.readlines()[linenum - 1].replace('\n', '')
    except:
        return f"[ERROR]: could not open '{file}'"


def get_distro():
    line = get_line('/etc/os-release', 3)
    return line.split('=')[1].replace('"', '')


def read_file(file):
    """Get the contents of a file."""
    try:
        with open(file, 'r') as f:
            content = f.read().replace('\n', '')
            return content
    except:
        return f"[ERROR]: could not open '{file}'"


def get_music():
    import musicpd
    cli = musicpd.MPDClient()
    cli.connect()
    artist = cli.currentsong().get('artist')
    title = cli.currentsong().get('title')
    return f'{artist} - {title}'


def get_packages(mngr):
    if mngr != 'portage':
        return '[ERROR]: sorry, only portage is supported right now'
    with open('/var/lib/portage/world', 'r') as w:
        explicit = str(len(w.readlines()))
    total = str(len(glob.glob('/var/db/pkg/*/*')))
    return f'{explicit} (explicit) {total} (total)'


def get_uptime():
    raw_uptime = int(read_file('/proc/uptime').split('.')[0])
    if raw_uptime > 86400:
        days = str(raw_uptime / 60 / 60 / 24).split('.')[0] + 'd'
    else:
        days = ''
    if raw_uptime > 3600:
        hours = str(raw_uptime / 60 / 60 % 24).split('.')[0] + 'h'
    else:
        hours = ''
    if raw_uptime > 60:
        minutes = str(raw_uptime / 60 % 60).split('.')[0] + 'm'
    else:
        minutes = ''
    return f'{days} {hours} {minutes}'.strip()


cpu = get_line('/proc/cpuinfo', 5).split(':')[1][1:]
distro = get_distro()
editor = env['EDITOR']
hostname = gethostname()
kernel = read_file('/proc/sys/kernel/osrelease')
packages = get_packages('portage')
shell = env['SHELL']
uptime = get_uptime()
user = env['USER']
if '-m' in sys.argv:
    music = get_music()
else:
    music = '[N/A]: -m was not not supplied'
print(
    f"""
cpu      = {cpu}
distro   = {distro}
editor   = {editor}
hostname = {hostname}
kernel   = {kernel}  
packages = {packages}
shell    = {shell}   
uptime   = {uptime}  
user     = {user}
music    = {music}
"""
    )

#!/usr/bin/env python

from os import environ as env
from socket import gethostname
import glob, sys

def get_line(file, linenum):
    """Get the line of a file."""
    try:
        with open(file, "r") as f:
            return f.readlines()[linenum - 1].replace("\n", "")
    except:
        return f"[ERROR]: could not open '{file}'"

def get_distro():
    line = get_line("/etc/os-release", 3)
    return line.split('=')[1].replace('"', "")

def read_file(file):
    """Get the contents of a file."""
    try:
        with open(file, "r") as f:
            content = f.read().replace("\n", "")
            return content
    except:
        return f"[ERROR]: could not open '{file}'"

def get_music():
    import musicpd
    cli = musicpd.MPDClient()
    cli.connect()
    artist = cli.currentsong().get("artist")
    title = cli.currentsong().get("title")
    return f"{artist} - {title}"

def get_packages(mngr):
    if mngr != "portage":
        return("[ERROR]: sorry, only portage is supported right now")
    with open("/var/lib/portage/world", "r") as w:
        explicit = str(len(w.readlines()))
    total = str(len(glob.glob("/var/db/pkg/*/*")))
    return f"{explicit} (explicit) {total} (total)"

def get_uptime():
    raw_uptime = int(read_file("/proc/uptime").split('.')[0])
    if raw_uptime > 86400:
        days    = str(raw_uptime / 60 / 60 / 24).split('.')[0]   + 'd'
    else:
        days = ""
    if raw_uptime > 3600:
        hours   = str((raw_uptime / 60 / 60) % 24).split('.')[0] + 'h'
    else:
        hours = ""
    if raw_uptime > 60:
        minutes = str((raw_uptime / 60) % 60).split('.')[0]      + 'm'
    else:
        minutes = ""
    return f"{days} {hours} {minutes}".strip()

cpu      = get_line("/proc/cpuinfo", 5).split(':')[1][1:]
distro   = get_distro()
editor   = env['EDITOR']
hostname = gethostname()
kernel   = read_file("/proc/sys/kernel/osrelease")
packages = get_packages("portage")
shell    = env['SHELL']
uptime   = get_uptime()
user     = env['USER']
if ("-m" in sys.argv):
    music = get_music()
else:
    music = "[N/A]: -m was not not supplied"
    
print(f"""
cpu      = {cpu}
distro   = {distro}
editor   = {editor}
hostname = {hostname}
kernel   = {kernel}  
packages = {packages}
shell    = {shell}   
uptime   = {uptime}  
user     = {user}
music    = {music}
""")
