Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- from bs4 import BeautifulSoup
- import urllib
- import sys
- import re
- import time
- from yattag import Doc, indent
- import xml.etree.ElementTree
- import os
- import urllib.request as urllib2
- import random
- import string
- import adventure
- import io
- url='https://boards.4chan.org/qa/thread/527093'
- print(url, '\n')
- tmpfile = io.open('finalarchive.txt', 'w+')
- tmpfile.write('WELCOME TO COLOSSAL CAVES!! WOULD YOU LIKE INSTRUCTIONS?\nMade by Josh with the the library of github/brandon-rhodes')
- tmpfile.close()
- def gettoken(data):
- soup=BeautifulSoup(data, 'html.parser')
- out1=''
- for element in soup.find_all(name=True, value=True, type=True):
- if element['name'] == 'csrf_token_login':
- out1=element['value']
- continue
- return(out1)
- def clean(text):
- return re.sub(r'[^\x00-\x7F]',' ', text)
- def start():
- file = io.open('toUser.txt', 'w+')
- file.close()
- adventure.play()
- runFirstComponent()
- def runThirdComponent(array):
- print('Went to Third Component.')
- tmpfile = io.open('finalarchive.txt', 'r+')
- finarr = tmpfile.readlines()
- tmpfile.close()
- # print(array)
- final_array=[]
- for element in finarr:
- tmpvar=element
- if len(element) >= 1:
- final_array.append(element)
- for element in array:
- final_array.append(element)
- with io.open("finalarchive.txt", "w+") as myfile:
- for element in final_array:
- myfile.write('%s\n' % element)
- myfile.close
- nospace_final_array=[]
- x=0
- for element in final_array:
- if len(element) > 1:
- nospace_final_array.append(element.replace('\n',''))
- x+=1
- finstr='\n'.join(nospace_final_array)
- print(finstr)
- updatesession(finstr)
- def runSecondComponent(array):
- print('Went to Second Component.')
- def readfile():
- tmpfile = io.open('output.txt', 'r+')
- tmparr = tmpfile.readlines()
- tmpfile.close()
- return tmparr
- outarr=[]
- tmparr=[]
- for command in array:
- def error(command):
- tmparr.append('>' + command)
- tmparr.append('INVALID INPUT')
- try:
- if (command not in ['quit', 'quit()', 'suspend', 'pause', 'save']):
- if (','not in command and '.' not in command and '/' not in command and '\\' not in command):
- pattern = re.compile('[^A-Z,a-z,(,)]')
- if pattern.findall(command):
- error(command)
- else:
- output='print(' + command + ')'
- exec(output)
- tmparr.append('>' + command)
- for line in readfile():
- tmparr.append(line)
- else:
- error(command)
- else:
- error(command)
- except Exception as e:
- error(command)
- for element in tmparr:
- if element != '\n':
- outarr.append(element.replace('\n',''))
- with io.open("toUser.txt", "a") as myfile:
- for element in outarr:
- myfile.write('%s\n' % element)
- myfile.close
- return outarr
- def runFirstComponent():
- print('Made it to First component')
- while(True):
- headers='Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36'
- try:
- req = urllib2.Request(url, headers={ 'User-Agent': headers })
- html = urllib2.urlopen(req, timeout=20).read()
- except Exception as e:
- print("Error: ", e)
- time.sleep(10)
- runFirstComponent()
- html=clean((str)(html))
- soup = soup = BeautifulSoup(html, "html.parser")
- title=soup.html.head.title.text
- doc, tag, text = Doc().tagtext()
- with tag ('thread'):
- for posts in soup.findAll(('div'),{"class":"postContainer"}):
- for reply in posts.findAll(('div'),{"class":"post reply"}):
- string=reply.find(('blockquote'),{"class":"postMessage"})
- string=(str)(string)
- string=re.sub('<[^>]+>', '\n',string)
- string=string.replace('>', '>')
- array=string.splitlines()
- array=[x for x in array if x]
- array=list(map(str, array))
- with tag('post', name=posts.find(('span'),{"class":"postNum desktop"}).text[3:]):
- i=0
- for lines in array:
- with tag('line'):
- text(array[i].replace('$gt;', '>'))
- i+=1
- #prettying document up
- result = indent(
- doc.getvalue(),
- indentation = ' '*4,
- newline = '\r\n'
- )
- result=result.replace('>','>')
- # write xml to file
- file = io.open('output.xml', 'w+')
- file.write(result)
- file.close()
- e = xml.etree.ElementTree.parse('output.xml').getroot()
- active=[]
- #returns active posts in an array
- for posts in e.findall('post'):
- active.append((int)(posts.get('name')))
- newposts=active[:]
- file=io.open('saved.txt', 'r')
- inactive=file.readlines()
- file.close()
- inactive=list(map(int, inactive))
- s1=set(inactive)
- s2=set(active)
- #remove posts found in saved.csv array
- for x in s1:
- for y in s2:
- if x == y:
- active.remove(x)
- active=list(map(str, active))
- toProgram=[]
- for post in e.findall('post'):
- for element in active:
- if (post.get('name')==element):
- i=0
- for line in post.findall('line'):
- try:
- tmp=line.text
- if len(tmp) < 30 and tmp[0] == ';':
- tmp=tmp[1:]
- toProgram.append(tmp)
- i+=1
- if (i == 8):
- break
- except:
- i+=0
- # writing new values to file
- file=io.open('saved.txt', 'w+')
- for posts in newposts:
- file.write((str)(posts) + '\n')
- file.close()
- outarr = runSecondComponent(toProgram)
- runThirdComponent(outarr)
- sleep_time=random.randint(10,13)
- print('Sleeping for', sleep_time, ' seconds')
- time.sleep(sleep_time)
- def updatesession(str):
- with requests.Session() as c:
- headers='Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'
- url='http://www.pastebin.com/login'
- out = c.get(url, headers={'User-Agent': headers})
- tmp=out.content
- # tmp=tmp.replace('\n','')
- # information to include in the first POST message, for logging in
- csrf_token_login=gettoken(tmp)
- submit_hidden='submit_hidden'
- user_name='icarus42'
- user_password='f.u.'
- submit='Login'
- print(csrf_token_login)
- # post information. You send your POST information, then after that GET the page
- login_data=dict(csrf_token_login=csrf_token_login, submit_hidden=submit_hidden, user_name=user_name, user_password=user_password, submit=submit)
- try:
- c.post(url, data=login_data, headers={'Referer':url, 'User-Agent':headers})
- logged_in_url='http://www.pastebin.com/u/icarus42'
- page=c.get(logged_in_url,headers={'User-Agent':headers})
- except Exception as e:
- print('[1] Exception', e)
- paste_url='http://pastebin.com/edit/3t0WiT2q'
- out=c.get(paste_url, headers={'Referer':logged_in_url, 'User-Agent':headers})
- me=out.content
- submit_hidden='submit_hidden'
- item_key='3t0WiT2q'
- csrf_token_3t0WiT2q=gettoken(me)
- paste_code=str
- paste_format='1'
- paste_expire_date='DNC'
- paste_private='0'
- paste_name='Colossal Caves'
- submit='Save+Changes'
- submitted_data=dict(submit_hidden=submit_hidden, item_key=item_key,
- csrf_token_3t0WiT2q=csrf_token_3t0WiT2q, paste_code=paste_code,
- paste_format=paste_format, paste_expire_date=paste_expire_date,
- paste_private=paste_private, paste_name=paste_name, submit=submit)
- try:
- c.post(paste_url, data=submitted_data, headers={'Referer':paste_url, 'User-Agent':headers})
- finished_url='http://pastebin.com/3t0WiT2q'
- page=c.get(finished_url, headers={'Referer':paste_url, 'User-Agent':headers})
- except Exception as e:
- print('[2] Exception', e)
- print('Finished Downloading')
- def start():
- adventure.play()
- runFirstComponent()
- start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement