Ejemplo n.º 1
0
Archivo: api.py Proyecto: samirahmed/fu
    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
Ejemplo n.º 2
0
Archivo: api.py Proyecto: stayhigh/fu
    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
Ejemplo n.º 3
0
Archivo: api.py Proyecto: samirahmed/fu
    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)
Ejemplo n.º 4
0
		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)
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
		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 ) 
Ejemplo n.º 7
0
    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)
Ejemplo n.º 8
0
Archivo: api.py Proyecto: benvd/fu
		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) 
Ejemplo n.º 9
0
    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)
Ejemplo n.º 10
0
Archivo: api.py Proyecto: stayhigh/fu
    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)