Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 57746af

Browse files
Merge pull request avinashkranjan#1457 from slayerrr12/master
Updated README Content and Updated Script of CPU TEMPERATURE
2 parents b3f2e89 + fd30783 commit 57746af

File tree

2 files changed

+41
-21
lines changed

2 files changed

+41
-21
lines changed

‎CPU temperature/Readme.md

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,39 @@
11
# CPU Temperature
22

3-
This python script is used to get cpu temperature
3+
This Python script is used to retrieve the CPU temperature using the psutil library.
44

5-
- psutil (process and system utilities) is a cross-platform library.
6-
- It is used for retrieving information on running processes and system utilization (CPU, memory, disks, network, sensors) in Python.
75

8-
## Explanation of the script
6+
## Prerequisites
7+
- Python installed on your machine
8+
- `psutil` library installed. You can install it by running the following command:
9+
```bash
10+
pip install psutil
911

10-
- Using psutil library's inbuilt function "sensors_temperatures()" to measure temperature of CPU
1112

12-
## Setup instructions
13+
## Explanation of the Script
1314

14-
- Clone the repo to your machine
15-
- Head over to the required folder (Cpu Temperature folder)
16-
- Install psutil using
15+
The script utilizes the `psutil` library's `sensors_temperatures()` function to measure the temperature of the CPU.
16+
17+
## Setup Instructions
18+
19+
1. Clone the repository to your local machine.
20+
2. Navigate to the "Cpu Temperature" folder.
21+
3. Install the `psutil` library if you haven't already by running the following command:
1722
```bash
1823
pip install psutil
1924
```
20-
- Run the script
21-
```bash
22-
python temp.py
23-
```
24-
2525
## Output
2626

27-
<img src="https://raw.githubusercontent.com/gavinlyonsrepo/raspberrypi_tempmon/master/screenshots/main_screen.jpg">
27+
The script will display the current CPU temperature in Celsius.
28+
29+
30+
31+
## Compatibility
32+
33+
Please note that the script is primarily designed for Linux-based systems. While it may work on other platforms, the availability and format of temperature information can vary. Ensure that your system supports the `psutil` library and has the necessary sensors for CPU temperature measurement.
34+
35+
## Contributing
36+
37+
Contributions are welcome! If you find any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request.
2838

29-
## Disclaimer
3039

31-
This does not work on a windows machine

‎CPU temperature/temp.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1-
# importing the psutil library
21
import psutil
32

4-
# Note: It is not for windows user
3+
# Function to retrieve CPU temperature
4+
def get_cpu_temperature():
5+
try:
6+
# Retrieve temperature information using psutil
7+
# and access the first temperature value from the 'coretemp' key
8+
temperature = psutil.sensors_temperatures()['coretemp'][0].current
9+
return temperature
10+
except (KeyError, IndexError):
11+
# Handle cases where temperature information is not available
12+
return "CPU temperature information not available."
13+
14+
# Call the get_cpu_temperature() function to get the CPU temperature
15+
cpu_temperature = get_cpu_temperature()
16+
17+
# Print the CPU temperature
18+
print("Current CPU Temperature (Celsius):", cpu_temperature)
519

6-
data = psutil.sensors_temperatures()
7-
print("Current Temperature of CPU (celcius): ", data['coretemp'][0][1])

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /