def notification(title, message):
        """Sends a new OS X notification

        .. seealso: :func:`utils.send_notification`.

        :param title: the title of the notification.
        :type title: ``str``.
        :param message:  the message to be displayed in the notification.
        :type message: ``str``.
        """
        send_notification(title, message)
Ejemplo n.º 2
0
    def notification(title, message):
        """Sends a new OS X notification

        .. seealso: :func:`utils.send_notification`.

        :param title: the title of the notification.
        :type title: ``str``.
        :param message:  the message to be displayed in the notification.
        :type message: ``str``.
        """
        send_notification(title, message)
Ejemplo n.º 3
0
def broadcast_notification(request):
    user_ids = request.GET.get('ids').split(',')

    if request.method == "POST":
        message = request.POST["title"]
        custom = {"message": request.POST["text"]}

        for nf in UserNotification.objects.filter(user_id__in=user_ids):
            send_notification(custom, message, nf)

    return render(request, 'send_push.html')
Ejemplo n.º 4
0
def process_productivity(config, task):
	today = utils.send_request(config, perspective="interval", resolution_time="day", restrict_kind="efficiency")
	productivity_score = today.at[0, "Efficiency (percent)"]

	today = utils.send_request(config, perspective="interval", resolution_time="day", restrict_kind="productivity")
	very_productive_min = utils.extract_from_cell(today, 'Time', 'Productivity', 2) or 0
	productive_min = utils.extract_from_cell(today, 'Time', 'Productivity', 1) or 0
	time_remaining = task['minutes'] - (very_productive_min + productive_min)
	time_remaining = time_remaining if time_remaining > 0 else 0

	utils.send_notification("You are %d percent productive so far!\n" \
		"You have %d minutes out of %d minutes goal ahead of you."
		% (productivity_score, time_remaining, task['minutes']))
Ejemplo n.º 5
0
def process_category(config, task):
	today = utils.send_request(config, perspective="rank", restrict_kind="overview")
	time_spent = utils.extract_from_cell(today, 'Time', 'Category', task['slice_name'])

	if time_spent:
		if config.doPlot:
			utils.plot_df(today, 'Category', 'Time')

		# send notification
		if task['task_type'] == 'limit':
			if time_spent > task['minutes']:
				utils.send_notification("Ooops you've spent %d minutes out of %d minutes limit on %s today." \
					% (time_spent, task['minutes'], task['slice_name']))
		elif task['task_type'] == 'goal':
			if time_spent < task['minutes']:
				utils.send_notification("Work harder! You have %d minutes out of %d minutes goal ahead of you to work on %s" \
					% (task['minutes'] - time_spent, task['minutes'], task['slice_name']))
Ejemplo n.º 6
0
    def _send_notifications(self, messages_by_email, template):
        """
        Send the notifications described in the `messages_by_email` data
        structure, using the specified EmailTemplate.

        `messages_by_email` should be a dictionary, keyed by email
        address. The values should be dictionaries suitable to be passed
        as kwargs (options) to the template.
        """
        portal = self.getSite()
        email_tool = portal.getEmailTool()
        addr_from = email_tool.get_addr_from()
        for addr_to, kwargs in messages_by_email.iteritems():
            translate = self.portal_i18n.get_translation
            kwargs.update({'portal': portal, '_translate': translate})
            mail_data = template(**kwargs)
            notif_logger.info('.. sending notification to %r', addr_to)
            utils.send_notification(email_tool, addr_from, addr_to,
                mail_data['subject'], mail_data['body_text'])
Ejemplo n.º 7
0
    if utils.is_expense(comment_text):
        ZohoAPI.create_expense_record(comment_text)
        continue
    if utils.is_assistant_transfer(comment_text):
        ZohoAPI.create_assistant_transaction(comment_text)
        continue
    if utils.is_exchange(comment_text):
        ZohoAPI.create_exchange_transaction(comment_text)
    if utils.is_checking_balance(comment_text):
        balance = utils.clear_amount(ZohoAPI.get_balance(comment_text))

        cash = utils.extract_comment_entities(comment_text).get(
            'expense_amount')
        cash_amount = utils.clear_amount(cash)

        diff = balance - cash_amount
        amount = ''
        if diff != 0:
            if utils.is_usd_amount(cash):
                amount = f'${diff}'
            elif utils.is_eur_amount(cash):
                amount = f'{diff}eur'
            else:
                amount = diff
            print(amount)
            ZohoAPI.create_expense_record(
                f'unknown::{amount}::разница из остатка')
        continue
    else:
        utils.send_notification(comment_text)
Ejemplo n.º 8
0
def upload_manager():
    global config, default_check_interval
    try:
        default_check_interval = config['local_folder_check_interval']
        logger.debug("Started upload manager for %r", config['local_folder'])
        while True:
            time.sleep(60 * config['local_folder_check_interval'])

            # restore check interval to original after an extended sleep after a rate limit ban (25hrs)
            if config['local_folder_check_interval'] == 1500:
                config['local_folder_check_interval'] = default_check_interval
                logger.info(
                    "Restored local_folder_check_interval to %d minutes after an extended sleep (25 hours) due "
                    "to the last upload being cancelled due to rate limits!",
                    config['local_folder_check_interval'])

                utils.send_notification(
                    config,
                    "local_folder_check_interval has been reset back to %d minutes after a 25 hour "
                    "sleep due to ratelimits!" %
                    config['local_folder_check_interval'])

            logger.debug("Checking size of %r", config['local_folder'])
            size = utils.folder_size(config['local_folder'],
                                     config['du_excludes'])
            if size is not None and size > 0:
                if size >= config['local_folder_size']:
                    logger.debug("Local folder has %d gigabytes, %d too many!",
                                 size, size - config['local_folder_size'])

                    # check if files are opened, skip this upload if so
                    opened_files = utils.opened_files(config['local_folder'],
                                                      config['lsof_excludes'])
                    if opened_files:
                        for item in opened_files:
                            logger.debug("File is being accessed: %r", item)
                        logger.debug(
                            "Local folder has %d file(s) open, skipping upload until next check...",
                            len(opened_files))
                        # send skip notification
                        utils.send_notification(
                            config,
                            "Upload process of %d gigabytes temporarily skipped.\n"
                            "%d file(s) are currently being accessed." %
                            (size, len(opened_files)))
                        continue

                    # remove hidden before upload
                    # (we don't want to delete a hidden from remote, after already replacing it)
                    logger.debug("Purging _HIDDEN~ before upload commences")
                    remove_hidden()

                    # send start notification
                    utils.send_notification(
                        config,
                        "Upload process started. %d gigabytes to upload." %
                        size)

                    # rclone move local_folder to local_remote
                    logger.debug("Moving data from %r to %r...",
                                 config['local_folder'],
                                 config['local_remote'])
                    upload_cmd = utils.rclone_move_command(
                        config['local_folder'], config['local_remote'],
                        config['rclone_transfers'], config['rclone_checkers'],
                        config['rclone_bwlimit'], config['rclone_excludes'],
                        config['rclone_chunk_size'], config['dry_run'])
                    logger.debug("Using: %r", upload_cmd)

                    start_time = timeit.default_timer()
                    utils.run_command(upload_cmd, config)
                    time_taken = timeit.default_timer() - start_time
                    logger.debug("Moving finished in %s",
                                 utils.seconds_to_string(time_taken))

                    # remove empty directories
                    if len(config['rclone_remove_empty_on_upload']):
                        time.sleep(5)
                        utils.remove_empty_directories(config)

                    new_size = utils.folder_size(config['local_folder'],
                                                 config['du_excludes'])
                    logger.debug("Local folder is now left with %d gigabytes",
                                 new_size)

                    # send finish notification
                    utils.send_notification(
                        config,
                        "Upload process finished in %s. %d gigabytes left over."
                        % (utils.seconds_to_string(time_taken), new_size))

                else:
                    logger.debug(
                        "Local folder is still under the max size by %d gigabytes",
                        config['local_folder_size'] - size)

    except Exception as ex:
        logger.exception("Exception occurred: ")
from laptop_price_scraper import LaptoppriceSpider
from utils import get_past_data, save_data, send_notification

MESSAGE_TEMPLATE = 'Price Change detected\nASIN:{}\nOld Price:{}\t\tNew Price:{}'

if __name__ == "__main__":

    amazon_data = []
    settings = get_project_settings()
    process = CrawlerProcess(settings)
    process.crawl(LaptoppriceSpider, amazon_data)
    process.start()

    curr_df = pd.DataFrame(amazon_data)

    old_data = get_past_data()

    if len(old_data) != 0:
        for i in range(len(curr_df)):
            price = curr_df['price'].iloc[i]
            asin = curr_df['asin'].iloc[i]

            old_price = old_data[old_data['asin'] == asin]['price'].iloc[0]
            if old_price != price:
                message = MESSAGE_TEMPLATE.format(asin, old_price, price)
                print(message)
                send_notification(message)

    save_data(curr_df)