From 574201235c09b3d1eb03d07564cc31ee889bf5c6 Mon Sep 17 00:00:00 2001 From: Ed Summers Date: Tue, 7 Mar 2017 12:25:48 -0500 Subject: [PATCH] search command This commit adds a search command where you can search for a variety of entities: fbarc search page blacklivesmatter fbarc search place minneapolis Searching for user, event, group require your app be out of sandbox mode (approved by FB). Missing from this commit are unittests (I couldn't quite figure out what was going on with the mocks). Also it seemed like paging of some kind would be useful, and that there was support for that that could be leveraged? --- fbarc.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) mode change 100644 => 100755 fbarc.py 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.