Skip to content

Commit

Permalink
Tweak spam algorithm to flag more bad accounts based on keywords in u…
Browse files Browse the repository at this point in the history
…sernames
  • Loading branch information
rneiss committed Mar 23, 2022
1 parent dba0ee6 commit c2cb263
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions sefaria/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,11 +867,14 @@ def profile_spam_dashboard(request):

regex = r'.*(?!href=[\'"](\/|http(s)?:\/\/(www\.)?sefaria).+[\'"])(href).*'

spam_keywords_regex = r'(?i).*support.*|.*coin.*|.*helpline.*'

users_to_check = db.profiles.find(
{'$or': [
{'website': {"$ne": ""}, 'bio': {"$ne": ""}, "id": {"$gt": earliest_new_user_id},
"reviewed": {"$ne": True}},
{'bio': {"$regex": regex}, "id": {"$gt": earliest_new_user_id}, "reviewed": {"$ne": True}}
{'bio': {"$regex": regex}, "id": {"$gt": earliest_new_user_id}, "reviewed": {"$ne": True}},
{'slug': {"$regex": spam_keywords_regex}, "id": {"$gt": earliest_new_user_id}, "reviewed": {"$ne": True}}
]
})

Expand All @@ -882,7 +885,9 @@ def profile_spam_dashboard(request):
for user in users_to_check:
history_count = db.user_history.find({'uid': user['id']}).count()
if history_count < 10:
profiles_list.append({"id": user["id"], "slug": user["slug"], "bio": strip_tags(user["bio"][0:250]), "website": user["website"][0:50]})
profile = model.user_profile.UserProfile(id=user["id"])

profiles_list.append({"name": f"{profile.first_name} {profile.last_name}", "email": profile.email, "id": user["id"], "slug": user["slug"], "bio": strip_tags(user["bio"][0:250]), "website": user["website"][0:50]})

return render_template(request, 'spam_dashboard.html', None, {
"title": "Potential Spam Profiles since %s" % date.strftime("%Y-%m-%d"),
Expand Down
3 changes: 2 additions & 1 deletion templates/spam_dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ <h1>{{ title }}</h1>
<tbody>
{% for profile in profiles %}
<tr>
<td><a href='/profile/{{ profile.slug }}' target='_blank'>{{ profile.slug }}</a></td>
<td><a href='/profile/{{ profile.slug }}' target='_blank'>{{ profile.name }}</a></td>
<td>{{ profile.email }}</td>
<td>{{ profile.bio }}</td>
<td>{{ profile.website }}</td>
<td><input type='checkbox' name='spam_profiles[]' value='{{ profile.id }}' form='spam_form'/></td>
Expand Down

0 comments on commit c2cb263

Please sign in to comment.