Beispiel #1
0
def run_test(re):
    fl = filters.get_filters(filter_dict)
    if len(fl) != 4:
        return 'Built incorrect list of Filters: %s' % fl, 6
    # print('\n\n')
    ts = test_source.TestPostProducer()
    ts.apply_filters(fl)

    loaded_posts = []
    for e in ts.get_elements():
        loaded_posts.append(e)
        # print(e.title)

    if len(loaded_posts) == 0:
        return 'No posts were matched by test filters!', 5

    for p in loaded_posts:
        # print(p.title)
        if p.created_utc > start_time:
            return 'Invalid parsed time!', 1
        if 're' not in p.title.lower():
            return 'Invalid title!', 2
        if p.score < 1000:
            return 'Invalid score: %s' % p.score, 3
        if any('.com' not in url.lower() for url in p.get_urls()):
            return 'Invalid URL found in Post.', 4

    return '', 0
Beispiel #2
0
def api_get_sources():
    ret = {'available': [], 'active': [], 'filters': {}}
    for s in sources.load_sources():
        ret['available'].append(s.to_obj(for_webui=True))
    for s in settings.get_sources():
        ret['active'].append(s.to_obj(for_webui=True))
    ret['filters']['available'] = [
        f.to_js_obj() for f in filters.get_filters()
    ]
    ret['filters']['operators'] = [f.value for f in filters.Operators]
    return ret
def api_save_sources(new_obj):
    print('Saving new source list:')
    output_settings = []
    for so in new_obj:
        print('\tType:', so['type'], 'Alias:', so['alias'])
        for s in sources.load_sources():
            if s.type == so['type']:
                s.set_alias(so['alias'])
                for k, v in so['data'].items():
                    s.insert_data(k, v)
                for f in so['filters']:
                    for fi in filters.get_filters():
                        if f['field'] == fi.field:
                            fi.set_operator(f['operator'])
                            fi.set_limit(f['limit'])
                            s.add_filter(fi)
                            break
                output_settings.append(s)
    for s in settings.get_sources():
        settings.remove_source(s, save_after=False)
    for s in output_settings:
        settings.add_source(s, prevent_duplicate=False, save_after=False)
    return settings.save()