Merge remote-tracking branch 'origin/master'

# Conflicts:
#	backend/app_be/views/twitter.py
This commit is contained in:
Tobias Eidelpes 2021-05-02 17:50:37 +02:00
commit 92366179a2

View File

@ -1,9 +1,10 @@
import twitter import twitter
import os import os
import sched, time import sched, time, datetime
import asyncio
s = sched.scheduler(time.time(), time.sleep) import sys
from app_be.models import Tweet
from dotenv import load_dotenv from dotenv import load_dotenv
load_dotenv() load_dotenv()
@ -22,11 +23,13 @@ class twitter_api:
@staticmethod @staticmethod
def get_last_six_tweets(): def get_last_six_tweets():
print(api.GetUserTimeline(screen_name='WAECMG4', count=6)) last_six = Tweet.objects.all().order_by('-id')[:6]
print(last_six)
@staticmethod @staticmethod
def get_last_twelve_tweets(): def get_last_twelve_tweets():
print(api.GetUserTimeline(screen_name='WAECMG4', count=12)) last_twelve = Tweet.objects.all().order_by('-id')[:12]
print(last_twelve)
@staticmethod @staticmethod
def post_update(text, url): def post_update(text, url):
@ -37,13 +40,29 @@ class twitter_api:
class twitter_bot: class twitter_bot:
def scan_active_feed(self): def scan_active_feed(self):
starttime = time.time() starttime = time.time()
# while True: while True:
# Search RSS Feed # Search RSS Feeds TODO: for looping over feeds
print("Looking for new results in active feeds")
# time.sleep(60.0 - ((time.time() - starttime) % 60.0)) new_tweet = Tweet()
new_tweet.icon = None
new_tweet.text = "Test 1"
new_tweet.date_time = datetime.datetime.now()
new_tweet.url = "www.google.com"
# if tweet not in db yet
if Tweet.objects.filter(text=new_tweet.text) == []:
# call twitter api to post tweet and store to db
print("Posting update on Twitter")
twitter_api.post_update(new_tweet.text, new_tweet.url)
new_tweet.save()
time.sleep(60.0 - ((time.time() - starttime) % 60.0))
if 'runserver' in sys.argv:
twitter_bot = twitter_bot() twitter_bot = twitter_bot()
twitter_bot.scan_active_feed() twitter_bot.scan_active_feed()