Movatterモバイル変換


[0]ホーム

URL:


Skip to content
Search Gists
Sign in Sign up

Instantly share code, notes, and snippets.

@endolith
Last activeJune 5, 2023 19:48
    • Star(0)You must be signed in to star a gist
    • Fork(0)You must be signed in to fork a gist

    Select an option

    Save endolith/02bc3cf6d6deb879c5cbb530a83f15b7 to your computer and use it in GitHub Desktop.
    Turn BOINC on or off depending on how warm the room is
    #!/usr/bin/env python3
    importsubprocess
    importre
    importdatetime
    importos
    # Set the temperature threshold (in Celsius)
    TEMP_THRESHOLD=25
    # Set the path to the BOINC data directory containing the gui_rpc_auth.cfg file
    boinc_data_dir="/var/lib/boinc-client"
    # Get the current temperature from TemperHum
    temperhum_output=subprocess.check_output("temper-poll -c",shell=True).decode("utf-8")
    current_temperature=float(temperhum_output.strip())
    # Set the absolute path to the log file
    log_file="/home/endolith/temperature/boinc_temperature_control.log"
    # Change the working directory to the BOINC data directory
    os.chdir(boinc_data_dir)
    # Get project status
    project_status_output=subprocess.check_output("boinccmd --get_project_status",shell=True).decode("utf-8")
    # Extract project URLs and their "don't request more work" status
    projects=re.findall(r'master URL: (.+?)\n.*?don\'t request more work: (\w+)',project_status_output,re.DOTALL)
    # Check if the temperature is above the threshold
    ifcurrent_temperature>TEMP_THRESHOLD:
    # Disable new tasks for all projects only if they are not already suspended
    forproject_url,no_more_workinprojects:
    ifno_more_work=="no":
    subprocess.run(f"boinccmd --project{project_url} nomorework",shell=True)
    withopen(log_file,"a")aslog:
    log.write(f"{datetime.datetime.now()} - Temperature:{current_temperature}°C - BOINC tasks suspended for project{project_url}\n")
    else:
    # Enable new tasks for all projects only if they are not already running
    forproject_url,no_more_workinprojects:
    ifno_more_work=="yes":
    subprocess.run(f"boinccmd --project{project_url} allowmorework",shell=True)
    withopen(log_file,"a")aslog:
    log.write(f"{datetime.datetime.now()} - Temperature:{current_temperature}°C - BOINC tasks resumed for project{project_url}\n")
    Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

    [8]ページ先頭

    ©2009-2025 Movatter.jp