def handle_confluence_search(bot, ievent): if "channels" not in cfg.data or ievent.channel not in cfg.data["channels"]: ievent.reply("Confluence wiki search not enabled for this channel") return serverName = cfg.data["channels"][ievent.channel] server = cfg.data["servers"][serverName] if len(ievent.args) == 0: ievent.reply("The wiki is located at %s" % server["url"]) return args = ievent.args if args[0][0] == "#": maxResults = int(args[0].strip("#")) args = args[1:] else: maxResults = 5 query = " ".join(args) try: client, auth = getRpcClient(server) results = client.search(auth, query, maxResults) except Exception as ex: ievent.reply("an error occured: %s" % str(ex)) ; return ievent.reply("Displaying %s result(s) :" % min(maxResults, len(results))) for page in results[:maxResults]: tinyurl = get_tinyurl(page["url"]) tinyurl = tinyurl[0] if tinyurl else page["url"] ievent.reply('"%s": %s' % (page["title"], tinyurl))
def main(): client = Client() print("WELCOME TO THE TINY BOOKSTORE!") while True: print() command = input( "What do you want to do? (Search, Lookup, Buy) ").lower() if command == "search": topic = input("Topic: ") client.search(topic) elif command == "lookup": item_num = int(input("Item number: ")) client.lookup(item_num) elif command == "buy": item_num = int(input("Item number of book to buy: ")) client.buy(item_num) elif command == "": break else: print("Invalid command. Please try again.")
def get_package_infos(name): """ Get the package"s name, version and description from [PyPI](https://pypi.org/pypi). """ client = xmlrpc.client.ServerProxy("https://pypi.org/pypi") search_result = client.search({"name": name}) package_info_list = [] for i, pkg in enumerate(search_result): pkg_name = pkg["name"] pkg_version = pkg["version"] pkg_summary = pkg["summary"] pkg_info = PackageInfo(pkg_name, pkg_version, pkg_summary) package_info_list.append(pkg_info) return package_info_list[::-1]
def _get_search_results(self, query: str): client = xmlrpc.client.ServerProxy("https://pypi.org/pypi") search_results = client.search({"name": query}) return search_results[:10] if len( search_results) > 10 else search_results