from flask import *
from redmine import Redmine
import sys
app = Flask(__name__)
REDMINE_KEY='sdfsdfsdfsdfsd'
REDMINE_URL='http://blabla/redmine'
redmine = Redmine(REDMINE_URL)
redmine = Redmine(REDMINE_URL, key=REDMINE_KEY)
neu = []
bearbeitung = []
erledigt = []
id_thema = ""
thema = ""
project = ""
zugewiesen = ""
def ticket_zugewiesen(diesTicket):
alleticket = redmine.issue.get(diesTicket)
try:
alleticket.assigned_to
except:
return True
def ticket_infos(diesTicket):
alleticket = redmine.issue.get(diesTicket)
try:
id_thema = alleticket.id
thema = alleticket.subject
project = alleticket.project.name
zugewiesen = alleticket.assigned_to
except:
id_thema = alleticket.id
thema = alleticket.subject
project = alleticket.project.name
return
neueIssues = redmine.issue.filter(status_id='1')
for i in neueIssues:
neu.append(i.id)
neueIssues = redmine.issue.filter(status_id='2')
for i in neueIssues:
bearbeitung.append(i.id)
neueIssues = redmine.issue.filter(status_id='5')
for i in neueIssues:
erledigt.append(i.id)
@app.route('/_sendinfo')
def info():
return jsonify(result=id_thema,thema=thema, project=project, zugewiesen=zugewiesen)
@app.route('/')
def home():
while True:
neu2 = []
bearbeitung2 = []
erledigt2 = []
neueIssues = redmine.issue.filter(status_id='1')
for neues in neueIssues:
neu2.append(neues.id)
neueIssues = redmine.issue.filter(status_id='2')
for bearbeitetes in neueIssues:
bearbeitung2.append(bearbeitetes.id)
neueIssues = redmine.issue.filter(status_id='5')
for erledigtes in neueIssues:
erledigt2.append(erledigtes.id)
for i in neu2:
if i not in neu:
janein = ticket_zugewiesen(i)
if janein is True:
l = ticket_infos(i)
else:
pass
neu = neu2
for ii in bearbeitung2:
if ii not in bearbeitung:
if ii in erledigt:
l = ticket_infos(ii)
erledigt = erledigt2
bearbeitung = bearbeitung2
for iii in erledigt2:
if iii not in erledigt:
l = ticket_infos(iii)
erledigt = erledigt2
return render_template("index.html")
if __name__ == '__main__':
app.run()
如何在home()
瓶中进行无限循环?
现在它不起作用。
或者有更好的方法从redmine获取数据吗?
我将检查每一轮,无限循环,如果三个列表neu2,bearbeitung2,erledigt2等于neu,bearbeitung,erledigt。如果" list2"我将动态地在前端(浏览器)上显示一些信息。
答案 0 :(得分:0)
如果我理解正确,您希望继续从单个Flask路线推送更新到浏览器。可悲的是,这是不可能的。您将需要研究使用浏览器端JavaScript和使用AJAX轮询,或者使用websockets来推送实时更新。
AJAX和WS之间的选择取决于您的具体用例。试着看看两者。 AJAX可能更容易设置,但据我所知,Flask有一些WS支持:https://github.com/miguelgrinberg/Flask-SocketIO
编辑:如果您不需要支持旧浏览器,您也可以尝试使用服务器发送事件(尽管似乎还有polyfill,它们也支持旧浏览器)。他们在这里得到了很好的解释:How to implement server push in Flask framework?并且看起来很容易使用,尽管我从未亲自尝试过。
答案 1 :(得分:0)
我不知道这是否是个好主意,但我解决了。
from concurrent.futures import ThreadPoolExecutor
executor = ThreadPoolExecutor(1) # number of executor
executor.submit(home)
from concurrent.futures import ThreadPoolExecutor
from flask import *
from redmine import Redmine
import sys
app = Flask(__name__)
REDMINE_KEY='sdfsdfsdfsdfsd'
REDMINE_URL='http://blabla/redmine'
redmine = Redmine(REDMINE_URL)
redmine = Redmine(REDMINE_URL, key=REDMINE_KEY)
neu = []
bearbeitung = []
erledigt = []
id_thema = ""
thema = ""
project = ""
zugewiesen = ""
def ticket_zugewiesen(diesTicket):
alleticket = redmine.issue.get(diesTicket)
try:
alleticket.assigned_to
except:
return True
def ticket_infos(diesTicket):
alleticket = redmine.issue.get(diesTicket)
try:
id_thema = alleticket.id
thema = alleticket.subject
project = alleticket.project.name
zugewiesen = alleticket.assigned_to
except:
id_thema = alleticket.id
thema = alleticket.subject
project = alleticket.project.name
return
neueIssues = redmine.issue.filter(status_id='1')
for i in neueIssues:
neu.append(i.id)
neueIssues = redmine.issue.filter(status_id='2')
for i in neueIssues:
bearbeitung.append(i.id)
neueIssues = redmine.issue.filter(status_id='5')
for i in neueIssues:
erledigt.append(i.id)
@app.route('/_sendinfo')
def info():
return jsonify(result=id_thema,thema=thema, project=project, zugewiesen=zugewiesen)
executor = ThreadPoolExecutor(1) # number of executor
def home():
while True:
neu2 = []
bearbeitung2 = []
erledigt2 = []
neueIssues = redmine.issue.filter(status_id='1')
for neues in neueIssues:
neu2.append(neues.id)
neueIssues = redmine.issue.filter(status_id='2')
for bearbeitetes in neueIssues:
bearbeitung2.append(bearbeitetes.id)
neueIssues = redmine.issue.filter(status_id='5')
for erledigtes in neueIssues:
erledigt2.append(erledigtes.id)
for i in neu2:
if i not in neu:
janein = ticket_zugewiesen(i)
if janein is True:
l = ticket_infos(i)
else:
pass
neu = neu2
for ii in bearbeitung2:
if ii not in bearbeitung:
if ii in erledigt:
l = ticket_infos(ii)
erledigt = erledigt2
bearbeitung = bearbeitung2
for iii in erledigt2:
if iii not in erledigt:
l = ticket_infos(iii)
erledigt = erledigt2
return render_template("index.html")
if __name__ == '__main__':
executor.submit(home)
app.run()