Ejemplo n.º 1
0
 def write(self, strings):
   "Write a list of strings"
   for string in strings:
     if not isinstance(string, basestring):
       Trace.error('Not a string: ' + unicode(string) + ' in ' + unicode(strings))
       return
     self.writestring(string)
Ejemplo n.º 2
0
 def readall(self):
     "Read the whole file"
     for encoding in FileConfig.parsing['encodings']:
         try:
             return self.readcodec(encoding)
         except UnicodeDecodeError:
             pass
     Trace.error('No suitable encoding for ' + self.filename)
     return []
Ejemplo n.º 3
0
 def readall(self):
     "Read the whole file"
     for encoding in FileConfig.parsing["encodings"]:
         try:
             return self.readcodec(encoding)
         except UnicodeDecodeError:
             pass
     Trace.error("No suitable encoding for " + self.filename)
     return []
Ejemplo n.º 4
0
 def dotseparated(self, number):
   "Get the number separated by dots: 1.1.3"
   dotsep = ''
   if len(number) == 0:
     Trace.error('Empty number')
     return '.'
   for piece in number:
     dotsep += '.' + unicode(piece)
   return dotsep[1:]
Ejemplo n.º 5
0
 def gethtml(self, container):
   "Return the HTML code"
   html = []
   if container.contents == None:
     return html
   for element in container.contents:
     if not hasattr(element, 'gethtml'):
       Trace.error('No html in ' + element.__class__.__name__ + ': ' + unicode(element))
       return html
     html += element.gethtml()
   return html
Ejemplo n.º 6
0
 def increase(self, number):
   "Increase the number (or letter)"
   if not isinstance(number, str):
     return number + 1
   if number == '-':
     index = 0
   elif not number in NumberGenerator.letters:
     Trace.error('Unknown letter numeration ' + number)
     return 0
   else:
     index = NumberGenerator.letters.index(number) + 1
   return self.letter(index)
Ejemplo n.º 7
0
 def convert(self, filename, directory=''):
     "Convert the filename adding the appropriate directories."
     if os.path.exists(filename):
         return filename
     newname = os.path.join(self.directory, filename)
     if os.path.exists(newname):
         return newname
     newname = os.path.join(directory, filename)
     if os.path.exists(newname):
         return newname
     Trace.error('Missing file ' + filename)
     return None
Ejemplo n.º 8
0
 def gethtml(self, container):
     "Return the HTML code"
     html = []
     if container.contents == None:
         return html
     for element in container.contents:
         if not hasattr(element, 'gethtml'):
             Trace.error('No html in ' + element.__class__.__name__ + ': ' +
                         unicode(element))
             return html
         html += element.gethtml()
     return html
Ejemplo n.º 9
0
 def convert(self, filename, directory = ''):
   "Convert the filename adding the appropriate directories."
   if os.path.exists(filename):
     return filename
   newname = os.path.join(self.directory, filename)
   if os.path.exists(newname):
     return newname
   newname = os.path.join(directory, filename)
   if os.path.exists(newname):
     return newname
   Trace.error('Missing file ' + filename)
   return None
    def __init__(self, *argv):
        "Analyze the command line args and launch the Twitter location stream"

        southwest = None
        northeast = None
        output = sys.stdout
        # set KeyboardInterrupt signal handler
        signal.signal(signal.SIGINT, self.keyboard_interrupt_handler)
        #turn tuple into list
        argv = list(argv)
        # remove the first argument
        argv.pop(0)
        # iterate the list
        for argument in argv[:]:
            # look for southwest
            if argument == "-sw":
                try:
                    southwest = argv[argv.index("-sw") + 1]
                except IndexError:
                    self.usage()
                    return
                argv.remove("-sw")
                argv.remove(southwest)
            # look for northeast
            if argument == "-ne":
                try:
                    northeast = argv[argv.index("-ne") + 1]
                except IndexError:
                    self.usage()
                    return
                argv.remove("-ne")
                argv.remove(northeast)
        # check if argv was correct
        if southwest is None or northeast is None or len(argv) > 1:
            self.usage()
            return
        # check for output
        if len(argv) == 1:
            output = open(argv[0], "w")
        # launch the LocationStream
        self.twitterstream = LocationStream(southwest + "," + northeast)
        try:
            stream = self.twitterstream.start()
            Trace.message("Twitter stream started!!")
            Trace.message("Press ctrl+c to stop.")
        except:
            Trace.error("Raised exception: " + str(sys.exc_info()[0]))
            Trace.error("Stopping twitterstream")
            self.twitterstream.stop()
            return
        for line in stream:
            print >> output, line.strip()
Ejemplo n.º 11
0
 def generateordered(self, type):
   "Generate ordered numbering: a number to use and possibly concatenate "
   "with others. Example: Chapter 1, Section 1.5."
   level = self.getlevel(type)
   if level == 0:
     Trace.error('Impossible level 0 for ' + type)
     return '.'
   if len(self.number) >= level:
     self.number = self.number[:level]
   else:
     while len(self.number) < level:
       self.number.append(0)
   self.number[level - 1] = self.increase(self.number[level - 1])
   return self.dotseparated(self.number)
Ejemplo n.º 12
0
 def number(self, layout):
   "Set all attributes: number, entry, level..."
   if self.generator.isunique(layout):
     number = self.generator.generateunique(layout.type)
     self.setcommonattrs(layout, number)
     layout.anchortext = ''
     if layout.number != '':
       layout.anchortext = layout.entry + '.'
     return
   if not self.generator.isinordered(layout):
     Trace.error('Trying to number wrong ' + unicode(layout))
     return
   # ordered or unordered
   if self.generator.isnumbered(layout):
     number = self.generator.generateordered(layout.type)
   else:
     number = self.generator.generateunique(layout.type)
   self.setcommonattrs(layout, number)
   layout.anchortext = layout.number
   layout.output.tag = layout.output.tag.replace('?', unicode(layout.level))
Ejemplo n.º 13
0
 def findtranslation(self):
     "Find the translation for the document language."
     self.langcodes = None
     if not self.language:
         Trace.error('No language in document')
         return
     if not self.language in TranslationConfig.languages:
         Trace.error('Unknown language ' + self.language)
         return
     if TranslationConfig.languages[self.language] == 'en':
         return
     langcodes = [TranslationConfig.languages[self.language]]
     try:
         self.translation = gettext.translation('elyxer', None, langcodes)
     except IOError:
         Trace.error('No translation for ' + unicode(langcodes))
Ejemplo n.º 14
0
 def findtranslation(self):
   "Find the translation for the document language."
   self.langcodes = None
   if not self.language:
     Trace.error('No language in document')
     return
   if not self.language in TranslationConfig.languages:
     Trace.error('Unknown language ' + self.language)
     return
   if TranslationConfig.languages[self.language] == 'en':
     return
   langcodes = [TranslationConfig.languages[self.language]]
   try:
     self.translation = gettext.translation('elyxer', None, langcodes)
   except IOError:
     Trace.error('No translation for ' + unicode(langcodes))
    def usage(self):
        "Show command line help."

        Trace.error('Usage: twitterstream.py -sw 2.012,45.3232 -ne 3.119,48.8777 [fileout]')
        Trace.error('Launch a twitter stream client and send the result to an output')
        Trace.error('[fileout]: the file to dump the output. Stdout if omitted')
        Trace.error('  Parameters:')
        Trace.error('    --sw: longitude,latitude coordinates of the South West corner of the bounding box. Compulsory.')
        Trace.error('    --ne: longitude,latitude coordinates of the North East corner of the bounding box. Compulsory.')
        Trace.error('Example: python run_location_stream.py -sw -11.733398,35.763229 -ne 5.009766,42.970492')
Ejemplo n.º 16
0
 def usage(self):
     Trace.error('Usage: coalesce.py filein [fileout]')
     return
Ejemplo n.º 17
0
 def usage(self):
   Trace.error('Usage: coalesce.py filein [fileout]')
   return