def display(self, isVerbose, count, showAll): self.total = len(self.response_json) # Check if we have any results, if inform user and exit if self.total < 1: # Print with some red print color.cyan("fu") + ": No Results Matching Query" sys.exit(0) display_count = self.total if showAll else min(self.total, count) num = 1 # Print each response for result in self.response_json[:display_count]: # Extract the summary and commands summary = result["summary"] command = color.green(result["command"]) # Highlight any of the search terms summary = self.__highlight(summary) # Highlight any of a print " %s\t# " % color.cyan(str(num)), summary print "\t", command if isVerbose: print "\tURL: ", result["url"] print "\tvotes: ", result["votes"] print "" num += 1 self.display_count = display_count
def display(self, isVerbose, count, showAll): self.total = len(self.response_json) # Check if we have any results, if inform user and exit if (self.total < 1): # Print with some red print color.cyan('fu') + ": No Results Matching Query" sys.exit(0) display_count = self.total if showAll else min(self.total, count) num = 1 # Print each response for result in self.response_json[:display_count]: # Extract the summary and commands summary = result['summary'] command = color.green(result['command']) # Highlight any of the search terms summary = self.__highlight(summary) # Highlight any of a print ' %s\t# ' % color.cyan(str(num)), summary print '\t', command if isVerbose: print '\tURL: ', result['url'] print '\tvotes: ', result['votes'] print "" num += 1 self.display_count = display_count
def load(self): try: # Make request to the commandline fu API, split response by lines and print ### In case of proxy requirement ### ## # os.environ['http_proxy'] = '$hostname:$port' # os.environ['no_proxy'] = '$hostname' # urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler())) headers = { "User-Agent": r"Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7", "Accept-Encoding": "gzip, deflate", } req = urllib2.Request(self.url, headers=headers) results = urllib2.urlopen(req) response_text = results.read() if "gzip" in results.headers.get("Content-Encoding", ""): import zlib response_text = zlib.decompress(response_text, 16 + zlib.MAX_WBITS) import re m = re.search(r"\[.*\]", response_text) ### make sure only json array. response_text = m.group(0) self.raw_json = response_text # Create json file and return self.response_json = json.loads(response_text) return self.response_json except urllib2.URLError, e: # In the event we have an Error we inform the user with/ colors errorStr = "%s: %s. Unable to connect to commandlinefu.com" % (color.cyan("fu"), color.red("ERROR")) sys.exit(errorStr)
def open(self,string): # We will attempt to open the url try: webbrowser.open(string) except: print "%s: %s. \n\t%s" % (color.cyan('fu'), color.fail('Unable to Open Browser' ) , string)
def open(self, string): # We will attempt to open the url try: webbrowser.open(string) except: print "%s: %s. \n\t%s" % ( color.cyan('fu'), color.fail('Unable to Open Browser'), string)
def copy(self,string): # Assuming it works, we try and execute the function worked = True try: subprocess.Popen([self.copy_command], stdin=subprocess.PIPE).communicate(str(unicode(string))) except Exception, why: # If it doesn't work return flase worked = False print "%s: %s. The %s command failed" % ( color.cyan('fu'), color.fail('ERROR'), self.copy_command )
def copy(self, string): # Assuming it works, we try and execute the function worked = True try: subprocess.Popen(shlex.split(self.copy_command), stdin=subprocess.PIPE).communicate( str(unicode(string))) except Exception, why: # If it doesn't work return flase worked = False print "%s: %s. The %s command failed" % ( color.cyan('fu'), color.fail('ERROR'), self.copy_command)
def load( self ) : try : # Make request to the commandline fu API, split response by lines and print results = urllib2.urlopen(self.url) response_text = results.read() self.raw_json = response_text # Create json file and return self.response_json = json.loads(response_text) return self.response_json except urllib2.URLError, e: # In the event we have an Error we inform the user with/ colors errorStr = "%s: %s. Unable to connect to commandlinefu.com" %(color.cyan("fu"), color.red("ERROR") ) sys.exit(errorStr)
def load(self): try: # Make request to the commandline fu API, split response by lines and print results = urllib2.urlopen(self.url) response_text = results.read() self.raw_json = response_text # Create json file and return self.response_json = json.loads(response_text) return self.response_json except urllib2.URLError, e: # In the event we have an Error we inform the user with/ colors errorStr = "%s: %s. Unable to connect to commandlinefu.com" % ( color.cyan("fu"), color.red("ERROR")) sys.exit(errorStr)
def load(self): try: # Make request to the commandline fu API, split response by lines and print ### In case of proxy requirement ### ## # os.environ['http_proxy'] = '$hostname:$port' # os.environ['no_proxy'] = '$hostname' # urllib2.install_opener(urllib2.build_opener( urllib2.ProxyHandler())) headers = { 'User-Agent': r'Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7', 'Accept-Encoding': 'gzip, deflate' } req = urllib2.Request(self.url, headers=headers) results = urllib2.urlopen(req) response_text = results.read() if 'gzip' in results.headers.get('Content-Encoding', ''): import zlib response_text = zlib.decompress(response_text, 16 + zlib.MAX_WBITS) import re m = re.search(r'\[.*\]', response_text) ### make sure only json array. response_text = m.group(0) self.raw_json = response_text # Create json file and return self.response_json = json.loads(response_text) return self.response_json except urllib2.URLError, e: # In the event we have an Error we inform the user with/ colors errorStr = "%s: %s. Unable to connect to commandlinefu.com" % ( color.cyan("fu"), color.red("ERROR")) sys.exit(errorStr)