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("/")
async def babelli(ctx, arg, arg2): msg = "" key = arg url = "https://oaflopean.pythonanywhere.com/?key=" + key data = requests.post(url, auth=('oaflopean', 'babellibot')) text_model = markovify.Text(data.content.decode("utf-8")) for i in range(int(arg2)): try: msg = msg + " " + text_model.make_sentence() + " " except TypeError: continue print(data) if len(msg) == 0: await ctx.send("Sorry! Try more options.") else: chunks, chunk_size = len(msg), len(msg) / (len(msg) / 1995) list = [ msg[i:i + int(chunk_size)] for i in range(0, chunks, int(chunk_size)) ] for msg_pt in list: await ctx.send(msg_pt) book = Books() book.title = arg + " " + str(arg2) book.author = ctx.message.author.name book.description = msg s = "abcdefghijklmnopqrstuvwxyz" passlen = 12 book.uri = "".join(random.sample(s, passlen)) book.reddit_url = "http://oaflopean.pythonanywhere.com/?key=" + book.uri post = RedditPost(uri=book.uri, reddit_url=book.reddit_url, title=book.title, body=book.description, username=book.username) db.session.add(post) db.session.commit() db.session.add(book) db.session.commit() await ctx.send(book.reddit_url)
async def library(ctx, arg, arg2): if arg == "search": try: search = Books.query.filter( or_( func.lower(Books.title).contains(arg2), (func.lower(Books.author).contains(arg2)))).all() for books in search[:25]: await ctx.send(books.title + " by " + books.author + " https://oaflopean.pythonanywhere.com/?key=" + books.uri) except Exception as e: await ctx.send("error: " + e) elif arg == "add": if arg2 == "all": books = Books.query.filter().all() a = open("babelli-copypasta.json", mode="r") b = a.read() c = {} json1 = json.loads(b) for bookid in json1.keys(): books = Books.query.filter(Books.uri == str(bookid)).first() if books.uri: await ctx.send( books.title + " by " + books.author + " https://oaflopean.pythonanywhere.com/?key=" + books.uri + " already existed") else: json2 = json1[str(bookid)] book = Books() book.title = json2.title book.author = json2.author s3 = boto3.client( 's3', aws_access_key_id="python", aws_secret_access_key="ZPRZ5P6LFLB64B7KE554", region_name="sfo2") one = 0 for one in range(100): one += 1 obj = s3.Bucket('paginated').Object("page_" + one + ".json") dlfile = s3.download_file(objp) n = {} m = json.loads(dlfile.read()) s = "adfhklnquvxyz" passlen = 12 book.uri = arg2 book.reddit_url = "http://oaflopean.pythonanywhere.com/?key=" + book.uri post = RedditPost(uri=book.uri, reddit_url=book.reddit_url, title=book.title, body=book.description, username=book.username) db.session.add(post) db.session.commit() db.session.add(book) db.session.commit() await ctx.send( book.title + " by " + book.author + " https://oaflopean.pythonanywhere.com/?key=" + book.uri + "added with uri key " + str(bookid))
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)