Пример #1
0
def main(argv=None):
   if argv is None:
     argv = sys.argv

   try:
       try:
          opts, args = getopt.getopt(argv[1:],'hvj:o:',['help', 'verbose', 'json=', 'object='])
       except getopt.error, msg:
         raise _Usage(msg)    
     
       if len(opts) == 0:
           raise _Usage(_helpMessage)
         
       jsonFile=None
       objectType=None
       
       for option, value in opts:           
          if option in ('-h', '--help'):
             raise _Usage(_helpMessage)
          elif option in ('-v', '--verbose'):
             global _verbose
             _verbose = True
          elif option in ('-j', '--json'):
             jsonFile = value
          elif option in ('-o', '--object'):
             objectType = value
             

       if not os.path.exists(jsonFile):
           print >>sys.stderr,"Path: ["+jsonFile+"] does not exist!\n"
           return 2
       
       if objectType == None:
           raise _Usage(_helpMessage)

       f = open(jsonFile, 'r')
       jsonContents = f.read()
       jsonObjects = prepareDocs(jsonContents, objectType)
       for obj in jsonObjects:
        cleanseImage(obj)
        cleanseBody(obj)
        formatDate(obj)
        unravelStructs(obj)    
        filePath = os.getcwd() + "/" + str(obj["id"])+".json"
        verboseLog("Writing json file: ["+filePath+"]")
        writeDoc(obj, filePath)
Пример #2
0
def main(argv=None):
    if argv is None:
        argv = sys.argv
    try:
        try:
            opts, args = getopt.getopt(argv[1:], 'hvu:o:',
                                       ['help', 'verbose', 'url=', 'object='])
        except getopt.error, msg:
            raise _Usage(msg)

        if len(opts) == 0:
            raise _Usage(_helpMessage)

        solrUrl = None
        objectType = None

        for option, value in opts:
            if option in ('-h', '--help'):
                raise _Usage(_helpMessage)
            elif option in ('-v', '--verbose'):
                global _verbose
                _verbose = True
            elif option in ('-u', '--url'):
                solrUrl = value
            elif option in ('-o', '--object'):
                objectType = value

        if solrUrl == None or objectType == None:
            raise _Usage(_helpMessage)

        for filename in sys.stdin:
            filename = filename.rstrip()
            if not ".json" in filename or not os.path.exists(filename):
                continue
            verboseLog("Processing: " + filename)
            f = open(filename, 'r')
            jsonContents = f.read()
            jsonObjs = prepareDocs(jsonContents, objectType)
            for obj in jsonObjs:
                cleanseImage(obj)
                cleanseBody(obj)
                formatDate(obj)
                unravelStructs(obj)
                postString = prepareDocForSolr(obj, False)
                verboseLog(postString)
                postJsonDocToSolr(solrUrl, postString)
Пример #3
0
def main(argv=None):    
   if argv is None:
       argv = sys.argv
   try:
       try:
          opts, args = getopt.getopt(argv[1:],'hvu:o:',['help', 'verbose', 'url=', 'object='])
       except getopt.error, msg:
         raise _Usage(msg)    
     
       if len(opts) == 0:
           raise _Usage(_helpMessage)
         
       solrUrl=None
       objectType=None
       
       for option, value in opts:           
          if option in ('-h', '--help'):
             raise _Usage(_helpMessage)
          elif option in ('-v', '--verbose'):
             global _verbose
             _verbose = True
          elif option in ('-u', '--url'):
             solrUrl = value
          elif option in ('-o', '--object'):
             objectType = value
             

       if solrUrl == None or objectType == None:
           raise _Usage(_helpMessage)

       for filename in sys.stdin:
           filename = filename.rstrip()
           if not ".json" in filename or not os.path.exists(filename):
               continue
           verboseLog("Processing: "+filename)
           f = open(filename, 'r')
           jsonContents = f.read()
           jsonObjs = prepareDocs(jsonContents, objectType)
           for obj in jsonObjs:
               cleanseImage(obj)
               cleanseBody(obj)
               formatDate(obj)
               unravelStructs(obj)    
               postString = prepareDocForSolr(obj, False)
               verboseLog(postString)
               postJsonDocToSolr(solrUrl, postString)