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 afafe51188
commit b15ae3fcc6
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
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()

View file

@ -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()