Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import urllib.request
- import urllib.parse
- import time
- import json
- # YOU CAN EDIT THE TEXT HERE. USE \n TO MAKE A NEW LINE.
- text="spez can gargle my nuts"
- headers={
- # 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
- "Cookie":"PUT YOUR COOKIE VALUE HERE",
- "User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/113.0",
- "Referer":"https://old.reddit.com/",
- "Origin":"https://old.reddit.com",
- }
- req=urllib.request.urlopen(urllib.request.Request("https://old.reddit.com/", headers=headers))
- modhash=json.loads(req.read().decode('utf-8').split('<script type="text/javascript" id="config">r.setup(')[1].split(')</script>')[0])['modhash']
- req.close()
- comments_done=set()
- try:
- with open("comments_done.txt","r") as f:
- for line in f:
- comments_done.add(line.strip())
- except FileNotFoundError:
- pass
- text = urllib.parse.quote(text)
- donefile=open("comments_done.txt","a")
- with open("comment_headers.csv","r") as f:
- f.readline() # skip header
- for line in f:
- parts = line.split(",")
- cid = parts[0]
- if cid in comments_done: continue
- subreddit = parts[4]
- try:
- req = urllib.request.urlopen(urllib.request.Request("https://old.reddit.com/api/editusertext", data=
- ("thing_id=t1_"+cid+"&text="+text+"&id=%23form-t1_"+cid+"&r="+subreddit+"&uh="+modhash+"&renderstyle=html")
- .encode('utf-8')
- , headers=headers))
- except urllib.error.HTTPError as e:
- print(cid,e.code)
- if e.code == 403:
- # e.g. subreddit is now private
- time.sleep(5)
- continue
- else:
- raise
- print(cid,req.getcode())
- data=req.read().decode("utf-8")
- if req.getcode() != 200 or ".error" in data:
- print(req.getheaders())
- print(data)
- raise Exception("failed")
- req.close()
- donefile.write(cid+"\n")
- donefile.flush()
- time.sleep(5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement