예제 #1
0
    def process(self):
        update_obj = []
        
        entries = process("http://www.mitbbs.com/board_rss/FleaMarket.xml")
        for key,entry in entries.items():
            obj = self.parse_rss(key,entry)
        
            if obj != None:
                update_obj.append(obj)


        return update_obj
예제 #2
0
def processTimes(server, xml):
   from time import mktime, strptime
   data = parse.process(xml,tag=server['options']['tag'])

   if (len(data) == 0):
      return None
   
   sname = server['params']['propertyName']

   data = data[0][data[0].keys()[0]]
   [int(mktime(strptime(x[sname.lower()].split('T')[0],"%Y-%m-%d"))) for x in data] 
   
   return data
예제 #3
0
 def test_german(self):
     text = "Den ganzen Druck vorwärts, statt zu verteidigen!\n\n\n\n\nDas eine trieb das andere an; " \
            "so lächerlich es Ihnen vielleicht scheint, ich \n begann mich zu beschimpfen – 'schneller, schneller!"
     wanted = "Den ganzen Druck vorwärts, statt zu verteidigen! Das eine trieb das andere an; " \
              "so lächerlich es Ihnen vielleicht scheint, ich \n begann mich zu beschimpfen – 'schneller, schneller!"
     self.assertEqual(" ".join(process(text, "de")), wanted)
예제 #4
0
 def test_spanish(self):
     text = "¡El español es bueno, vivir es lindo!¡Buena suerte y crédito en tu bolsillo!"
     wanted = "¡El español es bueno, vivir es lindo!"
     self.assertEqual("".join(process(text, "es")), wanted)
예제 #5
0
 def test_russian(self):
     text = "Все сдали лабу, кроме меня! А тесты сами себя не пишут, почему? Получается, автотесты не настоящие!"
     wanted = "Все сдали лабу, кроме меня! Получается, автотесты не настоящие!"
     self.assertEqual(" ".join(process(text, "ru")), wanted)
예제 #6
0
 def test_nothing(self):
     text = None
     wanted = None
     self.assertEqual(process(text), wanted)
예제 #7
0
파일: run.py 프로젝트: leogermond/primer
def run():
    """This method is run by typing `blender-chemicals` into a terminal."""
    parser = argparse.ArgumentParser(description="Imports chemicals into "
                                     "Blender with Open Babel.")
    parser.add_argument('input', help="The file or smiles string to draw.")
    parser.add_argument('--format',
                        type=str,
                        default='auto',
                        help="The "
                        "chemical format of the input file. Defaults to "
                        "'auto', which uses the file extension.")
    parser.add_argument('--convert-only',
                        action='store_true',
                        help="Converts "
                        "the input into a simplified JSON format and prints "
                        "to stdout. Does not draw.")
    parser.add_argument('--space-filling',
                        action='store_true',
                        help="Draws "
                        "a space-filling (instead of ball-and-stick) "
                        "representation.")
    parser.add_argument('--no-join',
                        dest='join',
                        action='store_false',
                        help="Skips joining the atoms/bonds into a single "
                        "mesh. Use if you want to individually edit atoms in "
                        "Blender, but note it will impair performance.")
    parser.add_argument('--join-colors',
                        dest='join',
                        action='store_const',
                        const='colors',
                        help="For each material (color), joins all objects "
                        "with that material. Cuts down on the number of "
                        "particle systems needed when morphing.")
    parser.add_argument('--no-hydrogens',
                        dest='hydrogens',
                        action='store_false',
                        help="Avoids drawing hydrogens.")
    parser.add_argument('--no-generate-coords',
                        dest='generate_coords',
                        action='store_false',
                        help="Skips generating 3D "
                        "coordinates.")
    parser.add_argument('--no-infer-bonds',
                        dest='infer_bonds',
                        action='store_false',
                        help="Skips inferring bonds.")

    args = parser.parse_args()

    try:
        with open(args.input) as in_file:
            data = in_file.read()
        is_file = True
    except IOError:
        data = args.input
        is_file = False

    if args.format == 'auto':
        chemformat = os.path.splitext(args.input)[1][1:] if is_file else 'smi'
    else:
        chemformat = args.format

    if not pybel.informats:
        sys.stderr.write("Open babel not properly installed. Exiting.\n")
        sys.exit()
    if chemformat not in pybel.informats:
        prefix = "Inferred" if args.format == 'auto' else "Supplied"
        formats = ', '.join(pybel.informats.keys())
        sys.stderr.write(
            ("{} format '{}' not in available open babel formats."
             "\n\nSupported formats:\n{}\n").format(prefix, chemformat,
                                                    formats))
        sys.exit()

    try:
        mol = pybel.readstring(chemformat, data)
    except OSError:
        prefix = "Inferred" if args.format == 'auto' else "Supplied"
        debug = ((" - Read input as file."
                  if is_file else " - Inferred input as string, not file.") +
                 "\n - {} format of '{}'.".format(prefix, chemformat))
        sys.stderr.write("Could not read molecule.\n\nDebug:\n" + debug + "\n")
        sys.exit()

    json_mol = process(mol, args.hydrogens, args.generate_coords,
                       args.infer_bonds, args.convert_only)
    #print(json_mol)
    if args.convert_only:
        print(json_mol)
        sys.exit()

    mac_path = '/Applications/blender.app/Contents/MacOS/./blender'
    if shutil.which('blender') is not None:
        blender = 'blender'
    elif os.path.isfile(mac_path):
        blender = mac_path
    else:
        sys.stderr.write("Could not find installed copy of Blender. Either "
                         "make sure it's on your path or copy the contents of "
                         "`draw.py` into a running blender instance.\n")
        sys.exit()

    root = os.path.normpath(os.path.dirname(__file__))
    script = os.path.join(root, 'draw.py')
    command = [blender, '--python', script, '--', json_mol]
    if args.space_filling:
        command.append('--space-filling')
    if args.join == False:
        command.append('--no-join')
    if args.join == 'colors':
        command.append('--join-colors')
    #print(command)
    with open(os.devnull, 'w') as null:
        subprocess.Popen(command, stdout=null, stderr=null)
예제 #8
0
파일: wfs.py 프로젝트: OPEC-PML/GISportal
def processBODCResponse(response, params):
   import parse
   import string
   import operator
   
   output = {}
   
   typename = string.split(str(params['typeName'].value).lower(), ':', 1)[1]
   data = parse.process(response, tag=None)[0]     
   feature = data['featuremembers'][typename]
   sortedFeature = sorted(feature.iteritems(), key = operator.itemgetter(0))
         
   if 'shref' in feature:
      output['shref'] = feature['shref']         
   if 'datacat' in feature:
      output['datacat'] = feature['datacat']        
   if 'instrument' in feature:
      output['instrument'] = feature['instrument']        
   if 'country' in feature:
      output['country'] = feature['country']
   if 'org' in feature:
      output['org'] = feature['org']
   if 'startdate' in feature:
      output['startdate'] = feature['startdate']
   if 'projectnam' in feature:
      output['projectnam'] = feature['projectnam']
   if 'theme' in feature:
      output['theme'] = feature['theme']
   if 'paramgroup' in feature:
      output['paramgroup'] = feature['paramgroup']
   if 'paramdisp' in feature:
      output['paramdisp'] = feature['paramdisp']
   if 'metadata' in feature:
      output['metadata'] = feature['metadata']
   if 'dataqxf' in feature:
      output['dataqxf'] = feature['dataqxf']
   if 'dataodv' in feature:
      output['dataodv'] = feature['dataodv']
   if 'databodcreq' in feature:
      output['databodcreq'] = feature['databodcreq']
   if 'dataplot1' in feature:
      output['dataplot1'] = feature['dataplot1']
   if 'dataplot2' in feature:
      output['dataplot2'] = feature['dataplot2']
   if 'dataplot3' in feature:
      output['dataplot3'] = feature['dataplot3']
   if 'dataplot4' in feature:
      output['dataplot4'] = feature['dataplot4']
   if 'dataplot5' in feature:
      output['dataplot5'] = feature['dataplot5']
   if 'dataplot6' in feature:
      output['dataplot6'] = feature['dataplot6']
   if 'dataplot7' in feature:
      output['dataplot7'] = feature['dataplot7']
   if 'dataplot8' in feature:
      output['dataplot8'] = feature['dataplot8']
   if 'dataplot9' in feature:
      output['dataplot9'] = feature['dataplot9']
   if 'dataplot10' in feature:
      output['dataplot10'] = feature['dataplot10']
   if 'dataplot11' in feature:
      output['dataplot11'] = feature['dataplot11']
   
   if 'shape' in feature:
      shape = feature['shape']
      if 'point' in shape:
         point = shape['point']
         if 'pos' in point:
            output['position'] = point['pos']
   
   content = ""
            
   for item in sortedFeature:
      if item[0] != 'shape':
         # See if it contains a url
         temp = '<div><br> %s: %s </div>' % (item[0], replaceAll(item[1], {'&lt;': '<', '&gt;': '>'}))
         if '<a' in temp and "'>" in temp:
            content += replaceAll(temp, {"'>": "' target='_blank'>"})
         else:
            content += temp
      
   output['content'] = content;
                   
   return output