Twitter API + Bot start
This commit is contained in:
@@ -50,3 +50,9 @@ class LoginClass:
|
||||
return JsonResponse({}, status=401)
|
||||
|
||||
return JsonResponse({'user': user_sub}, safe=False, status=200)
|
||||
|
||||
class TwitterClass:
|
||||
@staticmethod
|
||||
@api_view(['GET'])
|
||||
def getLastSixTweets():
|
||||
return JsonResponse({[{"asdf","asdf","sdfasdf","asdf"},{"asdf","asdf","sdfasdf","asdf"}]}, safe=False, status=200)
|
||||
@@ -0,0 +1,50 @@
|
||||
import twitter
|
||||
import os
|
||||
import sched, time
|
||||
|
||||
s = sched.scheduler(time.time(), time.sleep)
|
||||
|
||||
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():
|
||||
print(api.GetUserTimeline(screen_name='WAECMG4', count=6))
|
||||
|
||||
@staticmethod
|
||||
def get_last_twelve_tweets():
|
||||
print(api.GetUserTimeline(screen_name='WAECMG4', count=12))
|
||||
|
||||
@staticmethod
|
||||
def post_update(text, url):
|
||||
update = text + ": " + url
|
||||
api.PostUpdate(update)
|
||||
|
||||
|
||||
class twitter_bot:
|
||||
|
||||
def scan_active_feed(self):
|
||||
starttime = time.time()
|
||||
|
||||
while True:
|
||||
# Search RSS Feed
|
||||
|
||||
|
||||
time.sleep(60.0 - ((time.time() - starttime) % 60.0))
|
||||
|
||||
|
||||
twitter_bot = twitter_bot()
|
||||
twitter_bot.scan_active_feed()
|
||||
Reference in New Issue
Block a user