コード例 #1
0
ファイル: rest.py プロジェクト: djj211/CatFeeder
    def POST(self):
        auth = web.ctx.env.get('HTTP_AUTHORIZATION')
        authreq = False

        if auth is None:
            authreq = True
        else:
            auth = re.sub('^Basic ', '', auth)
            username, password = base64.decodestring(auth).split(':')

            if (username, password) in allowed:
                web.header('Content-Type', 'application/json')
                data = json.loads(web.data())
                feedTime = data["time"]
                feed = Feeder(float(feedTime))
                result = feed.feed()
                successDate = feed.getDate()
                jsonResponse = {'result': result, 'date': successDate}
                return json.dumps(jsonResponse)
            else:
                authreq = True

        if authreq:
            web.header('WWW-Authenticate', 'Basic realm="Cat Feeder"')
            web.ctx.status = '401 Unauthorized'
            return
コード例 #2
0
ファイル: rest.py プロジェクト: djj211/CatFeeder
    def POST(self):
        auth = web.ctx.env.get('HTTP_AUTHORIZATION')
        authreq = False

        if auth is None:
            authreq = True
        else:
            auth = re.sub('^Basic ', '', auth)
            username, password = base64.decodestring(auth).split(':')
            if (username, password) in allowed:
                web.header('Content-Type', 'application/json')
                jsonResponse = {'date': Feeder.getDate()}
                return json.dumps(jsonResponse)
            else:
                authreq = True

        if authreq:
            web.header('WWW-Authenticate', 'Basic realm="Cat Feeder"')
            web.ctx.status = '401 Unauthorized'
            return
コード例 #3
0
ファイル: feedCats.py プロジェクト: djj211/CatFeeder
from feeder import Feeder
from datetime import datetime, timedelta

datetime_object = datetime.strptime(Feeder.getDate(), '%Y-%m-%d %H:%M:%S')

if datetime_object < datetime.now() - timedelta(hours=4):
    feed = Feeder()
    feed.feed()