twitter bot ctd.
This commit is contained in:
parent
4cdc59af9a
commit
2442b1326f
@ -1,5 +1,6 @@
|
||||
from django.contrib import admin
|
||||
from app_be.models import Tweet
|
||||
from app_be.models import Tweet, Feed
|
||||
|
||||
# Register your models here.
|
||||
admin.site.register(Tweet)
|
||||
admin.site.register(Feed)
|
||||
@ -1,3 +1,5 @@
|
||||
import sys
|
||||
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
@ -6,6 +8,7 @@ class AppBeConfig(AppConfig):
|
||||
|
||||
def ready(self):
|
||||
|
||||
if 'runserver' in sys.argv:
|
||||
from app_be.views.twitter_bot import twitter_bot
|
||||
twitter_bot1 = twitter_bot()
|
||||
twitter_bot1.start()
|
||||
|
||||
@ -2,8 +2,9 @@ import threading
|
||||
from datetime import datetime
|
||||
import time
|
||||
|
||||
from app_be.models import Tweet
|
||||
from app_be.models import Tweet, Feed
|
||||
from app_be.views.twitter_api import twitter_api
|
||||
from feedsearch import search
|
||||
|
||||
|
||||
class twitter_bot(threading.Thread):
|
||||
@ -12,21 +13,48 @@ class twitter_bot(threading.Thread):
|
||||
threading.Thread.__init__(self)
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
# Search RSS Feeds TODO: for looping over feeds
|
||||
print("Looking for new results in active feeds")
|
||||
|
||||
posted = False
|
||||
|
||||
while True:
|
||||
|
||||
print("Looking for new results in active feeds")
|
||||
feed_set = Feed.objects.filter(active=True)
|
||||
|
||||
for feed in feed_set:
|
||||
if posted:
|
||||
break
|
||||
|
||||
#load feed
|
||||
feeds = search(feed.url)
|
||||
|
||||
#search single posts
|
||||
for current in feeds:
|
||||
print(current)
|
||||
|
||||
#TODO: split keywords and search
|
||||
#looking for keywords
|
||||
if feed.keywords in current.title:
|
||||
if posted:
|
||||
break
|
||||
|
||||
#preparing tweet
|
||||
new_tweet = Tweet()
|
||||
new_tweet.icon = None
|
||||
new_tweet.text = "Test 2"
|
||||
new_tweet.text = current.title
|
||||
new_tweet.date_time = datetime.now()
|
||||
new_tweet.url = "www.google.com"
|
||||
new_tweet.url = current.url
|
||||
|
||||
# if tweet not in db yet
|
||||
if Tweet.objects.filter(text=new_tweet.text) == []:
|
||||
if not 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)
|
||||
print(new_tweet)
|
||||
|
||||
#TODO: uncomment
|
||||
#twitter_api.post_update(new_tweet.text, new_tweet.url)
|
||||
new_tweet.save()
|
||||
posted = True
|
||||
|
||||
time.sleep(60)
|
||||
posted = False
|
||||
|
||||
@ -19,6 +19,7 @@ setup(name='waecm-2021-group-04',
|
||||
'py-jwt-validator==0.6.0',
|
||||
'python-twitter==3.5',
|
||||
'python-dotenv==0.17.1',
|
||||
'feedsearch==1.0.12',
|
||||
],
|
||||
license='BSD License', # example license
|
||||
description='DESCRIPTION')
|
||||
|
||||
27
frontend/package-lock.json
generated
27
frontend/package-lock.json
generated
@ -432,6 +432,9 @@
|
||||
"version": "9.2.4",
|
||||
"resolved": "https://registry.npmjs.org/@angular/cdk/-/cdk-9.2.4.tgz",
|
||||
"integrity": "sha512-iw2+qHMXHYVC6K/fttHeNHIieSKiTEodVutZoOEcBu9rmRTGbLB26V/CRsfIRmA1RBk+uFYWc6UQZnMC3RdnJQ==",
|
||||
"dependencies": {
|
||||
"parse5": "^5.0.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"parse5": "^5.0.0"
|
||||
}
|
||||
@ -967,6 +970,7 @@
|
||||
"dependencies": {
|
||||
"anymatch": "~3.1.1",
|
||||
"braces": "~3.0.2",
|
||||
"fsevents": "~2.1.2",
|
||||
"glob-parent": "~5.1.0",
|
||||
"is-binary-path": "~2.1.0",
|
||||
"is-glob": "~4.0.1",
|
||||
@ -2146,6 +2150,7 @@
|
||||
"dependencies": {
|
||||
"anymatch": "~3.1.1",
|
||||
"braces": "~3.0.2",
|
||||
"fsevents": "~2.1.2",
|
||||
"glob-parent": "~5.1.0",
|
||||
"is-binary-path": "~2.1.0",
|
||||
"is-glob": "~4.0.1",
|
||||
@ -3698,7 +3703,8 @@
|
||||
"dependencies": {
|
||||
"esprima": "~1.0.4",
|
||||
"estraverse": "~1.5.0",
|
||||
"esutils": "~1.0.0"
|
||||
"esutils": "~1.0.0",
|
||||
"source-map": "~0.1.30"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"source-map": "~0.1.30"
|
||||
@ -6537,7 +6543,8 @@
|
||||
"esprima": "^4.0.1",
|
||||
"estraverse": "^4.2.0",
|
||||
"esutils": "^2.0.2",
|
||||
"optionator": "^0.8.1"
|
||||
"optionator": "^0.8.1",
|
||||
"source-map": "~0.6.1"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"source-map": "~0.6.1"
|
||||
@ -7553,6 +7560,7 @@
|
||||
"minimist": "^1.2.5",
|
||||
"neo-async": "^2.6.0",
|
||||
"source-map": "^0.6.1",
|
||||
"uglify-js": "^3.1.4",
|
||||
"wordwrap": "^1.0.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
@ -9272,6 +9280,7 @@
|
||||
"dependencies": {
|
||||
"anymatch": "~3.1.1",
|
||||
"braces": "~3.0.2",
|
||||
"fsevents": "~2.1.2",
|
||||
"glob-parent": "~5.1.0",
|
||||
"is-binary-path": "~2.1.0",
|
||||
"is-glob": "~4.0.1",
|
||||
@ -9411,8 +9420,12 @@
|
||||
"clone": "^2.1.2",
|
||||
"errno": "^0.1.1",
|
||||
"graceful-fs": "^4.1.2",
|
||||
"image-size": "~0.5.0",
|
||||
"make-dir": "^2.1.0",
|
||||
"mime": "^1.4.1",
|
||||
"promise": "^7.1.1",
|
||||
"request": "^2.83.0",
|
||||
"source-map": "~0.6.0",
|
||||
"tslib": "^1.10.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
@ -9632,6 +9645,7 @@
|
||||
"anymatch": "^2.0.0",
|
||||
"async-each": "^1.0.1",
|
||||
"braces": "^2.3.2",
|
||||
"fsevents": "^1.2.7",
|
||||
"glob-parent": "^3.1.0",
|
||||
"inherits": "^2.0.3",
|
||||
"is-binary-path": "^1.0.0",
|
||||
@ -13626,6 +13640,9 @@
|
||||
"resolved": "https://registry.npmjs.org/rollup/-/rollup-2.1.0.tgz",
|
||||
"integrity": "sha512-gfE1455AEazVVTJoeQtcOq/U6GSxwoj4XPSWVsuWmgIxj7sBQNLDOSA82PbdMe+cP8ql8fR1jogPFe8Wg8g4SQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"fsevents": "~2.1.2"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"fsevents": "~2.1.2"
|
||||
}
|
||||
@ -13772,6 +13789,7 @@
|
||||
"dependencies": {
|
||||
"anymatch": "~3.1.1",
|
||||
"braces": "~3.0.2",
|
||||
"fsevents": "~2.1.2",
|
||||
"glob-parent": "~5.1.0",
|
||||
"is-binary-path": "~2.1.0",
|
||||
"is-glob": "~4.0.1",
|
||||
@ -16514,8 +16532,10 @@
|
||||
"integrity": "sha512-aWAgTW4MoSJzZPAicljkO1hsi1oKj/RRq/OJQh2PKI2UKL04c2Bs+MBOB+BBABHTXJpf9mCwHN7ANCvYsvY2sg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"chokidar": "^3.4.1",
|
||||
"graceful-fs": "^4.1.2",
|
||||
"neo-async": "^2.5.0"
|
||||
"neo-async": "^2.5.0",
|
||||
"watchpack-chokidar2": "^2.0.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"chokidar": "^3.4.1",
|
||||
@ -17221,6 +17241,7 @@
|
||||
"anymatch": "^2.0.0",
|
||||
"async-each": "^1.0.1",
|
||||
"braces": "^2.3.2",
|
||||
"fsevents": "^1.2.7",
|
||||
"glob-parent": "^3.1.0",
|
||||
"inherits": "^2.0.3",
|
||||
"is-binary-path": "^1.0.0",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user