Last active
December 21, 2015 11:28
-
-
Save cben/f23e94fe63a0a3d22437 to your computer and use it in GitHub Desktop.
Find all downvoted posts from my StackOverflow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/fish | |
| # TODO: this is only SO — how to fetch from all StackExchange sites? | |
| set MY_USER_ID 239657 | |
| # Don't remember exact content of filter but it includes .has_more and more info about votes. | |
| # See: curl --compressed "https://api.stackexchange.com/2.2/filters/$FILTER" | |
| set FILTER '!b0OfN6h15EULDG' | |
| rm downvotes-* | |
| set page 1 | |
| while true | |
| curl --compressed "https://api.stackexchange.com/2.2/users/$MY_USER_ID/posts?order=desc&sort=activity&site=stackoverflow&filter=$FILTER&page=$page" > downvotes-$page | |
| if not jq '.has_more' downvotes-$page | grep true | |
| break | |
| end | |
| set page (math $page + 1) | |
| end | |
| echo == Downvoted posts == | |
| cat downvotes-* | jq '.items | map(select(.down_vote_count>0))' | |
| echo == Downvotes: == | |
| cat downvotes-* | jq -s 'map(.items | map(.down_vote_count) | add) | add' | |
| echo == Upvotes: == | |
| cat downvotes-* | jq -s 'map(.items | map(.up_vote_count) | add) | add' | |
| echo == Posts: == | |
| cat downvotes-* | jq -s 'map(.items | length) | add' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python3 | |
| # TODO: this is only SO — how to fetch from all StackExchange sites? | |
| import requests, pprint | |
| MY_USER_ID = 239657 | |
| # Don't remember exact content of filter but it includes .has_more and more info about votes. | |
| # See https://api.stackexchange.com/2.2/filters/!b0OfN6h15EULDG | |
| FILTER = '!b0OfN6h15EULDG' | |
| posts = [] | |
| for page in range(1, 1000): | |
| url = ("https://api.stackexchange.com/2.2/users/{MY_USER_ID}/posts?" | |
| "order=desc&sort=activity&site=stackoverflow&" | |
| "filter={FILTER}&page={page}".format(**vars())) | |
| json = requests.get(url).json() | |
| posts += json.pop('items') | |
| pprint.pprint(json) | |
| if not json['has_more']: | |
| break | |
| print('Posts:', len(posts)) | |
| print('Upvotes:', sum(p['up_vote_count'] for p in posts)) | |
| print('Downvotes:', sum(p['down_vote_count'] for p in posts)) | |
| print('== Downvoted posts ==') | |
| pprint.pprint([p for p in posts if p['down_vote_count'] > 0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment