[twitter] Move twitter config options to subpoint twitter

This commit is contained in:
Cathy Hu 2020-07-08 13:22:53 +02:00 committed by acipm
parent 8af6205146
commit 66684c2fea
2 changed files with 10 additions and 11 deletions

View file

@ -17,13 +17,12 @@ class TwitterBot(Censor):
def __init__(self, twitter_model):
super().__init__(twitter_model.hood)
self.twitter_model = twitter_model
self.tokens = {
'consumer_key': config['twitter_consumer_key'],
'consumer_secret': config['twitter_consumer_secret'],
'access_token': twitter_model.access_token,
'access_token_secret': twitter_model.access_token_secret,
}
self.client = PeonyClient(**self.tokens)
self.client = PeonyClient(
consumer_key=config['twitter']['consumer_key'],
consumer_secret=config['twitter']['consumer_secret'],
access_token=twitter_model.access_token,
access_token_secret=twitter_model.access_token_secret,
)
self.polling_interval_sec = 60
self.mentions_since_id = self.twitter_model.mentions_since_id
self.dms_since_id = self.twitter_model.dms_since_id

View file

@ -47,8 +47,8 @@ async def twitter_delete(twitter=Depends(get_twitter)):
async def twitter_create(response: Response, hood=Depends(get_hood)):
try:
request_token = await get_oauth_token(
config['twitter_consumer_key'],
config['twitter_consumer_secret'],
config['twitter']['consumer_key'],
config['twitter']['consumer_secret'],
callback_uri='http://127.0.0.1:8000/api/twitter/callback',
)
if request_token['oauth_callback_confirmed'] != 'true':
@ -69,8 +69,8 @@ async def twitter_read_callback(oauth_token: str, oauth_verifier: str):
try:
twitter = await Twitter.objects.filter(access_token=oauth_token).get()
access_token = await get_access_token(
config['twitter_consumer_key'],
config['twitter_consumer_secret'],
config['twitter']['consumer_key'],
config['twitter']['consumer_secret'],
twitter.access_token,
twitter.access_token_secret,
oauth_verifier,