Just added two little scripts to the steempersist repo this might be of interest to those of you who are bothered by comment bots. These scripts are just a first step, I plan to do more towards the same goal, but I thought it worth it to disclose the function of these two scripts early so others may benefit.
The basis for the script is the daily @steemcleaners posts. The first of the two scripts will fetch the latest few reports from @steemcleaners, scrape out the Comment Spam entries and write out the accounts involved to a json file named steemcleaners.json.
#!/usr/bin/python3
import steem
import json
spambots = set()
s=steem.steemd.Steemd()
entries = s.get_blog_entries("steemcleaners",-1,4)
for entry in entries:
content = s.get_content("steemcleaners",entry["permlink"])["body"]
parts = content.split("# Report\n")
if len(parts) > 1:
body = parts[1]
lines = body.split("\n")
for line in lines:
parts = line.split("|")
if len(parts) >5:
link = parts[1]
abuse_type = parts[2]
if "Comment Spam" in abuse_type:
p2 = link.split("@")
if len(p2) > 1:
p3 = p2[1].split("/")
if len(p3) > 1:
spambots.add(p3[0])
sb_obj = dict()
sb_obj["spambots"] = []
for bot in sorted(spambots):
sb_obj["spambots"].append(bot)
with open("steemcleaners.json", "w") as pjson:
pjson.write(json.dumps(sb_obj))
print("Done")
The script is real straightforward. I'll need to make it a bit more eobust though in case @steemcleaners ever chooses to change its reporting formatting.
A second script takes the JSON file from the first script and uses it to mute all listed spam bot accounts. Note that this script does an import mycredentials. It expects to find your account name and posting key in that file as it will need those to mute the bot accounts.
#!/usr/bin/python3
import steem
import json
import mycredentials
import sys
muted = set()
s = steem.Steem([],keys=mycredentials.keys)
try:
with open("muted.json") as pjson:
obj = json.loads(pjson.read())
for account in obj["spambots"]:
muted.add(account)
print("Already muted:",len(muted),"spam bots")
except:
print("Can't process muted.json")
count = 0
try:
with open("steemcleaners.json") as pjson:
obj = json.loads(pjson.read())
for account in obj["spambots"]:
if not account in muted:
print("muting",account)
ojson=["follow",{"follower" : mycredentials.account, "following" : account, "what" : ["ignore"]}]
s.commit.custom_json("follow",ojson,required_posting_auths=[mycredentials.account])
muted.add(account)
count = count + 1
if count > 0:
print("Muted",count,"spam bots")
else:
print("No new spam bots to mute.")
except:
print("Something went wrong!")
if count > 0:
print("Saving muted.")
obj = dict()
obj["spambots"] = []
for account in muted:
obj["spambots"].append(account)
js = json.dumps(obj)
print(js)
with open("muted.json", "w") as pjson:
pjson.write(js)
print("Done")
The second script also keeps its own JSON file for keeping track of what accounts it already muted.
Currently, the script doesn't forgive or forget. Get flagged by @steemcleaners for comment spam and get muted forever by anyone using these two here scripts.
If you like these scripts, consider running them on your account as cron-jobs.
As stated, these scripts are meant to become part of a bigger whole, but as they are already usable by themselves, I thought it worth sharing them at this point in time.
Great job!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit