2021-05-03 22:06:57 +02:00

44 lines
1.1 KiB
Python

import twitter
import os
from app_be.models import Tweet
from dotenv import load_dotenv
load_dotenv()
api = twitter.Api(consumer_key=os.getenv('TWITTER_API_KEY'),
consumer_secret=os.getenv('TWITTER_API_SECRET'),
access_token_key=os.getenv('TWITTER_ACCESS_TOKEN'),
access_token_secret=os.getenv('TWITTER_ACCESS_TOKEN_SECRET'))
class twitter_api:
@staticmethod
def check_credentials():
print(api.VerifyCredentials())
@staticmethod
def get_last_six_tweets():
last_six = api.GetUserTimeline('waecmg4',count=6)
print(last_six)
@staticmethod
def get_last_twelve_tweets():
last_twelve = api.GetUserTimeline('waecmg4',count=12)
print(last_twelve)
@staticmethod
def get_last_n_tweets(n):
last_twelve = api.GetUserTimeline('waecmg4',count=n)
print(last_twelve)
@staticmethod
def post_update(text, url):
tweet = text + ": " + url
if len(text) > 140:
surplus = len(text) - 140
tweet = text[:len(text) - (surplus + 3)] + "...: " + url
api.PostUpdate(tweet)