import json from argparse import ArgumentParser from stackexchange import Site from stackexchange import StackOverflow def get_parser(): parser = ArgumentParser() parser.add_argument('--tags') parser.add_argument('--n', type=int, default=20) return parser if __name__ == '__main__': parser = get_parser() args = parser.parse_args() my_key = os.environ.get('STACK_KEY') so = Site(StackOverflow, my_key) questions = so.questions(tagged=args.tags, pagesize=20)[:args.n] for i, item in enumerate(questions): print("{}) {} by {}".format(i, item.title, item.owner.display_name))
try: import config se_key = config.stackexchange['api_key'] except: se_key = os.environ.get('SE_KEY') if not se_key: import sys print 'No config.py file found. Exiting...' sys.exit(0) MAX_QUESTIONS = 10 app = Flask(__name__) so = Site(StackOverflow, se_key) def get_response_string(q): q_data = q.json check = ' :white_check_mark:' if q.json['is_answered'] else '' return "|%d|%s <%s|%s> (%d answers)" % (q_data['score'], check, q.url, q.title, q_data['answer_count']) @app.route('/overflow', methods=['post']) def overflow(): ''' Example: /overflow python list comprehension '''
#!/usr/bin/env python from __future__ import print_function # a hack so you can run it 'python demo/highest_voted.py' import sys sys.path.append('.') sys.path.append('..') from stackauth import StackAuth from stackexchange import Site, StackOverflow, Sort, DESC so = Site(StackOverflow) print('The highest voted question on StackOverflow is:') question = so.questions(sort=Sort.Votes, order=DESC)[0] print('\t%s\t%d' % (question.title, question.score)) print() print('Look, see:', question.url)
#!/usr/bin/env python from __future__ import print_function # a hack so you can run it 'python demo/narcissism.py' import sys sys.path.append('.') sys.path.append('..') from stackauth import StackAuth from stackexchange import Site, StackOverflow user_id = 41981 if len(sys.argv) < 2 else int(sys.argv[1]) print('StackOverflow user %d\'s accounts:' % user_id) stack_auth = StackAuth() so = Site(StackOverflow, impose_throttling=True) accounts = stack_auth.api_associated(so, user_id) reputation = {} for account in accounts: print(' %s / %d reputation' % (account.on_site.name, account.reputation)) # This may seem a slightly backwards way of storing it, but it's easier for finding the max reputation[account.reputation] = account.on_site.name print('Most reputation on: %s' % reputation[max(reputation)])
def get_site(self, **kw): # A bit hackish; strips off the "http://" domain = self.api_endpoint[7:] return Site(domain, **kw)
def get_site(self, *a, **kw): return Site(self.api_site_parameter, *a, **kw)