def test_stackauth_site_instantiate(self): for defn in stackauth.StackAuth().sites(): site_ob = defn.get_site(API_KEY) # Do the same as test_fetch_answer() and hope we don't get an exception defn.get_site(API_KEY).answer(ANSWER_ID) # Only do it once! break
from __future__ import print_function import stackauth, string sites = stackauth.StackAuth().sites() source = [ '''import stackexchange class __SEAPI(str): def __call__(self): return stackexchange.Site(self)''' ] for site in sites: name = ''.join(c for c in site.name if c.isalnum()) source.append('%s = __SEAPI(\'%s\')' % (name, site.api_endpoint[7:])) print('\n'.join(source))
def test_stackauth_site_types(self): s = stackauth.StackAuth() for site in s.sites(): self.assertTrue(site.site_type in {stackauth.SiteType.MainSite, stackauth.SiteType.MetaSite})
import stackexchange, stackauth if len(sys.argv) < 3: print('Usage: versus.py YOUR_SO_UID THEIR_SO_UID') sys.exit(1) so = stackexchange.Site(stackexchange.StackOverflow, impose_throttling=True) user1, user2 = (int(x) for x in sys.argv[1:]) rep1, rep2 = {}, {} username1, username2 = (so.user(x).display_name for x in (user1, user2)) total_rep1, total_rep2 = 0, 0 sites = [] for site in stackauth.StackAuth().api_associated(so, user1): rep1[site.on_site.name] = site.reputation sites.append(site.on_site.name) for site in stackauth.StackAuth().api_associated(so, user2): rep2[site.on_site.name] = site.reputation for site in sites: total_rep1 += rep1[site] if site in rep2: total_rep2 += rep2[site] max_user = username1 max_rep, other_rep = rep1[site], rep2.get(site, 0) if rep2.get(site, 0) > rep1[site]: max_user = username2 max_rep, other_rep = other_rep, max_rep