私はこれがスロピーであることを知っています。私は初心者ですが、これを行うにはより良い方法があります。あなたのコードの最初の数行を見てみるとこのスクリプトをPythonで書くよりよい方法がありますか?
#!/usr/bin/env python
"""
Script to send any pending alerts via email
"""
import sys
from pymongo import MongoClient
from datetime import datetime
#### begin
def send_email():
print "Begin GAMER-ALERT-SEND-EMAILS %s " % (datetime.now()).
if 'score_by_cat' >=9:
send_email()
if 'score_by_cat' >=9:
print("Send Email")
else:
print('Nothing")
print "Begin GAMER-ALERT-SEND-EMAILS %s " % (datetime.now())
client = MongoClient('mongodb://localhost:28057/')
db = client.factor
email_rcpt_list = ['[email protected]']
['[email protected]']
#process the alert.. if it is high enough risk and the makes sense (not a security control etc)
for alert in db.risk_alerts.find({"$and" : [{'sent': False}]}):
if float(alert['metric'])>=9 and alert['category']!='security control':
#Call email send here
for email in email_rcpt_list:
print 'Call email and pass in the email address from email_rcpt_list'
print ' Sample alert: Vendor: %s Has an new item %s on %s of elevated risk %s in the category %s link: https://Gamer-dev.momo.net/profile/view/detail/%s' % (alert['vendor_name'],alert['key'],alert['source'],alert['metric'],alert['category'],alert['profile_id'])
#mark as sent always
db.risk_alerts.update_one({"_id":alert['_id']},{"$set": {"sent":True}})
print "End GAMER-ALERT-SEND-EMAILS %s" % (datetime.now())
このスクリプトでも最初の場所で動作しますか? 'score_by_cat '> = 9'の場合、コロン': 'なし? –
ここで起こっている書式設定の問題があるようです。そして、Pythonでは、書式設定が重要なので、正しく書式設定されているかどうかを確認する必要があります。 –
さて、残念ですが、私はそれを編集します – Jon