Script that ask when a feed/input was last updated

since we dont have the feedtime widgit on i wonder if a python script could be hammered up that would ask when a given feed/input was last updated and if more than 5 mins ago i could use that to turn on a LED to signal that something is going on

gives me: {“time”:1522144019,“value”:“22”}

what time format is that? unix of some sorts?

It’s JSON and the timestamp is Unix (seconds since 00:00 01/01/1970)

The Python time module uses the same format so time.time() - 1522144019 = seconds since last update.

Look at the Python json module to decode the reply into a Python dict which you can the access the values using their names eg reply[‘time’] and reply[‘value’].

oki, will be on it

this is just an alternative to not having the feedtime widget :slight_smile:

first rough cut:

#!/usr/bin/env python

    # For Python 3.0 and later
    from urllib.request import urlopen
except ImportError:
    # Fall back to Python 2's urllib2
    from urllib2 import urlopen

import json
import time

#this one is for the wiringpi lib

import wiringpi

# wiringpi numbers

wiringpi.pinMode(0, 1)  # sets pin 0 to output (GPIO 17, Actual hardware pin number is 11) (Relay)

def get_jsonparsed_data(url):
    Receive the content of ``url``, parse it as JSON and return the object.

    url : str

    response = urlopen(url)
    data ="utf-8")
    return json.loads(data)

url = ("")

while True:

    dif = time.time() - (get_jsonparsed_data(url))['time']
    print dif
    if dif  >  60:
        print 'Last update is more than 5 mins ago'
        wiringpi.digitalWrite(0, 1) # sets port 0 to ON
        print 'Last update is less than 5 mins ago'
        wiringpi.digitalWrite(0, 0) # sets port 0 to OFF