Stream slots system and no double commissions
This commit is contained in:
parent
954d231d6d
commit
95c70b0b48
3 changed files with 16 additions and 4 deletions
|
@ -41,6 +41,12 @@ class Tweets(db.Model):
|
||||||
slots = db.Column(db.Integer)
|
slots = db.Column(db.Integer)
|
||||||
slots_max = db.Column(db.Integer)
|
slots_max = db.Column(db.Integer)
|
||||||
keywords = db.Column(db.String(256))
|
keywords = db.Column(db.String(256))
|
||||||
|
commissions = db.relationship("Commission", backref="tweet", lazy="dynamic")
|
||||||
|
|
||||||
|
class Commission(db.Model):
|
||||||
|
id = db.Column(db.Integer, primary_key=True, unique=True)
|
||||||
|
tweet_id = db.Column(db.Integer, db.ForeignKey("tweets.id"))
|
||||||
|
user = db.Column(db.String(15))
|
||||||
|
|
||||||
class TrelloAPI(db.Model):
|
class TrelloAPI(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True, unique=True)
|
id = db.Column(db.Integer, primary_key=True, unique=True)
|
||||||
|
|
|
@ -111,7 +111,10 @@ def dashboard():
|
||||||
twapi = twapi.api_login()
|
twapi = twapi.api_login()
|
||||||
|
|
||||||
if request.args.get("twrm"):
|
if request.args.get("twrm"):
|
||||||
db.session.delete(Tweets.query.filter_by(user = current_user, statu_id = request.args.get("twrm")).first())
|
t = Tweets.query.filter_by(user = current_user, statu_id = request.args.get("twrm")).first()
|
||||||
|
for c in t.commissions.all():
|
||||||
|
db.session.delete(c)
|
||||||
|
db.session.delete(t)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
if request.args.get("delet"):
|
if request.args.get("delet"):
|
||||||
twapi.destroy_status(request.args.get["twrm"])
|
twapi.destroy_status(request.args.get["twrm"])
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import tweepy, twitter_credentials, trello, trello_credentials, json, subprocess, argparse
|
import tweepy, twitter_credentials, trello, trello_credentials, json, subprocess, argparse
|
||||||
from app import db
|
from app import db
|
||||||
from app.models import User
|
from app.models import User, Commission
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("user", type = int, help = "User id")
|
parser.add_argument("user", type = int, help = "User id")
|
||||||
|
@ -13,15 +13,18 @@ api = tweepy.API(auth)
|
||||||
|
|
||||||
class listener(tweepy.streaming.StreamListener):
|
class listener(tweepy.streaming.StreamListener):
|
||||||
def on_data(self, data):
|
def on_data(self, data):
|
||||||
|
print(data)
|
||||||
all_data = json.loads(data)
|
all_data = json.loads(data)
|
||||||
for t in user.tweets.all():
|
for t in user.tweets.all():
|
||||||
if t.statu_id == int(all_data["in_reply_to_status_id"]) and api.me().id != int(all_data["user"]["id"]):
|
if "in_reply_to_status_id" in all_data and all_data["in_reply_to_status_id"] and t.statu_id == int(all_data["in_reply_to_status_id"]) and t.slots != t.slots_max and not t.commissions.filter_by(user = all_data["user"]["screen_name"]).first(): #and api.me().id != int(all_data["user"]["id"])
|
||||||
for w in eval(t.keywords.lower()):
|
for w in eval(t.keywords.lower()):
|
||||||
if all_data["text"].lower().find(w) != -1:
|
if all_data["text"].lower().find(w) != -1:
|
||||||
|
t.slots += 1
|
||||||
|
db.session.add(Commission(tweet = t, user = all_data["user"]["screen_name"]))
|
||||||
|
db.session.commit()
|
||||||
api.create_favorite(int(all_data["id"]))
|
api.create_favorite(int(all_data["id"]))
|
||||||
user.trello_api.first().api_login().get_list(user.boards.first().column_id).add_card(f"{all_data['user']['name']}'s commission", f"Commission take on Twitter with the cyberplanificateur with this tweet : https://twitter.com/{all_data['user']['screen_name']}/status/{all_data['id']}")
|
user.trello_api.first().api_login().get_list(user.boards.first().column_id).add_card(f"{all_data['user']['name']}'s commission", f"Commission take on Twitter with the cyberplanificateur with this tweet : https://twitter.com/{all_data['user']['screen_name']}/status/{all_data['id']}")
|
||||||
print("found")
|
print("found")
|
||||||
#Make slots system !
|
|
||||||
break
|
break
|
||||||
break
|
break
|
||||||
return True
|
return True
|
||||||
|
|
Reference in a new issue