Fetch all posts by the two users which were created in the last year with the help of the fromdate
parameter. Note that user ids are semicolon separated.
Fetch the (public) reputation history of the two users, filter out the events regarding posts whose ids were not returned in the previous API call, and sum the reputation_change
fields of all the remaining events.
Here's a Python implementation, which uses StackAPI:
from stackapi import StackAPI
from datetime import datetime
from dateutil.relativedelta import relativedelta
year = (datetime.now() - relativedelta(years=1)).timestamp()
SITE = StackAPI('stackoverflow', key = '') # add your key
# fill user ids
user1 = 0
user2 = 0
# fetch all posts by user1 and user2 in the last year
posts = SITE.fetch(
'users/{ids}/posts',
ids=[user1, user2],
filter='!*Ju*n-1rscDl8QtK',
fromdate=round(year)
)
ids = [item['post_id'] for item in posts['items']]
# fetch the reputation history of user1 and user2
history = SITE.fetch('users/{ids}/reputation-history', ids=[user1,user2])
total1 = sum(item['reputation_change'] for item in history['items'] if item['post_id'] in ids and item['user_id'] == user1)
total2 = sum(item['reputation_change'] for item in history['items'] if item['post_id'] in ids and item['user_id'] == user2)
print(total1)
print(total2)
Make sure to register your application in order to obtain a key.