diff --git a/fbarc.py b/fbarc.py old mode 100644 new mode 100755 index 66778c9..95a67ce --- a/fbarc.py +++ b/fbarc.py @@ -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) @@ -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 @@ -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.