From 4e56067d8243f5143f4aa3a4a544a13d3cdab436 Mon Sep 17 00:00:00 2001 From: Paal Braathen Date: Fri, 9 Sep 2016 15:42:27 +0200 Subject: [PATCH] Unfuck tweetorator --- tweetorator.py | 66 +++++++++++++++++++++----------------------------- 1 file changed, 28 insertions(+), 38 deletions(-) diff --git a/tweetorator.py b/tweetorator.py index 240eb96..43f2e7e 100755 --- a/tweetorator.py +++ b/tweetorator.py @@ -1,5 +1,6 @@ #!/usr/bin/env python #coding: utf-8 +import ConfigParser import sys import twitter import logging @@ -19,19 +20,18 @@ initialized = False def init(): global _api -# TWITTER IS FUCKED. paalbra 2016-06-08 -# cfg = ConfigParser.RawConfigParser() -# cfg.read("tweetorator.cfg") -# consumer_key = cfg.get("twitter", "consumer_key") -# consumer_secret = cfg.get("twitter", "consumer_secret") -# access_token_key = cfg.get("twitter", "access_token_key") -# access_token_secret = cfg.get("twitter", "access_token_secret") -# _api = twitter.Api(consumer_key = consumer_key, -# consumer_secret = consumer_secret, -# access_token_key = access_token_key, -# access_token_secret = access_token_secret) -# -# logging.debug("VerifyCredentials: %s" % _api.VerifyCredentials()) + cfg = ConfigParser.RawConfigParser() + cfg.read("tweetorator.cfg") + consumer_key = cfg.get("twitter", "consumer_key") + consumer_secret = cfg.get("twitter", "consumer_secret") + access_token_key = cfg.get("twitter", "access_token_key") + access_token_secret = cfg.get("twitter", "access_token_secret") + _api = twitter.Api(consumer_key = consumer_key, + consumer_secret = consumer_secret, + access_token_key = access_token_key, + access_token_secret = access_token_secret) + + logging.debug("VerifyCredentials: %s" % _api.VerifyCredentials()) tldb.loadCfg('tldb.cfg') @@ -46,28 +46,18 @@ def post_confession(text): if not initialized: init() -## UNFUCK START - logging.info("Adding unfucked confession") - try: - tldb.addConfession(text) - except: - logging.error("%s, 0, text was >>%s<<" % (sys.exc_info()[0], text)) - pass -## UNFUCK END - -# THIS IS FUCKED BEFAUSE TWITTER IS FUCKED. paalbra 2016-06-08 -# if len(text) > 140: -# logging.info("Adding confession longer than 140") -# try: -# tldb.addConfession(text) -# except: -# logging.error("%s, 1, text was >>%s<<" % (sys.exc_info()[0], text)) -# pass -# else: -# logging.info("Adding confession shorter than 140") -# try: -# status = _api.PostUpdate(text) -# tldb.addConfession(text, status.AsJsonString()) -# except: -# logging.error("%s, 2, text was >>%s<<" % (sys.exc_info()[0], text)) -# pass + if len(text) > 140: + logging.info("Adding confession longer than 140") + try: + tldb.addConfession(text) + except: + logging.error("%s, 1, text was >>%s<<" % (sys.exc_info()[0], text)) + pass + else: + logging.info("Adding confession shorter than 140") + try: + status = _api.PostUpdate(text) + tldb.addConfession(text, status.AsJsonString()) + except: + logging.error("%s, 2, text was >>%s<<" % (sys.exc_info()[0], text)) + pass