-
Notifications
You must be signed in to change notification settings - Fork 1
/
count_edit.py
43 lines (31 loc) · 900 Bytes
/
count_edit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""count_edit.py
"""
from io import StringIO
import requests
import pandas as pd
URL = "https://xtools.wmflabs.org/ec-yearcounts/zh.wikipedia.org/{}?format=csv"
users = pd.read_csv(
"data/wmc_memberships.csv",
header=0,
index_col=0,
dtype={
"Membership": bool
}
)
frames = []
for username in users.index:
print(username)
response = requests.get(URL.format(username))
try:
count = pd.read_csv(
StringIO(response.text),
header=0,
index_col=0
)
frames.append(count)
except pd.errors.ParserError:
print("unable to find {}".format(username))
counts = pd.concat(frames, keys=users.index, sort=True)
counts = counts.reindex(sorted(counts.columns), axis=1)
counts = counts.loc[:, ~counts.columns.str.contains('^Unnamed')]
counts.to_csv("data/edit_counts.csv", line_terminator="\r\n")