Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.py
More file actions
Latest commit
69 lines (52 loc) · 1.96 KB
/
Copy pathcore.py
File metadata and controls
69 lines (52 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""
Core application / API interaction logic of the GitHub example.
None of this code needs to change based on your I/O strategy -- you can
use blocking API (e.g. the ``requests`` library) or Twisted, asyncio,
or Tornado implementations of an HTTP client with this code, by providing
different performers for the :obj:`HTTPRequest` intent.
"""
from __future__ importprint_function
fromfunctoolsimportreduce
importjson
importoperator
fromeffectimportEffect, parallel
fromreadline_intentimportReadLine
fromehttp.http_intentimportHTTPRequest
defget_orgs(name):
"""
Fetch the organizations a user belongs to.
:return: An Effect resulting in a list of strings naming the user's
organizations.
"""
req=Effect(
HTTPRequest("get", "https://api.github.com/users/{0}/orgs".format(name))
)
returnreq.on(success=lambdax: [org["login"] fororginjson.loads(x)])
defget_org_repos(name):
"""
Fetch the repos that belong to an organization.
:return: An Effect resulting in a list of strings naming the repositories.
"""
req=Effect(
HTTPRequest("get", "https://api.github.com/orgs/{0}/repos".format(name))
)
returnreq.on(success=lambdax: [repo["name"] forrepoinjson.loads(x)])
defget_orgs_repos(name):
"""
Fetch ALL of the repos that a user has access to, in any organization.
:return: An Effect resulting in a list of repositories.
"""
req=get_orgs(name)
req=req.on(lambdaorg_names: parallel(map(get_org_repos, org_names)))
req=req.on(lambdarepo_lists: reduce(operator.add, repo_lists))
returnreq
defmain_effect():
"""
Request a username from the keyboard, and look up all repos in all of
that user's organizations.
:return: an Effect resulting in a list of repositories.
"""
intent=ReadLine("Enter Github Username> ")
read_eff=Effect(intent)
org_repos_eff=read_eff.on(success=get_orgs_repos)
returnorg_repos_eff