Skip to content
This repository has been archived by the owner on Mar 26, 2020. It is now read-only.

search command #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions fbarc.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ def main():
elif args.command == 'url':
fb = Fbarc()
print(fb.generate_url(args.node, args.node_type_definition, escape=args.escape))
elif args.command == 'search':
app_id, app_secret = load_keys(args)
fb = Fbarc(app_id=app_id, app_secret=app_secret)
print_graph(fb.search(args.node_type, args.query))
else:
# Load keys
app_id, app_secret = load_keys(args)
Expand Down Expand Up @@ -219,6 +223,10 @@ def get_argparser():

subparsers.add_parser('configure', help='input API credentials and store in configuration file')

search_parser = subparsers.add_parser('search', help='search for resources of a particular type from the Graph API')
search_parser.add_argument('node_type', choices=['user', 'page', 'event', 'group', 'place', 'placetopic'])
search_parser.add_argument('query')

return parser


Expand Down Expand Up @@ -345,6 +353,13 @@ def discover_type(self, node_id):
"""
return self.get_metadata(node_id)['metadata']['type']

def search(self, node_type, q):
"""
Search.
"""
return self._perform_http_get(self._prepare_url('search'),
params={'type': node_type, 'q': q})

def _prepare_request(self, node_id, node_type_definition_name):
"""
Prepare the request url and params.
Expand Down