Exemplo n.º 1
0
 def update(texts, sentences):
     while not new_sentences.empty():
         epoch, sentence = new_sentences.get()
         if sentences:
             previous = latest(sentences)
             sentences[previous][1] = epoch  # mutate end
         eprint("%d: %s" % (epoch, sentence))
         sentences[key(sentence)] = [epoch, None, sentence]  # mutable end
         texts = None  # flag to reset below
     if not texts:
         texts = repeat_text(sentences)
     return texts, sentences
Exemplo n.º 2
0
 def do_GET(self):
     path = unquote_plus(self.path)
     if path.startswith('/'): path = path[1:]
     if path in self.server.static_content:
         self.server.static_content[path](self)
     else:
         self.server.update()
         if path.startswith('?q='): path = path[len('?q='):]
         print('***', path)
         try:
             self._lookup(self.server.sentences[key(path)])
         except KeyError:
             if path:
                 self._not_found()
             else:
                 self._current()
Exemplo n.º 3
0
        start, end, sentence = data
        self.send(self.server.format('''
<p class="sentence">{sentence!s}</p>
<p class="date"><span class="epoch">{start!s}</span> &mdash; <span class="epoch">{end!s}</span>.</p>
''', start=start, end=end, sentence=sentence, title='Timestamp lookup'))

    def _current(self):
        start, end, sentence = latest_dict(self.server.sentences)
        if end: self._not_found()  # current should have an open endpoint
        else: self.send(self.server.format('''
<p class="sentence"><a href="./?q={encoded!s}">{sentence!s}</a></p>
''', sentence=sentence, encoded=quote_plus(sentence), title='Current timestamp'))

    def _not_found(self):
        self.send_error(404)


TEST_URL = 'http://localhost:8081'

def test_static():
    chdir('/home/andrew/project/wordstamp/git/static')
    static = HTTPServer(('0.0.0.0', 8081), SimpleHTTPRequestHandler)
    Thread(target=static.serve_forever).start()


if __name__ == '__main__':
    test_static()
    words = Words()
    sentence = words.sentence()
    Server(8080, TEST_URL, OrderedDict([(key(sentence), (123456, None, sentence))]))()