Ok for brevity I am assuming that people know how to get a image from a url at regular intervals.
You can create a url with the satellite image centred on your location here:
https://en.sat24.com/en/freeimagesUse the 300x300px option.
Here is the python code (with apologies to real python programmers)
# Important the python PIL library needs to be installed
import os, sys
import Image
import json
# This gets a value for the altitude of the Sun to decide which image to use
# You could use time instead if you haven't got access to a similar value
almanac = open('/var/www/html/VillarPerosa/jsondata/almanac.txt')
data = json.load(almanac)
sun = data["sunalt"]
almanac.close()
pixarray = []
# change the filepaths to the location of the images
if sun > 8:
im = Image.open("/var/www/html/VillarPerosa/sat1.png")
else:
im = Image.open("/var/www/html/VillarPerosa/sat2.png")
# this converts the image to grayscale
im = im.convert('L')
# coordinates for the box at the centre of the image
xpos1 = 145
xpos2 = 155
ypos1 = 145
ypos2 = 155
pix = im.load()
# creates an array with the individual pixel values in the box
for y in range(ypos1,ypos2):
for x in range(xpos1,xpos2):
pixarray.append(pix[x,y])
# takes the average
pixavg = sum(pixarray) / float(len(pixarray))
# calibration, min = totally clear, max = totally overcast
min = 50
max = 250
# an adjustment to align the infrared sat with the visible
adj = 60 * (255 - pixavg)/255
s = pixavg + adj
if sun > 8:
s = pixavg
# cloud cover %
s = (s - min)*100/(max - min)
# result written to a txt file for import into the weewx database.
text_file = open("cloud.txt", "w")
text_file.write(str(s))
text_file.close()
im.close()
Good luck with it!
http://moonappreciationsociety.com/Meteo/VillarPerosa/