From b15ae3fcc65b47a92b6248241348170e0451e7d9 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Sat, 18 Feb 2017 20:44:30 +0100 Subject: [PATCH] Preparation for using different accounts for different stuff --- setuptools/__init__.py | 20 ++++++++++++++++---- twitools/__init__.py | 21 +++++++++++++-------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/setuptools/__init__.py b/setuptools/__init__.py index c432018..143c337 100644 --- a/setuptools/__init__.py +++ b/setuptools/__init__.py @@ -1,5 +1,9 @@ import configparser, csv, datetime, html.parser, itertools, os, sqlite3, sys, tweepy +TWITTER = 0 +MARKOV = 1 +LYRICS = 2 + class SetupException(Exception): def __str__(self): return "Seems like config.cfg has not been created yet or contains serious errors. Run setup.py to create it." @@ -50,6 +54,14 @@ def dbpath(): ### +def sectionName(section): + if section == TWITTER: + return "Twitter" + elif section == MARKOV: + return "Markov" + elif section == LYRICS: + return "Lyrics" + def cke(): try: return getSetting("Twitter", "cke") @@ -62,15 +74,15 @@ def cse(): except: raise SetupException() -def ato(): +def ato(section = TWITTER): try: - return getSetting("Twitter", "ato") + return getSetting(sectionName(section), "ato") except: raise SetupException() -def ase(): +def ase(section = TWITTER): try: - return getSetting("Twitter", "ase") + return getSetting(sectionName(section), "ase") except: raise SetupException() diff --git a/twitools/__init__.py b/twitools/__init__.py index f69ef2b..2e5dc80 100644 --- a/twitools/__init__.py +++ b/twitools/__init__.py @@ -24,21 +24,26 @@ class twObject: def tweet(self, text, reply = 0): return self.api.update_status(text, reply) -def getFollowerIDs(two=twObject()): +def getFollowerIDs(section = setuptools.TWITTER): ''' Returns 5,000 follower IDs at most ''' - for id in list(two.api.followers_ids(screen_name=twObject().whoami())): + for id in list(twoHelper(section).api.followers_ids(screen_name=twObject().whoami())): yield int(id) -def getFollowingIDs(two=twObject()): - for id in list(two.api.friends_ids(screen_name=twObject().whoami())): +def getFollowingIDs(section = setuptools.TWITTER): + for id in list(twoHelper(section).api.friends_ids(screen_name=twObject().whoami())): yield int(id) -def getNameByID(uid, two=twObject()): - return two.api.get_user(uid).screen_name +def getNameByID(uid, section = setuptools.TWITTER): + return twoHelper(section).api.get_user(uid).screen_name -def getNamesByIDs(fids=getFollowerIDs(), two=twObject()): +def getNamesByIDs(fids=getFollowerIDs(), section = setuptools.TWITTER): for page in setuptools.paginate(fids, 100): - followers = two.api.lookup_users(user_ids=page) + followers = twoHelper(section).api.lookup_users(user_ids=page) for follower in followers: yield {"id": follower.id, "name": follower.screen_name} +def twoHelper(section = setuptools.TWITTER): + try: + return twObject(ato = setuptools.ato(section), ase = setuptools.ase(section)) + except: + return twObject()