From b0f6f1a14cd10252670b85e9ca67bb377ad53e72 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Tue, 21 Feb 2017 22:22:44 +0100 Subject: [PATCH] Allow Markov bot to tweet exactly at 0/15/30/45 --- markov.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/markov.py b/markov.py index 3c9081f..f15f387 100755 --- a/markov.py +++ b/markov.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import dbtools, setuptools, twitools -import argparse, html, markovify, nltk, operator, os, random, re, string, sys +import argparse, datetime, html, markovify, nltk, operator, os, random, re, string, sys, time class Possy(markovify.NewlineText): def word_split(self, sentence): @@ -36,6 +36,16 @@ def getText(db = dbtools.dbHelper()): def markovifyText(text): return Possy(text).make_short_sentence(130).replace("@", "@​") +def getTime(): + now = datetime.datetime.now() + + thenminute = 15 if now.minute < 15 else 30 if now.minute < 30 else 45 if now.minute < 45 else 0 + thenhour = now.hour + 1 if thenminute == 0 else now.hour + + then = datetime.datetime(now.year, now.month, now.day, thenhour, thenminute, 0) + return (then - now).seconds + if __name__ == "__main__": os.nice(5) + time.sleep(getTime()) twitools.tweet(markovifyText(getText()), section = setuptools.MARKOV)