forked from FlominatorTM/WikiTree
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectMembers.py
More file actions
349 lines (284 loc) · 12.1 KB
/
Copy pathProjectMembers.py
File metadata and controls
349 lines (284 loc) · 12.1 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
import requests
import dateutil.parser
import argparse
from datetime import datetime
from dateutil.relativedelta import relativedelta
badge = "germany"
words = ["German", "Deutsch", "Heiliges", "Holy Roman", "Prussia", "Preußen", "Alsace", "Elsass"]
def get_args():
parser = argparse.ArgumentParser(description='Creates a report of one project')
parser.add_argument('--contribs', action='store_true', help='Checks edited profiles for keyword')
parser.add_argument('--last', action='store_true', help='Gets last edit')
parser.add_argument('--any', action='store_true', help='Checks for edits in last months')
parser.add_argument('--checkin', action='store_true', help='Checks is user received check-in message')
parser.add_argument('--reply', action='store_true', help='Checks is user replied to check-in message')
parser.add_argument('--unbadge', action='store_true', help='Adds link to remove badge')
parser.add_argument('--join', action='store_true', help='Adds link to remove badge')
parser.add_argument('--users', help='link to text file with user names')
return parser.parse_args()
def get_members_file(filename):
members = []
with open(filename, encoding="utf-8") as f:
while True:
line = f.readline().strip()
if not line:
break
theUser = {}
theUser["id"] = line;
theUser["name"] = " ";
members.append(theUser)
return members
def get_member_users_project(project):
link = 'https://www.wikitree.com/index.php?title=Special:Badges&b=' + project + '&limit=5000'
f = requests.get(link)
memberPageContent = f.text
members = []
# <span class="large"><a href="/wiki/Straub-620" target="_blank" title="">Florian Straub</a></span>
isFirstRound = True
for member in memberPageContent.split('class="large"><a href="/wiki/'):
if isFirstRound == True:
isFirstRound = False
continue
#print ("-----------------")
# print(member)
theUser = {}
betweenIdAndName = '" target="_blank">'
indexIdEnds = member.find(betweenIdAndName)
indexNameBeginns = indexIdEnds + len(betweenIdAndName)
afterName = "</a></span>"
indexNameEnds = member.find(afterName);
if indexNameBeginns > 0:
theUser["id"] = member[0:indexIdEnds];
theUser["name"] = member[indexNameBeginns:indexNameEnds];
members.append(theUser)
# print(theUser)
# if len(members) > 2:
# break
print(str(len(members)) + " members found", flush=True)
return members
def check_edit_history(theUser):
global args
link = "https://www.wikitree.com/index.php?title=Special:Contributions&l=500&who=" + theUser["id"];
f = requests.get(link)
contribPage = f.text
beginnOfHistory = "<span class='HISTORY-DATE'>"
contribPageParts = contribPage.split(beginnOfHistory)
now = datetime.now()
six_months_ago = now + relativedelta(months=-6)
any_edit = False
dayNum = 0
for oneDay in contribPageParts[1:] :
# print(oneDay)
"<span class='HISTORY-ITEM'>"
dayNum+=1
indexDateEnd = oneDay.find('</span>');
# print (oneDay)
# print ( contribPage[indexDate:indexDateEnd] )
editDateFormatted = oneDay[0:indexDateEnd]
editDate = dateutil.parser.parse(editDateFormatted)
# print (editDateFormatted)
if dayNum is 1:
theUser["lastEditFormatted"] = editDateFormatted
theUser["lastEdit"] = editDate
theUser["editedProject"] = False
theUser["anyEdit"] = False
if args.last is False and args.contribs is False:
break
print (editDateFormatted)
if editDate > six_months_ago:
theUser["anyEdit"] = True
if args.contribs:
relevant_edit = did_user_perform_relevant_edit(oneDay)
if relevant_edit:
theUser["editedProject"] = True
break
any_edit = True
else:
print("edit too old, done")
break
def did_user_perform_relevant_edit(oneDay):
global words
editsPerDay = oneDay.split("<span class='HISTORY-ITEM'>")
for oneEdit in editsPerDay[1:]:
linksInEdit = oneEdit.split("<a href=\"")
#first part without link
#third part usually contains the topic of the edit
if len(linksInEdit) > 3:
# print(linksInEdit)
endOfLink = linksInEdit[3].find("\"")
subjectLink = linksInEdit[3][0:endOfLink]
if "http" in subjectLink and not "Special" in subjectLink:
print (subjectLink)
if does_profile_contain(subjectLink, words):
print("relevant edit found")
return True
else:
print("no project relevant edit")
print("-------------------")
return False
def does_profile_contain(link, words):
if link in profiles_global:
return profiles_global[link]
else:
f = requests.get(link)
profile_text = f.text
profiles_global[link] = False
for word in words:
if word in profile_text:
profiles_global[link] = True
return True
return False
def get_checkin_requested(theUser, checkInToken):
link = 'https://www.wikitree.com/wiki/' + theUser["id"]
f = requests.get(link)
userPage = f.text
indexCheckInToken = userPage.find(checkInToken)
if args.join:
midToken = 'data-mid="'
indexMidStart = userPage.index(midToken) + len(midToken)
indexMidEnd = userPage.index('"', indexMidStart)
get_date_joined(theUser, userPage[indexMidStart:indexMidEnd] )
if args.checkin is False and args.reply is False:
return
# print(str(indexCheckInToken))
theUser["check-in-requested"] = indexCheckInToken > -1
theUser["check-in-replied"] = False
theUser["check-in-reply-date"] = datetime(2122, 12, 19, 0, 0)
if theUser["check-in-requested"]:
indexOfReplyButtons = userPage.index("comment-info small", indexCheckInToken)
indexOfNextDiv = userPage.index("<div", indexOfReplyButtons)
indexEndOfThatDiv = userPage.index(">", indexOfNextDiv)
#<div id="comment_7317201" class="comment comment-depth-1 comment-reply " data-comment-id="7317201" data-reply-to="7316984" data-depth="1">
if "comment-reply" in userPage[indexOfNextDiv:indexEndOfThatDiv]:
theUser["check-in-replied"] = True
replyToken = '<div class="comment-body">'
indexOfActualReply = userPage.index(replyToken, indexEndOfThatDiv)
indexOfActualReply += len(replyToken)
indexEndOfActualReply = userPage.index("</div>", indexOfActualReply)
theUser["check-in-reply"] = userPage[indexOfActualReply:indexEndOfActualReply].strip()
theUser["check-in-negative"] = is_reply_negative(theUser["check-in-reply"])
#<time class="timeago" datetime="2023-05-05T20:43:44Z" title="May 05, 2023">10 hours ago</time>
replyTimeToken = 'datetime="'
indexOfReplyTimeStart = userPage.index(replyTimeToken, indexOfActualReply)
indexOfReplyTimeStart += len(replyTimeToken)
indexOfReplyTimeEnd = indexOfReplyTimeStart + len("2023-05-05T20:43:44")
replyTime = userPage[indexOfReplyTimeStart:indexOfReplyTimeEnd]
theUser["check-in-reply-date"] = dateutil.parser.parse(replyTime)
def get_date_joined(theUser, mId):
global badge
link = 'https://www.wikitree.com/index.php?title=Special:Badges&u=' + mId
f = requests.get(link)
badgePage = f.text
# <li id="list_item_180">
# <a href="/index.php?title=Special:Badges&b=germany"><img src="/images/badge/germany.gif.pagespeed.ce.9pUpJX44h-.gif" alt="Germany Project Member" width="125" height="70" border="0"></a> <br>
# <span class="large">Germany Project Member</span><br>
# Active participant in the <a href="http://www.wikitree.com/wiki/Project:Germany">Germany/German Roots Project</a>.<br>
# 29 Oct 2019
# <br>
# Awarded by <a href="/wiki/Haese-11" title="">Kylie Haese</a>
indexLinkToBadge = badgePage.index("b=germany")
indexBelowDate = badgePage.index("Awarded by ", indexLinkToBadge)
indexBrAfterDate = badgePage.rindex("<", indexLinkToBadge, indexBelowDate)
indexBrBeforeDate = badgePage.rindex('>', indexLinkToBadge, indexBrAfterDate) + len('>')
theUser["date-joined-formatted"] = badgePage[indexBrBeforeDate:indexBrAfterDate]
theUser["date-joined"] = dateutil.parser.parse(badgePage[indexBrBeforeDate:indexBrAfterDate])
def is_reply_negative(reply):
replyLower = reply.lower()
return "no " in replyLower or "don't" in replyLower or "drop out" in replyLower
def write_report(members):
global args
f = open("members.htm", "w")
f.write('<html><head></head><body><table border="1">')
f.write("<tr>")
f.write("<th>ID</th>")
f.write("<th>Name</th>")
if args.join:
f.write("<th>Date joined</th>")
if args.last:
f.write("<th>Last edit</th>")
if args.checkin:
f.write("<th>Check in?</th>")
if args.reply:
f.write("<th>Reply check-in</th>")
if args.any:
f.write("<th>Any edit?</th>")
if args.contribs:
f.write("<th>Project edit?</th>")
if args.unbadge:
f.write("<th>Badge</th>")
f.write("</tr>")
if args.reply:
sortkey='check-in-reply-date'
else:
sortkey='lastEdit'
for member in sorted(members, key=lambda d: d[sortkey]):
f.write("<tr>")
f.write("<td>")
f.write('<a href="https://www.wikitree.com/wiki/' + member["id"] + '">' + member["id"] + '</a>')
f.write("</td>")
f.write("<td>")
f.write(member["name"])
f.write("</td>")
if args.join:
f.write("<td>")
f.write( member["date-joined-formatted"])
f.write("</td>")
if args.last:
f.write("<td>")
f.write( member["lastEditFormatted"])
f.write("</td>")
if args.checkin:
f.write("<td>")
if member["check-in-requested"]:
f.write("yes")
else:
f.write("no")
f.write("</td>")
if args.reply:
f.write("<td>")
if member["check-in-replied"]:
if member["check-in-negative"]:
f.write("<b>")
f.write(member["check-in-reply"])
if member["check-in-negative"]:
f.write("</b>")
else:
f.write(" ");
f.write("</td>")
if args.any:
f.write("<td>")
if member["anyEdit"]:
f.write("yes")
else:
f.write("no")
f.write("</td>")
if args.contribs:
f.write("<td>")
if member["editedProject"]:
f.write("yes")
else:
f.write("no")
f.write("</td>")
if args.unbadge:
f.write("<td>")
f.write('<a href="https://www.wikitree.com/index.php?title=Special:AwardBadge&badge_id=180&users='+ member["id"]+'&action=remove">remove now</a>')
f.write("</td>")
f.write("</tr>")
f.write("</table></body>")
f.close()
args = get_args()
profiles_global = {}
members = []
if not args.users:
members = get_member_users_project(badge)
else:
members= get_members_file(args.users)
#pgm
numMembers = str(len(members))
done = 0
for member in members:
check_edit_history(member)
get_checkin_requested(member, "annual check-in time 2023. If you still ")
done +=1
print(str(done) + "/" + numMembers + " " + str(member) + "\n", flush=True)
write_report(members)