Beispiel #1
0
def celery_get_notification(*args, **kwargs):
    '''Connect to https://notify.unifispot.com/notify.json and get notifications

    '''
    current_app.logger.info(
        '-----------Running celery_get_notification-----------------------')
    accounts = Account.query.all()
    response = requests.get('http://notify.unifispot.com/notify.json')
    response.raise_for_status()
    data = response.json()
    for notify in data.get('notifications'):
        if not Notification.check_notify_added(notify.get('notifi_id')):
            #check if version id specified
            if notify.get('version') and compare_versions(
                    notify.get('version'), version) != 0:
                break
            elif notify.get('min_version') and compare_versions(
                    notify.get('min_version'), version) == 1:
                break
            elif notify.get('max_version') and compare_versions(
                    notify.get('max_version'), version) == -1:
                break
            for account in accounts:
                db.session.add(
                    Notification(content=notify['content'],
                                 notifi_type=notify['notifi_type'],
                                 notifi_id=notify['notifi_id'],
                                 user_id=0,
                                 account_id=account.id))
    db.session.commit()
    return 1