Exemple #1
0
    def run(self):
        result = {
            'items': [],
            'success': True,
            'error': None
        }
        try:

            user_storage = UserStorage.UserStorage()
            user = user_storage.get_user()
            favourites = self.storage.get_user_favourites(user)
            dict_favourites = []
            for favourite in favourites:
                favourite = dict(favourite)
                del(favourite['_id'])
                dict_favourites.append(favourite)
            favourites_by_name = sorted(dict_favourites, key=lambda fav: fav['card_title'], reverse=True)
            result['items'].append({
                'favourites': favourites_by_name
            })

        except Exception as e:
            result['error'] = str(e)
            result['success'] = False
            self.logger.add_entry(self.__class__.__name__, e)

        return result
Exemple #2
0
    def run(self, card_id, text):
        result = {
            'items': [],
            'success': True,
            'error': None
        }
        try:

            user_storage = UserStorage.UserStorage()
            user = user_storage.get_user()
            shout_out = self.so_storage.add_shout_out(card_id, text, user['id'])
            is_added = False
            if shout_out is not None:
                is_added = True
                notification_exists = self.notification_storage.un_notified_notification_exists(card_id, user['id'])
                if notification_exists is False:
                    self.notification_storage.add_notification(card_id, text, user['id'], True)
                shout_out = dict(shout_out)
                shout_out['short'] = user['short']
                shout_out['name'] = user['name']
            result['items'].append({
                'is_added': is_added,
                'shout_out': shout_out
            })

        except Exception as e:
            result['error'] = str(e)
            result['success'] = False
            self.logger.add_entry(self.__class__.__name__, e)

        return result
Exemple #3
0
    def create_card(self, title, text, keywords, external_link):
        user_storage = UserStorage.UserStorage()
        user = user_storage.get_user()

        card = Card.Card()
        card.id = self.get_next_card_id()
        card.title = title
        card.text = text
        card.keywords = keywords.split(',')
        card.created = time.time()
        card.changed = time.time()
        card.external_link = external_link
        card.type = 'fact'
        card.author = user['short']
        card.editors = [user['short']]
        self.store_card(dict(card))

        return card.id
Exemple #4
0
    def run(self):
        result = {'items': [], 'success': True, 'error': None}
        try:
            user_storage = UserStorage.UserStorage()
            user = user_storage.get_user()
            fact_count = self.info.get_fact_count()
            idea_count = self.info.get_idea_count()
            result['items'].append({
                'user_name': user['name'],
                'user_short': user['short'],
                'fact_count': fact_count,
                'idea_count': idea_count
            })

        except Exception as e:
            result['error'] = str(e)
            result['success'] = False
            self.logger.add_entry(self.__class__.__name__, e)

        return result
Exemple #5
0
    def run(self):
        result = {'items': [], 'success': True, 'error': None}
        try:
            user_storage = UserStorage.UserStorage()
            found_shout_outs = []
            shout_outs = self.so_storage.get_shout_outs()
            for shout_out in shout_outs:
                if shout_out['user_id'] is not None:
                    so_user = user_storage.get_user_by_id(shout_out['user_id'])
                    shout_out['short'] = so_user['short']
                    shout_out['name'] = so_user['name']
                if '_id' in shout_out:
                    del (shout_out['_id'])
                found_shout_outs.append(shout_out)
            result['items'].append({'shout_outs': found_shout_outs})

        except Exception as e:
            result['error'] = str(e)
            result['success'] = False
            self.logger.add_entry(self.__class__.__name__, e)

        return result
Exemple #6
0
    def run(self, name):
        result = {
            'message': '',
            'success': True,
            'error': None
        }
        try:

            user_storage = UserStorage.UserStorage()
            try:
                user_storage.rename_user(name)
                result['message'] = 'Name geändert'
            except Exception as e:
                result['message'] = str(e)
                result['success'] = False

        except Exception as e:
            result['error'] = str(e)
            result['success'] = False
            self.logger.add_entry(self.__class__.__name__, e)

        return result
Exemple #7
0
    def run(self, card_id):
        result = {'items': [], 'success': True, 'error': None}
        try:

            user_storage = UserStorage.UserStorage()
            user = user_storage.get_user()
            card = self.card_storage.get_card(card_id)
            favourite, is_added = self.favourite_storage.toggle_favourite(
                card, user)
            if favourite is not None:
                favourite = dict(favourite)
            result['items'].append({
                'is_added': is_added,
                'favourite': favourite
            })

        except Exception as e:
            result['error'] = str(e)
            result['success'] = False
            self.logger.add_entry(self.__class__.__name__, e)

        return result
Exemple #8
0
    def run(self):
        result = {'items': [], 'success': True, 'error': None}
        try:

            user_storage = UserStorage.UserStorage()
            user = user_storage.get_user()
            dict_notifications = []
            notifications = self.notification_storage.get_notifications(
                user['id'])
            self.notification_storage.flag_notifications_as_notified(
                notifications)
            for notification in notifications:
                notification = dict(notification)
                if '_id' in notification:
                    del (notification['_id'])
                dict_notifications.append(dict(notification))
            result['items'].append({'notifications': dict_notifications})

        except Exception as e:
            result['error'] = str(e)
            result['success'] = False
            self.logger.add_entry(self.__class__.__name__, e)

        return result
Exemple #9
0
def phoenix(request):

    user_storage = UserStorage.UserStorage()
    user_exists = user_storage.user_exists()
    if user_exists is False:
        user_storage.create_user()

    function = request.args.get('function', None)
    if function == 'Ping':
        ping = Ping.Ping()
        response = ping.run()
    elif function == 'Latest':
        latest = Latest.Latest()
        response = latest.run()
    elif function == 'Search':
        query = request.args.get('query', None)
        search = Search.Search()
        response = search.run(query)
    elif function == 'AutoComplete':
        query = request.args.get('query', None)
        auto_complete = AutoComplete.AutoComplete()
        response = auto_complete.run(query)
    elif function == 'Click':
        card_id = int(request.args.get('card_id', 0))
        loading_seconds = int(request.args.get('loading_seconds', 0))
        query = request.args.get('query', None)
        frontend = request.args.get('frontend', '')
        click = Click.Click()
        response = click.run(card_id, query, loading_seconds, frontend)
    elif function == 'Store':
        title = str(request.args.get('title', ''))
        text = str(request.args.get('text', ''))
        keywords = str(request.args.get('keywords', ''))
        card_id = int(request.args.get('card_id', 0))
        external_link = str(request.args.get('external_link', ''))
        store = Store.Store()
        response = store.run(title, text, keywords, external_link, card_id)
    elif function == 'Keywords':
        title = str(request.args.get('title', ''))
        text = str(request.args.get('text', ''))
        keywords = Keywords.Keywords()
        response = keywords.run(title, text)
    elif function == 'Favourite':
        card_id = int(request.args.get('card_id', 0))
        favourite = Favourite.Favourite()
        response = favourite.run(card_id)
    elif function == 'Favourites':
        favourites = Favourites.Favourites()
        response = favourites.run()
    elif function == 'Analytics':
        analytics = Analytics.Analytics()
        response = analytics.run()
    elif function == 'ShoutOut':
        card_id = int(request.args.get('card_id', 0))
        text = str(request.args.get('text', ''))
        shout_out = ShoutOut.ShoutOut()
        response = shout_out.run(card_id, text)
    elif function == 'Name':
        name = str(request.args.get('name', ''))
        name_mod = Name.Name()
        response = name_mod.run(name)
    elif function == 'ShoutOuts':
        shout_outs = ShoutOuts.ShoutOuts()
        response = shout_outs.run()
    elif function == 'Notifications':
        notifications = Notifications.Notifications()
        response = notifications.run()
    else:
        response = {'error': 'unknown function'}

    json_response = json.dumps(response)
    return Response(json_response,
                    mimetype='application/json',
                    headers={'Access-Control-Allow-Origin': '*'})