Пример #1
0
def pod():
    form2 = Titles()

    title = "Submit " + str(app)
    username = "******"

    if form2.validate_on_submit():
        book = Books()
        book.title = form2.title.data
        book.author = form2.author.data
        book.description = form2.description.data
        try:
            book.username = username
        except AttributeError:
            book.username = "******"
        s = "abcdefghijklmnopqrstuvwxyz"
        passlen = 6
        book.uri = "".join(random.sample(s, passlen))
        this_bot = Bots.query.filter_by(username="******").first()
        try:
            client_id = this_bot.client_id
        except AttributeError:
            return redirect("/")
        secret = this_bot.secret
        password = this_bot.password
        username = this_bot.username
        reddit = praw.Reddit(client_id=client_id,
                             client_secret=secret, password=password,
                             user_agent='Copypasta', username="******")

        try:
            reddit_url = reddit.subreddit('publishcopypasta').name
        except praw.exceptions.APIException:
            reddit_url = "No url"
        post = RedditPost(uri=book.uri, reddit_url=reddit_url, title=book.title, body=book.description,
                          username=book.username)
        book.reddit_url = reddit_url
        db.session.add(post)
        db.session.commit()
        db.session.add(book)
        db.session.commit()
        return redirect("/")
Пример #2
0
def push():
    form2 = Titles()

    texts=[]
    if form2.validate_on_submit():
        book = Books()
        book.title = form2.title.data
        book.author = form2.author.data
        book.description = form2.description.data
        try:
            book.username = "******"
        except AttributeError:
            book.username = "******"
        s = "abcdefghijklmnopqrstuvwxyzACDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
        passlen = 30
        book.uri = "".join(random.sample(s, passlen))

        kw = book.description
        title = book.title
        author = book.author
        client_id="GIsPYS_nLIS2Og"
        secret = "pytvKc3PHjebQIhOaOKc88PqRxI"
        password = "******"
        username = "******"
        reddit = praw.Reddit(client_id=client_id,
                             client_secret=secret, password=password,
                             user_agent='Copypasta', username=username)

        reddit_url = "http://www.reddit.com/r/astrapocalypse"

        post = RedditPost(uri=book.uri, reddit_url=reddit_url, title=book.title, body=book.description,
                          username=book.username)
        book.reddit_url = reddit_url
        db.session.add(post)
        db.session.commit()
        db.session.add(book)
        db.session.commit()
        return redirect("/")

    elif request.args.get("key"):
        key=request.args.get("key")

        count=Books.query.filter_by(uri=key).count()
        if count>0:
            content=Books.query.filter_by(uri=key).first()
            reply= content.author
            return reply
        else:
            reddit = praw.Reddit(client_id='FCBZa-yDqRLNag', client_secret="secret", password='******', user_agent='Copypasta', username="******")
            for submission in reddit.subreddit(key).new():

                if request.args.get("yes"):
                    reply=reply+" " + submission.title+" "
                else:
                    reply=reply+" " + submission.selftext+" "
            return reply
    else:

        if request.args.get("key"):
            key=request.args.get("key")
            count=Books.query.filter_by(uri=key).count()
            if count>0:
                content=Books.query.filter_by(uri=key).first()
                return render_template_string(str(content.description))
            else:
                url = 'https://www.reddit.com/r/' + key + '/new/.json?limit=500'

                data = requests.get(url, headers={'user-agent': 'scraper by /u/ciwi'}).json()

                for link in data['data']['children']:
                    body = link['data']['selftext']
                    texts.append(body.replace("\\","").replace("}","").replace("{",""))
                newt="<br><br>".join(texts)
                return render_template_string(Markup(newt))
        else:
            content = Books.query.filter_by(username="******").all()
            string_response =  "<html>{%include 'header.html'%}<body>{%include 'books.html'%}"
            for box in content:
                string_response = string_response +"<h3>name: " + box.title + "</h3>"
                string_response = string_response +"<br><big>keyname: <a href='/?key="+ box.uri+"'>"+box.uri+ "</big></a><br>url:<a href='"+box.description+"'>"
                string_response = string_response + box.description+"</a>"
            return render_template_string(string_response+"</html></body>", form2=form2)