Preparation for using different accounts for different stuff

This commit is contained in:
Klaus-Uwe Mitterer 2017-02-18 20:44:30 +01:00
parent f92405092d
commit 88f8792478
2 changed files with 29 additions and 12 deletions

View file

@ -1,5 +1,9 @@
import configparser, csv, datetime, html.parser, itertools, os, sqlite3, sys, tweepy import configparser, csv, datetime, html.parser, itertools, os, sqlite3, sys, tweepy
TWITTER = 0
MARKOV = 1
LYRICS = 2
class SetupException(Exception): class SetupException(Exception):
def __str__(self): def __str__(self):
return "Seems like config.cfg has not been created yet or contains serious errors. Run setup.py to create it." 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(): def cke():
try: try:
return getSetting("Twitter", "cke") return getSetting("Twitter", "cke")
@ -62,15 +74,15 @@ def cse():
except: except:
raise SetupException() raise SetupException()
def ato(): def ato(section = TWITTER):
try: try:
return getSetting("Twitter", "ato") return getSetting(sectionName(section), "ato")
except: except:
raise SetupException() raise SetupException()
def ase(): def ase(section = TWITTER):
try: try:
return getSetting("Twitter", "ase") return getSetting(sectionName(section), "ase")
except: except:
raise SetupException() raise SetupException()

View file

@ -24,21 +24,26 @@ class twObject:
def tweet(self, text, reply = 0): def tweet(self, text, reply = 0):
return self.api.update_status(text, reply) return self.api.update_status(text, reply)
def getFollowerIDs(two=twObject()): def getFollowerIDs(section = setuptools.TWITTER):
''' Returns 5,000 follower IDs at most ''' ''' 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) yield int(id)
def getFollowingIDs(two=twObject()): def getFollowingIDs(section = setuptools.TWITTER):
for id in list(two.api.friends_ids(screen_name=twObject().whoami())): for id in list(twoHelper(section).api.friends_ids(screen_name=twObject().whoami())):
yield int(id) yield int(id)
def getNameByID(uid, two=twObject()): def getNameByID(uid, section = setuptools.TWITTER):
return two.api.get_user(uid).screen_name 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): 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: for follower in followers:
yield {"id": follower.id, "name": follower.screen_name} 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()