I was recently looking into creating a small fan controller script and needed to get reliable access to the current CPU temperature. After a bit of research I came up with the following code that takes advantage of data published (via shared memory) by the popular SpeedFan program..

One obvious issue here is that SpeedFan doesn't tell us which values are associated with which bits of hardware so you'll likely have to customise anything you do with this to the current machine.
Anyway, feel free to use this for whatever you like.