कैसे स्थापित करने के लिए एक crontab के साथ html अनुरोध का उपयोग कर फ्लास्क-crontab?

0

सवाल

मैं करना चाहते हैं चलाने के लिए एक html पृष्ठ जहाँ मैं एक बटन का उपयोग करने के लिए एक विशिष्ट समय सेट (नीचे देखें), जो बाद में चलाता है एक cronjob के माध्यम से मॉड्यूल फ्लास्क-crontab. कैसे मैं उपयोग कर सकते हैं minute, hour, day, month बाहर def get_time() बिना सेटिंग चर वैश्विक?
क्या एक ठोस तरीका का उपयोग करने के लिए फ्लास्क-crontab यहाँ?

APP = Flask(__name__)
Bootstrap(APP)
crontab = Crontab(APP)

...

@APP.route('/randompage.html' methods = ['POST', 'GET])
def get_time():
    time_req = request.args.get("html_time")
    format_time = datetime.strptime(time_req, "%Y-%m-%dT%H:%M")

    minute = format_time.minute
    hour = format_time.hour
    day = format_time.day
    month = fomrat_time.month

    return render_template('randompage.html', time_req=time_req)


@crontab.job()
def exe_control():
    do something here

बटन पर html-पेज:

<form action="/randompage.html" method="GET">
<input type="datetime-local" name="html_time"/>
<input type="submit"/></form>
cron flask html linux
2021-11-13 12:05:37
1

सबसे अच्छा जवाब

0

का उपयोग करने के लिए मूल्यों minute, hour, day, month अन्य कार्यों में आप का उपयोग करने के लिए global चर या रखने में वैश्विक list/dictionary या बचाने में file/डेटाबेस` और पढ़ने में अन्य कार्यों ।

लेकिन अगर आप चाहते हैं इन मूल्यों का उपयोग करने के लिए के रूप में मूल्यों में @crontab.job(minute=..., hour=...) तो यह बेकार है. आप इसे चलाने के लिए चाहिए में सीधे get_time के रूप में सामान्य कार्य

crontab.job(minute=minute, ...)(exe_control)


APP = Flask(__name__)
Bootstrap(APP)
crontab = Crontab(APP)

# ...

@APP.route('/randompage.html' methods = ['POST', 'GET'])
def get_time():
    time_req = request.args.get("html_time")
    format_time = datetime.strptime(time_req, "%Y-%m-%dT%H:%M")

    minute = format_time.minute
    hour = format_time.hour
    day = format_time.day
    month = fomrat_time.month

    crontab.job(minute=minute, hour=hour, day=day, month=month)(exe_control)

    return render_template('randompage.html', time_req=time_req)

# - without decorator -
def exe_control():
    do something here
2021-11-14 00:00:27

अन्य भाषाओं में

यह पृष्ठ अन्य भाषाओं में है

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................

इस श्रेणी में लोकप्रिय

लोकप्रिय सवाल इस श्रेणी में