Skip to content

Commit 6a0d912

Browse files
author
Martin Krulis
committed
Tiny script for disabling gravatars which do not exist using recodex-cli.
1 parent 9f8735f commit 6a0d912

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

reset_gravatars/reset_gravatars.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import subprocess
2+
from io import StringIO
3+
import csv
4+
import requests
5+
6+
7+
def set_gravatar(id, gravatar):
8+
option = "--gravatar" if gravatar else "--no-gravatar"
9+
subprocess.run(["recodex", "users", "edit", id, option])
10+
11+
12+
def gravatar_exists(url):
13+
r = requests.get("{}&d=404".format(url))
14+
return r.status_code == 200
15+
16+
17+
cmd = ["recodex", "users", "search", "--csv", ""]
18+
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
19+
output, errors = proc.communicate()
20+
f = StringIO(output.decode("utf-8"))
21+
reader = csv.reader(f, delimiter=';')
22+
for row in reader:
23+
id = row[0]
24+
url = row[5]
25+
if url is not None and url != "":
26+
exists = gravatar_exists(url)
27+
print("{}\t{}\t{}".format(id, url, exists))
28+
if not exists:
29+
set_gravatar(id, False)

0 commit comments

Comments
 (0)