Exemple #1
0
def buy(user, *products):
    """
	Takes a user id (sci login name) and a list of products
	(db id, may still require casting) and adds the bill to the intranet.

	In case of a communication error this method blocks and retries to
	add the bill to the intranet.

	If the bill was added successfully True is returned. Otherwise,
	if the given user is not allowed to purchase things or a products
	is unknown, False is returned.
	"""
    logger = logging.getLogger("remote:buy")
    beverages = encode_buy(products)
    payload = {'buy': {'beverages': beverages, 'user': user}}
    headers = {'content-type': 'application/json'}
    # HTTP-200 -> ok
    # HTTP-422 -> scanned user is not allowed to buy stuff
    # HTTP-otherwise -> something went wrong, retry
    logger.info("init buy sequence")
    try_sync = True
    while True:
        try:
            r = requests.put(URL_BUY,
                             data=json.dumps(payload),
                             headers=headers,
                             auth=(AUTH_USER, AUTH_PASSWORD))
            if r.status_code == 200:
                logger.info("...everything worked fine")
                return True
            elif r.status_code == 422:
                # sync
                if not try_sync:
                    logger.critical(
                        "...did not work (user or product unknown by FSIntra)")
                    return False
                else:
                    logger.error(
                        "...did not work (user or product unknown by FSIntra) -> syncing"
                    )
                    try_sync = True
                    from product_list import PRODUCT_LIST
                    PRODUCT_LIST.update()
            else:
                # something went terribly wrong, retry
                logger.critical("...worked perfectly wrong")
                LCD.message_on(**MSG_BUY_RETRY)
                time.sleep(MSG_BUY_RETRY_WAIT)
        except requests.ConnectionError:
            logger.critical("connection refused. Are you online")
            LCD.message_on(**MSG_BUY_RETRY)
            time.sleep(MSG_BUY_RETRY_WAIT)
Exemple #2
0
def buy(user, *products):
	"""
	Takes a user id (sci login name) and a list of products
	(db id, may still require casting) and adds the bill to the intranet.

	In case of a communication error this method blocks and retries to
	add the bill to the intranet.

	If the bill was added successfully True is returned. Otherwise,
	if the given user is not allowed to purchase things or a products
	is unknown, False is returned.
	"""
	logger = logging.getLogger("remote:buy")
	beverages = encode_buy(products)
	payload = {'buy': {'beverages': beverages, 'user': user}}
	headers = {'content-type': 'application/json'}
	# HTTP-200 -> ok
	# HTTP-422 -> scanned user is not allowed to buy stuff
	# HTTP-otherwise -> something went wrong, retry
	logger.info("init buy sequence")
	try_sync = True
	while True:
		try:
			r = requests.put(URL_BUY, data=json.dumps(payload), headers=headers, auth=(AUTH_USER, AUTH_PASSWORD))
			if r.status_code == 200:
				logger.info("...everything worked fine")
				return True
			elif r.status_code == 422:
				# sync
				if not try_sync:
					logger.critical("...did not work (user or product unknown by FSIntra)")
					return False
				else:
					logger.error("...did not work (user or product unknown by FSIntra) -> syncing")
					try_sync = True
					from product_list import PRODUCT_LIST
					PRODUCT_LIST.update()
			else:
				# something went terribly wrong, retry
				logger.critical("...worked perfectly wrong")
				LCD.message_on(**MSG_BUY_RETRY)
				time.sleep(MSG_BUY_RETRY_WAIT)
		except requests.ConnectionError:
			logger.critical("connection refused. Are you online")
			LCD.message_on(**MSG_BUY_RETRY)
			time.sleep(MSG_BUY_RETRY_WAIT)
Exemple #3
0
def sync():
	logger = logging.getLogger("actions:sync")
	logger.info("syncing...")
	_gui.message_on(**MSG_SYNC_ON)
	success = PRODUCT_LIST.update()
	time.sleep(MSG_SYNC_DELAY)
	if success:
		_gui.message(**MSG_SYNC_SUCCESS)
		logger.info("sync successful")
	else:
		_gui.message(**MSG_SYNC_FAILED)
		logger.error("sync failed")
Exemple #4
0
def sync():
    logger = logging.getLogger("actions:sync")
    logger.info("syncing...")
    _gui.message_on(**MSG_SYNC_ON)
    success = PRODUCT_LIST.update()
    time.sleep(MSG_SYNC_DELAY)
    if success:
        _gui.message(**MSG_SYNC_SUCCESS)
        logger.info("sync successful")
    else:
        _gui.message(**MSG_SYNC_FAILED)
        logger.error("sync failed")
Exemple #5
0
def auto_sync():
	logger = logging.getLogger("actions:auto_sync")
	logger.info("cowardly syncing...")
	# this is harpooning automagically during idle time - do not display anything
	PRODUCT_LIST.update()
Exemple #6
0
def auto_sync():
    logger = logging.getLogger("actions:auto_sync")
    logger.info("cowardly syncing...")
    # this is harpooning automagically during idle time - do not display anything
    PRODUCT_LIST.update()