Advertisement
Guest User

Untitled

a guest
Nov 4th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.94 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # coding=utf-8
  3. """
  4. Muokkasin psykoosibotti vähän ja tää jakaa nyt random langoille tää ääniä satunnaisessa.
  5. Sit se postaa n.minuutin välein hiekkalaatikkoon uuden langan nii tienaa vähän aktiivisuuspisteitä.
  6. tarvii /img/ kansion juureen ja sinne random kuvia numerojärjestyksessä, että toi osaa postata niitä. Sit pitää createThread functiossa muistaa laittaa randintti oikeisiin lukemiin,
  7. että ohjelma tietää monta kuvaa kansiossa on. (En oo jaksanu tehdä tästä hienompaa, vaikka ei hankala ois :D)
  8. """
  9.  
  10. import dryscrape, re
  11. from bs4 import BeautifulSoup
  12. import getpass
  13. import random
  14. from random import randint
  15. import sys
  16. import os
  17. import datetime
  18. import time
  19. import threading
  20.  
  21. reload(sys)
  22. sys.setdefaultencoding('utf-8')
  23. url="https://ylilauta.org/satunnainen/"
  24. from requests import get
  25. times = raw_input("Monta kertaa käydään lankoja läpi: ")
  26. username = raw_input("Käyttäjätunnus:")
  27. passw = getpass.getpass('Salasana:' )
  28. session = dryscrape.Session()
  29. session.set_error_tolerant(True)
  30.  
  31. thisGiven = 0
  32. usedThreads =[]
  33. threadsMade = 0
  34.  
  35. timesDone = 0
  36. global makeNewThread
  37. makeNewThread = True
  38.  
  39. def update():
  40.     threading.Timer(1.0, update).start()
  41.     curTime = str(datetime.datetime.time(datetime.datetime.now()))[6:-7]
  42.     #print curTime
  43.     global makeNewThread
  44.    
  45.     if timesDone >= times:
  46.         compose = session.at_xpath('//*[contains(text(), "Kirjaudu ulos")]')
  47.         compose.click()
  48.         sys.exit(0)
  49.     if curTime == "50":
  50.         print "make new thread enabled"
  51.         makeNewThread = True
  52.        
  53. def createThread(threadNumbers):
  54.     try:
  55.         session.visit("https://ylilauta.org/hiekkalaatikko")
  56.         fil = session.at_xpath('//*[@name="file"]')
  57.         randFile = os.path.dirname(os.path.realpath(__file__))+"/img/"+str(randint(0,1064))+".jpg"
  58.         if os.path.isfile(randFile):
  59.             print randFile
  60.             fil.set(randFile)
  61.         else:
  62.             randFile = randFile[:-3]+"png"
  63.             print randFile
  64.             fil.set(randFile)
  65.         teksti = session.at_xpath('//*[@name="msg"]')
  66.         randomTekstit = ["testailua juu","testailen vielki moro","testii","testi","tetsaan sori","tesst","teest","testisisis","testiä","anteeksi testi"]
  67.         teksti.set(random.choice(randomTekstit))
  68.         token = session.at_xpath('//*[@name="submit"]')
  69.         token.click()
  70.         print "thread done"
  71.         threadNumbers=threadNumbers+1
  72.         return threadNumbers
  73.     except Exception, e:
  74.         print "error in thread making: "+str(e)
  75.    
  76.  
  77.  
  78. #log in to ylis xD
  79. try:
  80.     session.visit(url)
  81.  
  82.     name = session.at_xpath('//*[@name="username"]')
  83.     name.set(username)
  84.     password = session.at_xpath('//*[@name="password"]')
  85.     password.set(passw)
  86.     name.form().submit()
  87.     response = session.body()
  88.     soup = BeautifulSoup(response)
  89.     print soup.findAll(text=re.compile('Kirjautuneena'))
  90.     update()
  91. except:
  92.     print 'Error in page load when loggin in'
  93.        
  94. #-------------------------------------------------------
  95. for x in range(0, int(times)):
  96.     try:   
  97.         #50/50 to go to frontpage or some other
  98.         if randint(0,10) > 5:
  99.             session.visit("https://ylilauta.org/satunnainen-"+str(randint(2,3)))
  100.         else:
  101.             session.visit(url)
  102.         response = session.body()
  103.         soup = BeautifulSoup(response)
  104.        
  105.         # check for all threads
  106.         threads = soup.findAll("div", {"class": "thread"})
  107.        
  108.         #get random post
  109.         randomid = randint(0, len(threads)-1)
  110.         thread = threads[randomid]
  111.         post = thread.find("div", {"class":"op_post"})           
  112.        
  113.         author =  post.find("a", {"class":"postnumber"}).get_text()
  114.         authorModified =  re.sub("\D", "", author)
  115.        
  116.         if authorModified in usedThreads:
  117.             raise ValueError("Tää :D has been made in this htrööd :D")
  118.            
  119.         #OPEN THE POST
  120.         #convert the link to right format
  121.         linkToPost = post.find("a", {"class":"postsubject"})           
  122.         linkToPost = str(linkToPost)[str(linkToPost).find('href'):]
  123.         splitattu = linkToPost.split()
  124.         linkToPost = splitattu[0][6:]
  125.        
  126.         if "span" in linkToPost:
  127.             linkToPost = linkToPost[:-7]
  128.         else:
  129.             linkToPost = linkToPost[:-2]
  130.  
  131.         #visit the post
  132.         session.visit("https://ylilauta.org"+linkToPost)
  133.         response = session.body()
  134.         soup = BeautifulSoup(response)
  135.        
  136.         print "new thread: "+authorModified
  137.         buttons = session.xpath('//a[contains(@title, "Tää :D")]')
  138.         print "Tää :Ds to give: "+str(len(buttons))
  139.         print "going to take about: "+str(float(len(buttons)*0.6))+"seconds"
  140.         for thisButton in buttons:
  141.             thisButton.click();
  142.             thisGiven=thisGiven+1
  143.             waitTime = random.uniform(0.5, 1)
  144.             time.sleep(waitTime)
  145.         print "tää :D given: "+str(thisGiven)+" times.."
  146.         usedThreads.append(authorModified)
  147.         timesDone=timesDone+1
  148.         pisteet = soup.findAll(text=re.compile('Aktiivisuuspisteet'))
  149.         print pisteet[0]
  150.         if makeNewThread == True:
  151.             t = createThread(threadsMade)
  152.             threadsMade = t
  153.             makeNewThread = False
  154.             print "threads made: "+str(threadsMade)
  155.         #print str(makeNewThread)
  156.         time.sleep(2)
  157.        
  158.            
  159.     except Exception, e:
  160.         print "error : "+str(e)
  161.         time.sleep(15)
  162.         session.visit(url)
  163.         response = session.body()
  164.         soup = BeautifulSoup(response)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement