rdfindex.py 1.03 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from django.core.management.base import BaseCommand
from etherpadlite.models import Pad
from django.contrib.sites.models import Site
from django.urls import reverse
from aasniff import AAApp


class Conf(object):
    SNIFFERS = [
        'HttpSniffer',
        'HtmlSniffer',
    ]

    STORE = {
        'ENGINE': 'sqlite',
        'NAME': 'aasniff.sqlite',
    }


class Command(BaseCommand):
    args = ''
    help = 'Indexes pages'

    def handle(self, *args, **options):
        HOST = None

        if Site.objects.count() > 0:
            site = Site.objects.all()[0]
            HOST = site.domain

        if not HOST:
            return "No site domain settings found"

        host = u"http://%s" % HOST

        app = AAApp(conf=Conf)

        for pad in Pad.objects.filter():
            url = "{}{}".format(host, reverse('pad-read', kwargs={'mode': 'r', 'slug': pad.display_slug}))
            try:
                app.index(url)
                print(f"indexed {url}")
            except:
                print(f"fail at indexing {url}")