from stackapi import StackAPI, StackAPIError
import pandas as pd
import plotly.express as px
import urllib
access_token = urllib.parse.parse_qs(urllib.parse.urlparse(auth_url).fragment)[
"access_token"
][0]
SITE = StackAPI("stackoverflow", key=key, access_token=access_token)
SITE.max_pages = 100
def batch_get(site, so_api, ids, api_kwargs={}):
n = 100
return pd.concat(
[
pd.json_normalize(
site.fetch(so_api, ids=ids[i : i + n], **api_kwargs)["items"]
)
for i in range(0, len(ids), n)
]
)
# get all my answers
user_ids = [9441404]
dates = (
pd.date_range("1-jan-2017", "1-jun-2022", freq="MS").astype(int) // 10**9
).tolist()
df_ans = batch_get(
SITE,
"users/{ids}/answers",
user_ids,
api_kwargs={"fromdata": dates[0], "todate": dates[-1]},
)
# get questions corresponding to answers
df_q = batch_get(SITE, "questions/{ids}", ids=df_ans["question_id"].tolist())
# simple analysis of accepted answers by reputation bucket
df_temp = (
df_q.groupby([pd.qcut(df_q["owner.reputation"], q=10), "is_answered"])
.size()
.reset_index()
.rename(columns={0: "n"})
.assign(rep_bin=lambda d: d["owner.reputation"].astype(str))
)
# plot analysis
px.bar(
df_temp,
x="rep_bin",
y="n",
color="is_answered",
color_discrete_sequence=["red", "green"],
barmode="group",
)
from stackapi import StackAPI, StackAPIError
import pandas as pd
import plotly.express as px
import urllib
access_token = urllib.parse.parse_qs(urllib.parse.urlparse(auth_url).fragment)[
"access_token"
][0]
SITE = StackAPI("stackoverflow", key=key, access_token=access_token)
SITE.max_pages = 100
def batch_get(site, so_api, ids, api_kwargs={}):
n = 100
return pd.concat(
[
pd.json_normalize(
site.fetch(so_api, ids=ids[i : i + n], **api_kwargs)["items"]
)
for i in range(0, len(ids), n)
]
)
# get all my answers
user_ids = [9441404]
dates = (
pd.date_range("1-jan-2017", "1-jun-2022", freq="MS").astype(int) // 10**9
).tolist()
df_ans = batch_get(
SITE,
"users/{ids}/answers",
user_ids,
api_kwargs={"fromdata": dates[0], "todate": dates[-1]},
)
# get questions corresponding to answers
df_q = batch_get(SITE, "questions/{ids}", ids=df_ans["question_id"].tolist())
# simple analysis of accepted answers by reputation bucket
df_temp = (
df_q.groupby([pd.qcut(df_q["owner.reputation"], q=10), "is_answered"])
.size()
.reset_index()
.rename(columns={0: "n"})
.assign(rep_bin=lambda d: d["owner.reputation"].astype(str))
)
# plot analysis
px.bar(
df_temp,
x="rep_bin",
y="n",
color="is_answered",
color_discrete_sequence=["red", "green"],
barmode="group",
)