Advertisement
Guest User

Untitled

a guest
Jun 10th, 2023
652
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. import urllib.request
  2. import urllib.parse
  3. import time
  4. import json
  5.  
  6. # YOU CAN EDIT THE TEXT HERE. USE \n TO MAKE A NEW LINE.
  7. text="spez can gargle my nuts"
  8. headers={
  9. # PUT YOUR COOKIE VALUE HERE ON THE NEXT LINE. TO GET THIS VALUE YOU GO TO HTTP://OLD.REDDIT.COM AND LOOK AT THE REQUEST HEADERS IN THE NETWORK INSPECTOR. MAKE SURE TO RIGHT CLICK AND COPY VALUE, NOT CTRL-C BECAUSE CTRL-C WILL SHORTEN IT
  10. "Cookie":"PUT YOUR COOKIE VALUE HERE",
  11. "User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/113.0",
  12. "Referer":"https://old.reddit.com/",
  13. "Origin":"https://old.reddit.com",
  14. }
  15.  
  16. req=urllib.request.urlopen(urllib.request.Request("https://old.reddit.com/", headers=headers))
  17. modhash=json.loads(req.read().decode('utf-8').split('<script type="text/javascript" id="config">r.setup(')[1].split(')</script>')[0])['modhash']
  18. req.close()
  19.  
  20. comments_done=set()
  21. try:
  22. with open("comments_done.txt","r") as f:
  23. for line in f:
  24. comments_done.add(line.strip())
  25. except FileNotFoundError:
  26. pass
  27.  
  28. text = urllib.parse.quote(text)
  29.  
  30. donefile=open("comments_done.txt","a")
  31. with open("comment_headers.csv","r") as f:
  32. f.readline() # skip header
  33. for line in f:
  34. parts = line.split(",")
  35. cid = parts[0]
  36. if cid in comments_done: continue
  37. subreddit = parts[4]
  38. try:
  39. req = urllib.request.urlopen(urllib.request.Request("https://old.reddit.com/api/editusertext", data=
  40. ("thing_id=t1_"+cid+"&text="+text+"&id=%23form-t1_"+cid+"&r="+subreddit+"&uh="+modhash+"&renderstyle=html")
  41. .encode('utf-8')
  42. , headers=headers))
  43. except urllib.error.HTTPError as e:
  44. print(cid,e.code)
  45. if e.code == 403:
  46. # e.g. subreddit is now private
  47. time.sleep(5)
  48. continue
  49. else:
  50. raise
  51. print(cid,req.getcode())
  52. data=req.read().decode("utf-8")
  53. if req.getcode() != 200 or ".error" in data:
  54. print(req.getheaders())
  55. print(data)
  56. raise Exception("failed")
  57. req.close()
  58. donefile.write(cid+"\n")
  59. donefile.flush()
  60. time.sleep(5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement