Advertisement
Guest User

quoteall

a guest
Jul 3rd, 2015
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | None | 0 0
  1. __author__ = 'rorke'
  2. #simple program which allows for optimal shitposting via
  3. #a print out of all post numbers itt
  4.  
  5. import urllib.request
  6. import re # normies out
  7.  
  8. def read_by_tokens(fileobj):
  9.     for line in fileobj:
  10.         for token in line.split():
  11.             yield token
  12.  
  13. filename = input("enter text file name: ")
  14. url = input("enter url:")
  15.  
  16. page = urllib.request.urlopen(url)
  17.  
  18. text_page = str(page.read(), encoding="utf-8")#convert bytes to string
  19.  
  20. text_file = open(filename, 'r+')
  21. text_file.write(text_page)
  22.  
  23. replies_list = []
  24.  
  25. with open(filename) as f:
  26.     for token in read_by_tokens(f):
  27.         if re.search("javascript:quote", token):
  28.             token = token[24:]# delete first 24 characters
  29.             token = token[:8]# deletes all bar first 8 characters
  30.             token = ">>" + token + "\n"
  31.             replies_list.append(token)
  32.             print(token)
  33.  
  34. text_file = open(filename, 'w')
  35.  
  36. replies = list(set(replies_list))#convert to set then back to list to remove duplicates
  37.  
  38.  
  39. for you in replies:
  40.     text_file.write(you)
  41. text_file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement