diff --git a/examples/f.html b/examples/f.html new file mode 100644 index 0000000..e804397 --- /dev/null +++ b/examples/f.html @@ -0,0 +1,457 @@ + + + + + + + + + + +
+ + +

U:(ask) T:(66053792f79519bb21f0dad0a81fc696)

+
+

Friends

+ +
+
+

Following

+ +
+
+

Fans

+ +
+
+ + diff --git a/examples/f.rst b/examples/f.rst new file mode 100644 index 0000000..066876d --- /dev/null +++ b/examples/f.rst @@ -0,0 +1,142 @@ +U:(ask) T:(66053792f79519bb21f0dad0a81fc696) + +Friends +======= + +* abecciu (http://github.com/abecciu) +* acdha (http://github.com/acdha) +* alex (http://github.com/alex) +* auser (http://github.com/auser) +* batiste (http://github.com/batiste) +* benjaminws (http://github.com/benjaminws) +* boardman (http://github.com/boardman) +* bradjasper (http://github.com/bradjasper) +* brosner (http://github.com/brosner) +* carljm (http://github.com/carljm) +* cosimo (http://github.com/cosimo) +* cyrildoussin (http://github.com/cyrildoussin) +* digi604 (http://github.com/digi604) +* ericholscher (http://github.com/ericholscher) +* fictorial (http://github.com/fictorial) +* gcachet (http://github.com/gcachet) +* greut (http://github.com/greut) +* hammer (http://github.com/hammer) +* howiworkdaily (http://github.com/howiworkdaily) +* hugobr (http://github.com/hugobr) +* jacobian (http://github.com/jacobian) +* johnboxall (http://github.com/johnboxall) +* justinlilly (http://github.com/justinlilly) +* kcunning (http://github.com/kcunning) +* kvbik (http://github.com/kvbik) +* mahalo (http://github.com/mahalo) +* markng (http://github.com/markng) +* markpasc (http://github.com/markpasc) +* matagus (http://github.com/matagus) +* matclayton (http://github.com/matclayton) +* mmalone (http://github.com/mmalone) +* mnaberez (http://github.com/mnaberez) +* monadic (http://github.com/monadic) +* montylounge (http://github.com/montylounge) +* mulka (http://github.com/mulka) +* myme (http://github.com/myme) +* neilmock (http://github.com/neilmock) +* nowells (http://github.com/nowells) +* pagles (http://github.com/pagles) +* paulosuzart (http://github.com/paulosuzart) +* petrounias (http://github.com/petrounias) +* playpauseandstop (http://github.com/playpauseandstop) +* rays (http://github.com/rays) +* scotu (http://github.com/scotu) +* seanbrant (http://github.com/seanbrant) +* sebleier (http://github.com/sebleier) +* simonw (http://github.com/simonw) +* svetlyak40wt (http://github.com/svetlyak40wt) +* TheAtilla (http://github.com/TheAtilla) +* thejefflarson (http://github.com/thejefflarson) +* traviscline (http://github.com/traviscline) +* twillis (http://github.com/twillis) +* vandersonmota (http://github.com/vandersonmota) +* viniciuschagas (http://github.com/viniciuschagas) +* wargamez (http://github.com/wargamez) +* yashh (http://github.com/yashh) +* zacharyvoase (http://github.com/zacharyvoase) +* zuber (http://github.com/zuber) + +Following +========= + +* aaronelliotross (http://github.com/aaronelliotross) +* apollo13 (http://github.com/apollo13) +* bradleywright (http://github.com/bradleywright) +* davisp (http://github.com/davisp) +* dcramer (http://github.com/dcramer) +* dhellmann (http://github.com/dhellmann) +* django (http://github.com/django) +* eldarion (http://github.com/eldarion) +* erlang (http://github.com/erlang) +* freakboy3742 (http://github.com/freakboy3742) +* gmr (http://github.com/gmr) +* hungryblank (http://github.com/hungryblank) +* janl (http://github.com/janl) +* jespern (http://github.com/jespern) +* jnoller (http://github.com/jnoller) +* joearms (http://github.com/joearms) +* mattmatt (http://github.com/mattmatt) +* mongodb (http://github.com/mongodb) +* progrium (http://github.com/progrium) +* rabbitmq (http://github.com/rabbitmq) +* rares (http://github.com/rares) +* rhs (http://github.com/rhs) +* simplegeo (http://github.com/simplegeo) +* siwu (http://github.com/siwu) +* somic (http://github.com/somic) +* squaremo (http://github.com/squaremo) +* tonyg (http://github.com/tonyg) +* ubernostrum (http://github.com/ubernostrum) +* washingtontimes (http://github.com/washingtontimes) +* winhamwr (http://github.com/winhamwr) + +Fans +==== + +* amolenaar (http://github.com/amolenaar) +* andrewsmedina (http://github.com/andrewsmedina) +* andrulik (http://github.com/andrulik) +* asenchi (http://github.com/asenchi) +* beshrkayali (http://github.com/beshrkayali) +* caio (http://github.com/caio) +* clintecker (http://github.com/clintecker) +* codesplicer (http://github.com/codesplicer) +* codysoyland (http://github.com/codysoyland) +* Csele (http://github.com/Csele) +* deepthawtz (http://github.com/deepthawtz) +* dibaunaumh (http://github.com/dibaunaumh) +* ducky427 (http://github.com/ducky427) +* eculver (http://github.com/eculver) +* eferro (http://github.com/eferro) +* gintas (http://github.com/gintas) +* hbussell (http://github.com/hbussell) +* hughdbrown (http://github.com/hughdbrown) +* IanLewis (http://github.com/IanLewis) +* kaikuehne (http://github.com/kaikuehne) +* ledil (http://github.com/ledil) +* lsbardel (http://github.com/lsbardel) +* melito (http://github.com/melito) +* mgrouchy (http://github.com/mgrouchy) +* mykdzn (http://github.com/mykdzn) +* nabucosound (http://github.com/nabucosound) +* Nixarn (http://github.com/Nixarn) +* otfrom (http://github.com/otfrom) +* philippWassibauer (http://github.com/philippWassibauer) +* Raydiation (http://github.com/Raydiation) +* rlotun (http://github.com/rlotun) +* rzab (http://github.com/rzab) +* strange (http://github.com/strange) +* sunoano (http://github.com/sunoano) +* thoas (http://github.com/thoas) +* trent (http://github.com/trent) +* troynt (http://github.com/troynt) +* wcyee (http://github.com/wcyee) +* webiest (http://github.com/webiest) +* williamsjj (http://github.com/williamsjj) +* zen4ever (http://github.com/zen4ever) diff --git a/examples/friend-or-follow.py b/examples/friend-or-follow.py new file mode 100644 index 0000000..ccef96a --- /dev/null +++ b/examples/friend-or-follow.py @@ -0,0 +1,95 @@ +import sys +import optparse +from subprocess import Popen, PIPE + +from github2.client import Github + +ITEM_FMT = "* %s (%s)" +URL_USER_FMT = "http://github.com/%s" + +OPTION_LIST = ( + optparse.make_option('-t', '--api-token', + default=None, action="store", dest="api_token", type="str", + help="Github API token. Default is to find this from git config"), + optparse.make_option('-u', '--api-user', + default=None, action="store", dest="api_user", type="str", + help="Github Username. Default is to find this from git config"), +) +BY_LOWER = lambda value: value.lower() + + +class FriendOrFollow(object): + # Caching api calls + _followers = None + _following = None + + def __init__(self, username=None, api_user=None, api_token=None): + self.api_user = api_user or self.git_config_get("github.user") + self.api_token = api_token or self.git_config_get("github.token") + self.username = username or self.api_user + print("U:(%s) T:(%s) F:(%s)" % (self.api_user, self.api_token, + self.username)) + self.client = Github(self.api_user, self.api_token) + + def get_friends(self): + return sorted((user for user in self.following + if user in self.followers), key=BY_LOWER) + + def get_following(self): + return sorted((user for user in self.following + if user not in self.followers), key=BY_LOWER) + + def get_fans(self): + return sorted((user for user in self.followers + if user not in self.following), key=BY_LOWER) + + def users_with_urls(self, users): + return ((user, URL_USER_FMT % user) + for user in users) + + def git_config_get(self, key): + pipe = Popen(["git", "config", "--get", key], stdout=PIPE) + return pipe.communicate()[0].strip() + + @property + def followers(self): + if self._followers is None: + self._followers = self.client.users.followers(self.username) + return self._followers + + @property + def following(self): + if self._following is None: + self._following = self.client.users.following(self.username) + return self._following + + +def parse_options(arguments): + parser = optparse.OptionParser(option_list=OPTION_LIST) + options, values = parser.parse_args(arguments) + return options, values + + +def format_output(*data): + headify = lambda title: "\n".join([title, "=" * len(title)]) + itemify = lambda item: ITEM_FMT % item + + def format_section(header, items): + return "\n".join(["\n%s\n" % headify(header)] + + [itemify(item) for item in items]) + + return "\n".join(format_section(*section) + for section in data) + + +def main(): + options, values = parse_options(sys.argv[1:]) + username = values and values[0] or None + f = FriendOrFollow(username=username, **vars(options)) + print(format_output( + ("Friends", f.users_with_urls(f.get_friends())), + ("Following", f.users_with_urls(f.get_following())), + ("Fans", f.users_with_urls(f.get_fans())))) + +if __name__ == "__main__": + main()