コード例 #1
0
 def __wait_until(self, epoch):
     now = time()
     while epoch > now:
         eprint('waiting til %d (%ds)' % (epoch, epoch - now))
         sleep(max(0, epoch - now))
         now = time()
     return int(now)
コード例 #2
0
 def write(self, append, epoch, sentence):
     if append:
         if self.__twitter:
             try: self.__twitter.statuses.update(status=sentence)
             except Exception as e: eprint(e)
         else:
             eprint('Dummy twitter: %s' % sentence)
コード例 #3
0
 def __push(self):
     try:
         self.__git.add(self.__path)
         self.__git.commit(self.__path, m='new sentence')
         self.__git.push()
     except GitException as e:
         eprint(e)
コード例 #4
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
コード例 #5
0
def run(path, twitter, port, static):
    new_sentences = Queue()
    targets = (sentence_process, server_process)
    args = ((path, twitter, new_sentences), (port, static, new_sentences))
    processes = ([None], [None])  # mutable 'pointers'
    while True:
        for target, arg, process in zip(targets, args, processes):
            if not process[0] or not process[0].is_alive():
                eprint("Starting %s" % target)
                process[0] = Process(target=target, args=arg)
                process[0].start()
        sleep(1)