Ejemplo n.º 1
0
def update(request):

    books = Book.objects.all()

    for book in books:
        title = book.book_title.rstrip().lstrip().replace('\n', ' ').replace(
            '\r', '')
        description = book.book_description.rstrip().lstrip().replace(
            '\n', ' ').replace('\r', '')

        bookup = Book.objects.filter(id=book.id).update(
            book_title=re.sub(" +", " ", title),
            book_description=re.sub(" +", " ", description))

    return HttpResponse("sesses")
Ejemplo n.º 2
0
def modifalang(request):
    books = Book.objects.all()

    for d in books:
        df = re.sub("-+", " ", d.book_url)
        if d.book_url == "":
            dat = Book.objects.filter(id=d.id).update(
                keyboard=d.book_url[:15],
                book_url=d.book_url[:60].replace(" ", "-"))

    return HttpResponse("not change")
Ejemplo n.º 3
0
def changebook(request, book):
    s = ""
    books = Book.objects.filter(book_url=book)

    for d in books:
        df = re.sub("-+", " ", d.book_url)

        if df == " " or d.book_url == "-" or d.book_url.rstrip().lstrip(
        ) == "":
            trans1 = ''

            data = ""
            if trans1.text == "":
                dat = Book.objects.filter(id=d.id).update(
                    keyboard=d.book_title[:15],
                    book_url=d.book_title[:60].replace(" ", "-"))
            else:

                dat = Book.objects.filter(id=d.id).update(
                    keyboard=data[:15], book_url=data[:60].replace(" ", "-"))

    return HttpResponse("not change")
Ejemplo n.º 4
0
def changelang(request):
    s = ""
    books = Book.objects.all().order_by('-id')

    for d in books:
        df = re.sub("-+", " ", d.book_url)

        if df == " " or d.book_url == "-" or d.book_url.rstrip().lstrip(
        ) == "":

            data = ""
            trans1 = ""
            if trans1 == "":
                dat = Book.objects.filter(id=d.id).update(
                    keyboard=d.book_title[:15],
                    book_url=d.book_title[:60].replace(" ", "-"))
            else:

                dat = Book.objects.filter(id=d.id).update(
                    keyboard=data[:15], book_url=data[:60].replace(" ", "-"))

            print(data[:15])

    return HttpResponse("not change")
Ejemplo n.º 5
0
def hindistory(request, url):
    bdf = Book.objects.all()

    if bdf.count() < 40000:
        return HttpResponse("puh")
    data = ""
    response = requests.get(url)
    if response.status_code == 200:
        soup = BeautifulSoup(response.text)

        d = soup.find("div", attrs={'id': "main-row"})
        if d:
            titles = d.find(
                'h2',
                attrs={'class': 'title-target text-left d-none d-sm-block'})
            title = titles.text
            print(title)

            content = d.find("div",
                             attrs="content-container avoid-text-copy story")

            url = re.sub("^a-zA-Z\u0900-\u097F+", '', title)

            keysearch = '%20'.join(title.split()[:3])
            datad = requests.get(
                "http://google.com/complete/search?output=toolbar&q=" +
                keysearch)

            soupd = BeautifulSoup(datad.text)
            ds = soupd.findAll('suggestion')
            data = ""
            string = []

            for i in ds:
                string.append(i['data'])

            print(",".join(string[:5]))
            catarray = []

            arraycat = d.findAll(
                "a", {
                    "class":
                    'badge badge-light badge-light-hover p-2 rounded-pill mr-1 mb-2 ga-track border border-danger'
                })

            for catd in arraycat:
                cat_check = Category.objects.filter(cat_title=catd.text)
                if cat_check.count() < 1:
                    cats = Category(cat_title=catd.text)
                    cats.save()
                    catarray.append(cats.pk)

                else:
                    catarray.append(cat_check.first().id)

                books = Book.objects.filter(book_title=title)

            description = soup.find("meta", attrs={'name': "description"})

            books = Book.objects.filter(book_title=title)
            img = soup.find("img",
                            attrs={"class": 'rounded shadow-lg d-block'})
            catds = d.find('span', attrs={'class': 'col-sm-6 col-12'})

            catmain = catds.find("a", attrs={'class': 'ga-track'})
            for s in catmain.select('b'):
                s.extract()

            cts = Category.objects.filter(
                cat_title=str(catmain.text.replace(':', "")))
            if cts.count() < 1:
                ctd = Category(cat_title=str(catmain.text.replace(':', "")))
                ctd.save()
                catarray.append(ctd.id)
            else:
                catarray.append(cts[0].id)

            print(img.get('src'))

            if books.count() < 1 and d:
                book = Book(book_title=title,
                            book_description=str(description['content']),
                            book_data=str(content),
                            book_arrcat=catarray,
                            book_rates=2,
                            publisher=1,
                            keyboard=",".join(string[:5]),
                            book_publish=True,
                            book_upload_date=timezone.now(),
                            book_url=url.replace("\n", "").replace(" ", "-"),
                            book_catid=1,
                            book_commit_id=1)

                if img:
                    check_img = requests.get(img.get('src'))
                    if check_img.status_code == 200:
                        try:
                            book.get_remote_image(img.get('src'))
                            print(img.get('src'))
                        except:
                            print("error data")
                        else:
                            print("error data")

                book.save()

    return data
Ejemplo n.º 6
0
def wordpressjson(url, web):
    response = requests.get(url)

    if response.ok:
        #   response = requests.get(url)

        jas = json.loads(response.text)
        caatid = []
        for js in jas:
            title = js['title']['rendered']
            content = js['content']['rendered']
            parsed_html = BeautifulSoup(content)
            for f in parsed_html.select('img'):
                f.extract()

            for f in parsed_html.select('a'):
                f.extract()
            for f in parsed_html.select('script'):
                f.extract()
            description = parsed_html.text[:400]
            cat = js['categories']
            for ca in cat:
                caty = requests.get("https://" + web +
                                    "/wp-json/wp/v2/categories/" + str((ca)))
                #   print(caty.text)
                if caty.status_code == 200:
                    jsc = json.loads(caty.text)
                    catname = jsc['name']
                    cats = Category.objects.filter(cat_title=catname)
                    if cats.count() < 1:
                        catsave = Category(cat_title=catname)
                        catsave.save()

                        caatid.append(catsave.id)
                    else:
                        caatid.append(cats[0].id)
            featured_media = requests.get("https://" + web +
                                          "/wp-json/wp/v2/media/" +
                                          str(js['featured_media']))
            #featured_media  = requests.get(js["_links"]['wp:featuredmedia'][0]['href'])
            #print(featured_media.text)
            img_json = json.loads(featured_media.text)
            #   print(img)
            # img = js['featuredimage']
            books = Book.objects.filter(book_title=title)
            keybord = re.sub(r"[^A-Za-z0-9 ]+", '', title)
            slug = js['slug']
            fgh = re.sub(
                ' +', ' ',
                slug.rstrip().lstrip().replace('\n', ' ').replace('\r', ''))
            focaskey = re.sub(r"[^A-Za-z0-9 ]+", '', fgh)
            urlsd = focaskey.replace(" ", "-").rstrip("-").lstrip("-")

            #  keysearch = '%20'.join(title.split()[:2])
            #  datad = requests.get("http://google.com/complete/search?output=toolbar&q=" + keysearch)

            # soupd = BeautifulSoup(datad.text)
            # d = soupd.findAll('suggestion')
            # data = ""
            # string = []

            #  for i in d:
            #       string.append(i['data'])
            #
            #   print(",".join(string[:5]))

            if books.count() < 1 and js['status'] == "publish":
                book = Book(book_title=title,
                            book_description=description,
                            book_data=str(parsed_html),
                            book_arrcat=caatid,
                            book_rates=2,
                            publisher=1,
                            keyboard="",
                            book_publish=True,
                            book_upload_date=timezone.now(),
                            book_url=urlsd,
                            book_catid=1,
                            book_commit_id=1)

                try:

                    img = img_json['guid']['rendered']

                    book.get_remote_image(img)
                except KeyError:
                    print("no img")

                book.save()