Ejemplo n.º 1
0
def send_name(filename):
	'''Send the notification for the notice of given json filename'''
	logging.debug("called : %s", __name__)
	logging.debug("argument filename : %s", filename)

	if filename is None:
		logging.error("empty filename received")
		return

	n = Notice(filename)
	notice = n.get_json()

	# If the notice is not updated, update it.
	logging.debug("checking if notice is updated")
	if not notice['updated']:
		update.update_json(filename)
		notice = n.get_json()

	# If the notice is not sent, send it.
	logging.debug("checking if notice is sent")
	if not notice['sent']:
		if send_json(notice):
			# If notice is sent, save it locally. So that it is not
			# sent again.
			logging.debug("notice is sent - saving it locally")
			notice['sent'] = True
			n.save_json(notice)
			return True
		else:
			logging.error("failed sending notice")
			return False
	else:
		logging.debug("notice is already sent")
		return False
Ejemplo n.º 2
0
def send_name(filename):
    '''Send the notification for the notice of given json filename'''
    logging.debug("called : %s", __name__)
    logging.debug("argument filename : %s", filename)

    if filename is None:
        logging.error("empty filename received")
        return

    n = Notice(filename)
    notice = n.get_json()

    # If the notice is not updated, update it.
    logging.debug("checking if notice is updated")
    if not notice['updated']:
        update.update_json(filename)
        notice = n.get_json()

    # If the notice is not sent, send it.
    logging.debug("checking if notice is sent")
    if not notice['sent']:
        if send_json(notice):
            # If notice is sent, save it locally. So that it is not
            # sent again.
            logging.debug("notice is sent - saving it locally")
            notice['sent'] = True
            n.save_json(notice)
            return True
        else:
            logging.error("failed sending notice")
            return False
    else:
        logging.debug("notice is already sent")
        return False
Ejemplo n.º 3
0
def get_text_path(path):
	"""
	Given path to json file, return a formatted body string with all the details
	"""
	logging.debug("called : %s", __name__)
	logging.debug("argument path : ", path)
	n = Notice(path)
	notice = n.get_json()
	return get_text_dict(notice)
Ejemplo n.º 4
0
def get_text_path(path):
    """
	Given path to json file, return a formatted body string with all the details
	"""
    logging.debug("called : %s", __name__)
    logging.debug("argument path : ", path)
    n = Notice(path)
    notice = n.get_json()
    return get_text_dict(notice)
Ejemplo n.º 5
0
def sent_false():
	logging.debug('called : sent_false')
	root = os.path.abspath(os.path.dirname(__file__))
	path = root + '/gen/json/'
	listfile = os.listdir(path)
	if 'old' in listfile:
		listfile.remove('old')
	for fl in listfile:
		n = Notice(fl)
		notice = n.get_json()
		if not notice['sent']:
			notice['sent'] = True
			n.save_json(notice)
Ejemplo n.º 6
0
def update_json(name):
    logging.debug("called : %s", __name__)
    logging.debug("argument name : %s", name)

    path = jsondir + name
    if not os.path.isfile(path):
        logging.error("json file '%s' is not present.", path)
        return

    n = Notice(name)
    notice = n.get_json()

    # If the json is erroneous, i.e, has empty fields like topic etc, start
    # fresh by removing the json file. This way the json will be reloaded at
    # next cron update.
    if erroneous_json(notice):
        logging.error("Encountered errnoneous json %s. Deleting.", str(path))
        os.remove(path)
        return False

    # If notice is updated, do not update it once more.
    if notice['updated']:
        logging.info("notice %s is already updated", name)
        return False

    details = get_details_url(notice['url'], notice['num_attachments'] == 1)

    logging.debug(
        "Notice has been updated with information from the notice	page")
    notice['updated'] = True
    notice['text'] = details['text']
    if notice['num_attachments'] == 1:
        notice['attachments'] = details['attachments']
        notice['num_attachments'] = len(details['attachments'])

    logging.debug('Saving the updated notice')
    n.save_json(notice)

    return True
Ejemplo n.º 7
0
def update_json(name):
    logging.debug("called : %s", __name__)
    logging.debug("argument name : %s", name)

    path = jsondir + name
    if not os.path.isfile(path):
        logging.error("json file '%s' is not present.", path)
        return

    n = Notice(name)
    notice = n.get_json()

    # If the json is erroneous, i.e, has empty fields like topic etc, start
    # fresh by removing the json file. This way the json will be reloaded at
    # next cron update.
    if erroneous_json(notice):
        logging.error("Encountered errnoneous json %s. Deleting.", str(path))
        os.remove(path)
        return False

        # If notice is updated, do not update it once more.
    if notice["updated"]:
        logging.info("notice %s is already updated", name)
        return False

    details = get_details_url(notice["url"], notice["num_attachments"] == 1)

    logging.debug("Notice has been updated with information from the notice	page")
    notice["updated"] = True
    notice["text"] = details["text"]
    if notice["num_attachments"] == 1:
        notice["attachments"] = details["attachments"]
        notice["num_attachments"] = len(details["attachments"])

    logging.debug("Saving the updated notice")
    n.save_json(notice)

    return True