Posted this in the Wrong thread. Syntax issue with .py config file

  • I'm trying to make an install script for the Deskpi Fan case.

    While also knowing pretty much nothing about python.

    (this is an import from the thread that was in the wrong https://forum.libreelec.tv/thread/25435-trying-to-make-an-install-script-for-deskpi-pro-case/?postID=167915#post167915 thread)


    I'm having a hard time with this code:

    I'm pretty sure it's a formatting issue, but I can't seem to figure this part out:

    Code
    try: 
    while True: 
    if ser.isOpen(): 
    cpu_temp=subprocess.getoutput("/opt/vc/bin/vcgencmd measure_temp" | "sed -e "s/temp=//" -e "s/\..*'/ /") 
    cpu_temp=int(cpu_temp.split(.)[0])

    I keep getting errors, regardless of my changes. I get "unsupported operand type(s) for "|:" 'str' and 'str' " or just "syntax errors".

    I also tried:

    Code
    cpu_temp=subprocess.getoutput("/opt/vc/bin/vcgencmd.measure_temp") | "grep" "sed -e s/temp=// -e s/\..*'/ /"
    cpu_temp=float(int(cpu_temp.split('.')[0]) 


    Looks like the error I was getting was because I was trying to take a LITERAL(real number) into an Integer.

    You can't do that, so you have to turn it into a FLOAT.

    Adding "float(" in-front of the other code I had(int(cpu_tempt.split....) "fixed" it.

    But now I'm getting an error here:

    Code
    if cpu_temp < 40:
                    ^
    SyntaxError: invalid syntax

    Honestly I can barely read this, it's a little advanced for me. Can someone please point me in the right direction?

    Anything will help.

    Thanks in advance!

  • I was able to fix this by using :

    Code
    cpu_temp = subprocess.getoutput('vcgencmd measure_temp|awk -F\'=\' \'{print \$2\'}')
    cpu_temp=int(cpu_temp.split('.')[0])

    and by importing serial correctly:

    Code
    import serial
    sys.path.append('/storage/.local/lib/python3.8/site-packages/')