本文整理汇总了Python中sek.logger.SEKLogger.log方法的典型用法代码示例。如果您正苦于以下问题:Python SEKLogger.log方法的具体用法?Python SEKLogger.log怎么用?Python SEKLogger.log使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sek.logger.SEKLogger
的用法示例。
在下文中一共展示了SEKLogger.log方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MECODataAutoloader
# 需要导入模块: from sek.logger import SEKLogger [as 别名]
# 或者: from sek.logger.SEKLogger import log [as 别名]
class MECODataAutoloader(object):
"""
Provide automated loading of MECO energy data from exports in
gzip-compressed XML source data.
"""
def __init__(self):
"""
Constructor.
"""
self.logger = SEKLogger(__name__)
self.configer = MSGConfiger()
self.fileUtil = MSGFileUtil()
def newDataExists(self):
"""
Check the data autoload folder for the presence of new data.
:returns: True if new data exists.
"""
autoloadPath = self.configer.configOptionValue("MECO Autoload", "meco_autoload_new_data_path")
if not self.fileUtil.validDirectory(autoloadPath):
raise Exception("InvalidDirectory", "%s" % autoloadPath)
patterns = ["*.gz"]
matchCnt = 0
for root, dirs, filenames in os.walk(autoloadPath):
for pat in patterns:
for filename in fnmatch.filter(filenames, pat):
print filename
matchCnt += 1
if matchCnt > 0:
return True
else:
return False
def loadNewData(self):
"""
Load new data contained in the new data path.
"""
autoloadPath = self.configer.configOptionValue("MECO Autoload", "meco_autoload_new_data_path")
command = self.configer.configOptionValue("MECO Autoload", "meco_autoload_command")
os.chdir(autoloadPath)
try:
subprocess.check_call(command, shell=True)
except subprocess.CalledProcessError, e:
self.logger.log("An exception occurred: %s" % e, "error")
示例2: MSGWeatherDataDupeChecker
# 需要导入模块: from sek.logger import SEKLogger [as 别名]
# 或者: from sek.logger.SEKLogger import log [as 别名]
class MSGWeatherDataDupeChecker(object):
"""
Determine if a duplicate record exists based on the tuple
(WBAN, Date, Time, StationType).
"""
def __init__(self, testing = False):
"""
Constructor.
:param testing: Flag for testing mode.
"""
self.logger = SEKLogger(__name__, 'debug')
self.dbUtil = MSGDBUtil()
def duplicateExists(self, dbCursor, wban, datetime, recordType):
"""
Check for the existence of a duplicate record.
:param dbCursor
:param wban
:param datetime
:param recordType
:returns: True if a duplicate record exists, otherwise False.
"""
tableName = "WeatherNOAA"
sql = """SELECT wban, datetime, record_type FROM \"%s\" WHERE
wban = '%s' AND datetime = '%s' AND record_type = '%s'""" % (
tableName, wban, datetime, recordType)
self.logger.log("sql=%s" % sql, 'debug')
self.logger.log("wban=%s, datetime=%s, record_type=%s" % (
wban, datetime, recordType), 'debug')
self.dbUtil.executeSQL(dbCursor, sql)
rows = dbCursor.fetchall()
if len(rows) > 0:
return True
else:
return False
开发者ID:Hawaii-Smart-Energy-Project,项目名称:Maui-Smart-Grid,代码行数:47,代码来源:msg_noaa_weather_data_dupe_checker.py
示例3: MSGTimeUtilTester
# 需要导入模块: from sek.logger import SEKLogger [as 别名]
# 或者: from sek.logger.SEKLogger import log [as 别名]
class MSGTimeUtilTester(unittest.TestCase):
def setUp(self):
self.logger = SEKLogger(__name__, 'debug')
self.timeUtil = MSGTimeUtil()
def test_concise_now(self):
conciseNow = self.timeUtil.conciseNow()
self.logger.log(conciseNow)
pattern = '\d+-\d+-\d+_\d+'
result = re.match(pattern, conciseNow)
self.assertTrue(result is not None,
"Concise now matches the regex pattern.")
def test_split_dates(self):
start = dt(2014, 01, 07)
end = dt(2014, 04, 04)
print self.timeUtil.splitDates(start, end)
self.assertEqual(len(self.timeUtil.splitDates(start, end)), 4,
'Unexpected date count.')
示例4: SIDataUtilTester
# 需要导入模块: from sek.logger import SEKLogger [as 别名]
# 或者: from sek.logger.SEKLogger import log [as 别名]
class SIDataUtilTester(unittest.TestCase):
"""
"""
def setUp(self):
self.dataUtil = SIDataUtil()
self.logger = SEKLogger(__name__)
def test_find_max_timestamp(self):
filePath = 'data/test-meter/log.csv'
self.assertEquals(self.dataUtil.maxTimeStamp(filePath),
datetime.strptime('2014-03-10 23:59:00',
'%Y-%m-%d %H:%M:%S'))
def test_find_max_timestamp_db(self):
# @todo test with a static testing DB
meter = '001EC6051A0D'
self.logger.log(self.dataUtil.maxTimeStampDB(meter))
示例5: WeatherDataLoadingTester
# 需要导入模块: from sek.logger import SEKLogger [as 别名]
# 或者: from sek.logger.SEKLogger import log [as 别名]
class WeatherDataLoadingTester(unittest.TestCase):
def setUp(self):
self.weatherUtil = MSGWeatherDataUtil()
self.logger = SEKLogger(__name__, 'DEBUG')
self.dbConnector = MSGDBConnector()
self.cursor = self.dbConnector.conn.cursor()
self.configer = MSGConfiger()
def testLoadDataSinceLastLoaded(self):
"""
Data should be loaded since the last data present in the database.
"""
pass
def testRetrieveDataSinceLastLoaded(self):
"""
Data since the last loaded date is retrieved.
"""
pass
def testGetLastLoadedDate(self):
myDate = self.weatherUtil.getLastDateLoaded(self.cursor).strftime(
"%Y-%m-%d %H:%M:%S")
pattern = '^(\d+-\d+-\d+\s\d+:\d+:\d+)$'
match = re.match(pattern, myDate)
assert match and (match.group(1) == myDate), "Date format is valid."
def testWeatherDataPattern(self):
myPattern = self.configer.configOptionValue('Weather Data',
'weather_data_pattern')
testString = """<A HREF="someURL">QCLCD201208.zip</A>"""
match = re.match(myPattern, testString)
self.logger.log("pattern = %s" % myPattern, 'info')
if match:
self.logger.log("match = %s" % match)
self.logger.log("match group = %s" % match.group(1))
else:
self.logger.log("match not found")
assert match and match.group(
1) == 'QCLCD201208.zip', "Download filename was matched."
def testWeatherDataURL(self):
myURL = self.configer.configOptionValue('Weather Data',
'weather_data_url')
pass
开发者ID:Hawaii-Smart-Energy-Project,项目名称:Maui-Smart-Grid,代码行数:53,代码来源:test_noaa_weather_data_loading.py
示例6: NewDataAggregator
# 需要导入模块: from sek.logger import SEKLogger [as 别名]
# 或者: from sek.logger.SEKLogger import log [as 别名]
class NewDataAggregator(object):
"""
Perform aggregation of new data for a set of predefined data types (self
.rawTypes).
"""
def __init__(self):
"""
Constructor.
"""
self.logger = SEKLogger(__name__, 'DEBUG')
self.aggregator = MSGDataAggregator()
self.notifier = MSGNotifier()
self.rawTypes = [x.name for x in list(MSGAggregationTypes)]
self.connector = MSGDBConnector()
self.conn = self.connector.connectDB()
self.cursor = self.conn.cursor()
self.dbUtil = MSGDBUtil()
def sendNewDataNotification(self, result = None, testing = False):
"""
Sending notification reporting on new data being available since the
last time new data was reported.
:param result: list of dicts containing aggregation results as
provided by MSGDataAggregator::aggregateNewData.
:param testing: Use testing mode when True.
"""
self.logger.log('result {}'.format(result), 'debug')
lastReportDate = self.notifier.lastReportDate(
MSGNotificationHistoryTypes.MSG_DATA_AGGREGATOR)
if not lastReportDate:
lastReportDate = "never"
if not result:
msgBody = '\nNew data has NOT been aggregated in {}. No result ' \
'was obtained. This is an error that should be ' \
'investigated.'.format(self.connector.dbName)
else:
msgBody = '\nNew data has been aggregated in {}.'.format(
self.connector.dbName)
msgBody += '\n\n'
for i in range(len(result)):
msgBody += 'The new data count for type {} is {} readings' \
'.\n'.format(result[i].keys()[0],
result[i].values()[0])
msgBody += '\n\n'
msgBody += 'The last report date was %s.' % lastReportDate
msgBody += '\n\n'
self.notifier.sendNotificationEmail(msgBody, testing = testing)
self.notifier.recordNotificationEvent(
MSGNotificationHistoryTypes.MSG_DATA_AGGREGATOR)
def aggregateNewData(self):
"""
:return: list of dicts obtained from
MSGDataAggregator::aggregateNewData.
"""
result = map(self.aggregator.aggregateNewData, self.rawTypes)
self.logger.log('result {}'.format(result))
return result
示例7: aggregateNewData
# 需要导入模块: from sek.logger import SEKLogger [as 别名]
# 或者: from sek.logger.SEKLogger import log [as 别名]
msgBody += 'The new data count for type {} is {} readings' \
'.\n'.format(result[i].keys()[0],
result[i].values()[0])
msgBody += '\n\n'
msgBody += 'The last report date was %s.' % lastReportDate
msgBody += '\n\n'
self.notifier.sendNotificationEmail(msgBody, testing = testing)
self.notifier.recordNotificationEvent(
MSGNotificationHistoryTypes.MSG_DATA_AGGREGATOR)
def aggregateNewData(self):
"""
:return: list of dicts obtained from
MSGDataAggregator::aggregateNewData.
"""
result = map(self.aggregator.aggregateNewData, self.rawTypes)
self.logger.log('result {}'.format(result))
return result
if __name__ == '__main__':
aggregator = NewDataAggregator()
logger = SEKLogger(__name__)
logger.log('Last report date {}'.format(aggregator.notifier.lastReportDate(
MSGNotificationHistoryTypes.MSG_DATA_AGGREGATOR)))
result = aggregator.aggregateNewData()
aggregator.sendNewDataNotification(result = result, testing = False)
示例8: processCommandLineArguments
# 需要导入模块: from sek.logger import SEKLogger [as 别名]
# 或者: from sek.logger.SEKLogger import log [as 别名]
if __name__ == '__main__':
processCommandLineArguments()
tableBase = "MeterData"
pkey = 'meter_id, time_utc'
logger = SEKLogger(__name__, 'debug')
configer = SIConfiger()
dbUtil = SEKDBUtil()
conn = SEKDBConnector(
dbName = configer.configOptionValue('Database', 'db_name'),
dbHost = configer.configOptionValue('Database', 'db_host'),
dbPort = configer.configOptionValue('Database', 'db_port'),
dbUsername = configer.configOptionValue('Database', 'db_username'),
dbPassword = configer.configOptionValue('Database',
'db_password')).connectDB()
cursor = conn.cursor()
tableOwner = configer.configOptionValue('Database', 'table_owner')
for meterName in SIUtil().meters(basepath = COMMAND_LINE_ARGS.basepath):
logger.log('creating table {}'.format(tableBase + "_" + meterName))
sql = 'CREATE TABLE "{1}_{0}" ( CHECK ( meter_id = meter_id(\'{' \
'0}\'))) INHERITS ("{1}"); ALTER TABLE ONLY "{1}_{0}" ADD ' \
'CONSTRAINT "{1}_{0}_pkey" PRIMARY KEY ({3}); ALTER TABLE ONLY ' \
'"{1}_{0}" ADD CONSTRAINT meter_id_fkey FOREIGN KEY (meter_id) ' \
'REFERENCES "Meters"(meter_id) ON UPDATE CASCADE ON DELETE ' \
'CASCADE; ALTER TABLE "{1}_{0}" OWNER TO {2}'.format(
meterName, tableBase, tableOwner, pkey)
if dbUtil.executeSQL(cursor, sql, exitOnFail = False):
conn.commit()
else:
conn.rollback()
开发者ID:Hawaii-Smart-Energy-Project,项目名称:Smart-Grid-PV-Inverter,代码行数:32,代码来源:createMeterDataPartitions.py
示例9: performDownloading
# 需要导入模块: from sek.logger import SEKLogger [as 别名]
# 或者: from sek.logger.SEKLogger import log [as 别名]
# Get the keep list.
keepList = weatherUtil.getKeepList(retriever.fileList, cursor)
if keepList:
msg = "Performing secondary retrieval."
print msg
MSG_BODY += "%s\n" % msg
retriever.pool = multiprocessing.Pool(int(multiprocessingLimit))
results = retriever.pool.map(performDownloadingWithForcedDownload, keepList)
retriever.pool.close()
retriever.pool.join()
if False in results:
msg = "An error occurred during secondary retrieval."
print msg
MSG_BODY += "%s\n" % msg
if downloadCount == 0:
# Retrieve the last dated set if nothing else was retrieved.
retriever.dateList.sort()
logger.log("filelist {}".format(retriever.fileList), INFO)
performDownloading(retriever.fileList[-1], forceDownload=True)
msg = "downloadCount = %s." % downloadCount
print msg
MSG_BODY += "%s\n" % msg
cleanUpTxtFiles()
saveRetrievalResults()
示例10: MECODupeChecker
# 需要导入模块: from sek.logger import SEKLogger [as 别名]
# 或者: from sek.logger.SEKLogger import log [as 别名]
class MECODupeChecker(object):
"""
Check for duplicate data in the database.
"""
def __init__(self):
"""
Constructor.
"""
self.logger = SEKLogger(__name__, 'debug')
self.mecoConfig = MSGConfiger()
self.currentReadingID = 0
self.dbUtil = MSGDBUtil()
def getLastElement(self, rows):
"""
Get the last element in a collection.
Example:
rows = (element1, element2, element3)
getLastElement(rows) # return element3
:param rows Result froms from a query
:return last element in the collection
"""
for i, var in enumerate(rows):
if i == len(rows) - 1:
return var
def eventBranchDupeExists(self, conn, meterName, eventTime):
"""
:param conn: Database connection.
:param meterName: Meter name in MeterData table.
:param eventTime: Timestamp of event.
:return: True if tuple exists, False if not.
"""
dbCursor = conn.cursor()
sql = """SELECT "Event".event_time,
"MeterData".meter_data_id,
"EventData".event_data_id
FROM ( ( "MeterData" JOIN "EventData" ON (
( "MeterData".meter_data_id = "EventData"
.meter_data_id ) ) )
JOIN "Event" ON ( ( "EventData".event_data_id = "Event"
.event_data_id ) ) )
WHERE "MeterData".meter_name = '%s'
AND "Event".event_time = '%s' """ % (meterName, eventTime)
self.dbUtil.executeSQL(dbCursor, sql)
rows = dbCursor.fetchall()
if len(rows) > 0:
return True
else:
return False
def registerBranchDupeExists(self, conn, meterName, readTime,
registerNumber, DEBUG = False):
"""
Determine if a register branch duplicate exists for a given meter
name, read time, number tuple.
:param conn: Database connection.
:param meterName: Meter name in MeterData table.
:param readTime: Read time in RegisterRead table.
:param registerNumber: Corresponds to DB column "number".
:return: True if tuple exists, False if not.
"""
dbCursor = conn.cursor()
sql = """SELECT "public"."MeterData".meter_name,
"public"."RegisterRead".read_time,
"public"."Register"."number"
FROM "public"."MeterData"
INNER JOIN "public"."RegisterData" ON
"public" ."MeterData".meter_data_id = "public"
."RegisterData".meter_data_id
INNER JOIN "public"."RegisterRead" ON
"public"."RegisterData" .register_data_id = "public"
."RegisterRead".register_data_id
INNER JOIN "public"."Tier" ON "public"."RegisterRead"
.register_read_id = "public"."Tier" .register_read_id
INNER JOIN "public"."Register" ON "public"."Tier".tier_id =
"public"."Register".tier_id
WHERE "public"."MeterData".meter_name = '%s'
AND "public"."RegisterRead".read_time = '%s'
AND "public"."Register".number = '%s'
""" % (meterName, readTime, registerNumber)
self.dbUtil.executeSQL(dbCursor, sql)
rows = dbCursor.fetchall()
#.........这里部分代码省略.........
示例11: MSGFileUtil
# 需要导入模块: from sek.logger import SEKLogger [as 别名]
# 或者: from sek.logger.SEKLogger import log [as 别名]
class MSGFileUtil(object):
"""
Utilities related to files and directories.
"""
def __init__(self):
"""
Constructor.
"""
warnings.simplefilter('default')
warnings.warn("This module is deprecated in favor of SEKFileUtil.",
DeprecationWarning)
self.logger = SEKLogger(__name__, 'DEBUG')
def validDirectory(self, path):
"""
Verify that the path is a valid directory.
:param path: Path to check.
:returns: True if path is a valid directory.
"""
if os.path.exists(path) and os.path.isdir(path):
return True
else:
return False
def md5Checksum(self, fullPath):
"""
Get the MD5 checksum for the file given by fullPath.
:param fullPath: Full path of the file to generate for which to
generate a checksum.
:returns: MD5 checksum value as a hex digest.
"""
try:
f = open(fullPath, mode = 'rb')
content = hashlib.md5()
for buf in iter(partial(f.read, 128), b''):
content.update(buf)
md5sum = content.hexdigest()
f.close()
return md5sum
except IOError as detail:
self.logger.log(
'Exception during checksum calculation: %s' % detail, 'ERROR')
def gzipUncompressFile(self, srcPath, destPath):
"""
Gzip uncompress a file given by fullPath.
@todo Need to deal with large file sizes. Stop reading into memory.
:param srcPath: Full path of the file to be uncompressed.
:param destPath: Full path of file to be written to.
"""
self.logger.log(
'Uncompressing gzip source %s to %s' % (srcPath, destPath), 'DEBUG')
gzipFile = gzip.open(srcPath, "rb")
uncompressedFile = open(destPath, "wb")
decoded = gzipFile.read()
try:
uncompressedFile.write(decoded)
except:
self.logger.log("Exception while writing uncompressed file.")
gzipFile.close()
uncompressedFile.close()
def gzipCompressFile(self, fullPath):
"""
Perform gzip compression on a file at fullPath.
@todo Generalize this method.
:param fullPath: Full path of the file to be compressed.
:returns: Boolean: True if successful, False otherwise.
"""
success = False
self.logger.log('Gzip compressing %s.' % fullPath)
try:
f_in = open('%s' % (fullPath), 'rb')
f_out = gzip.open('%s.gz' % (fullPath), 'wb')
f_out.writelines(f_in)
f_out.close()
f_in.close()
success = True
except IOError as detail:
self.logger.log('IOError exception while gzipping: %s' % detail, 'ERROR')
return success
def splitFile(self, fullPath = '', chunkSize = 0):
"""
#.........这里部分代码省略.........
示例12: MECODBInserter
# 需要导入模块: from sek.logger import SEKLogger [as 别名]
# 或者: from sek.logger.SEKLogger import log [as 别名]
class MECODBInserter(object):
"""
Provides methods that perform insertion of MECO data.
"""
def __init__(self):
"""
Constructor.
"""
self.logger = SEKLogger(__name__, 'debug')
self.mapper = MECOMapper()
self.dupeChecker = MECODupeChecker()
self.dbUtil = MSGDBUtil()
def __call__(self, param):
print "CallableClass.__call__(%s)" % param
def insertData(self, conn, tableName, columnsAndValues, fKeyVal = None,
withoutCommit = 0):
"""
Given a table name and a dictionary of column names and values,
insert them to the DB.
:param conn: database connection
:param tableName: name of the db table
:param columnsAndValues: dictionary of columns and values to be
inserted to the db
:param (optional) fKeyVal: an explicit foreign key value
:param (optional) withoutCommit: a flag indicated that the insert
will not be immediately committed
:returns: A database cursor.
"""
cur = conn.cursor()
# Get a dictionary of mapped (from DB to source data) column names.
columnDict = self.mapper.getDBColNameDict(tableName)
dbColsAndVals = {}
if VISUALIZE_DATA:
print "----------" + tableName + "----------"
print columnDict
print columnsAndValues
for col in columnDict.keys():
# Use default as the value for the primary key so that the
# private key is obtained from the predefined sequence.
if col == '_pkey':
if VISUALIZE_DATA:
print columnDict[col], # DB col name.
print 'DEFAULT'
dbColsAndVals[columnDict[col]] = 'DEFAULT'
# For the foreign key, set the value from the given parameter.
elif col == '_fkey':
if VISUALIZE_DATA:
print columnDict[col], # DB col name.
print fKeyVal
dbColsAndVals[columnDict[col]] = fKeyVal
else:
if VISUALIZE_DATA:
print columnDict[col], # DB col name.
# The Register and Reading tables need to handle NULL
# values as a special case.
if tableName == 'Register' or tableName == 'Reading':
try:
if VISUALIZE_DATA:
print columnsAndValues[col] # data source value
dbColsAndVals[columnDict[col]] = columnsAndValues[col]
except:
if VISUALIZE_DATA:
print 'NULL'
dbColsAndVals[columnDict[col]] = 'NULL'
# For all other cases, simply pass the value.
else:
if VISUALIZE_DATA:
print columnsAndValues[col] # data source value
dbColsAndVals[columnDict[col]] = columnsAndValues[col]
# Add a creation timestamp to MeterData.
if tableName == 'MeterData':
dbColsAndVals['created'] = 'NOW()'
cols = []
vals = []
for col in dbColsAndVals.keys():
cols.append(col)
# DEFAULT, NULL and NOW() need to appear without quotes.
if dbColsAndVals[col] in {'DEFAULT', 'NULL', 'NOW()'}:
vals.append(dbColsAndVals[col])
else:
vals.append("'%s'" % dbColsAndVals[
col]) # Surround value with single quotes.
#.........这里部分代码省略.........
示例13: MSGWeatherDataUtil
# 需要导入模块: from sek.logger import SEKLogger [as 别名]
# 或者: from sek.logger.SEKLogger import log [as 别名]
class MSGWeatherDataUtil(object):
"""
Utility methods for working with weather data.
"""
def __init__(self):
"""
Constructor.
A database connection is not maintained here to keep this class
lightweight.
"""
self.logger = SEKLogger(__name__, DEBUG)
self.configer = MSGConfiger()
self.url = self.configer.configOptionValue('Weather Data',
'weather_data_url')
self.pattern = self.configer.configOptionValue('Weather Data',
'weather_data_pattern')
self.fileList = []
self.dateList = [] # List of dates corresponding weather data files.
self.fillFileListAndDateList()
self.dbUtil = MSGDBUtil()
def fillFileListAndDateList(self):
"""
Return a list of weather files obtained from the remote server used
in processing weather data.
"""
response = urllib2.urlopen(self.url).read()
self.logger.log('Filling file list:', DEBUG)
for filename in re.findall(self.pattern, response):
# Only examine first match group in the filename match.
self.logger.log('filename {}'.format(filename[0]), DEBUG)
self.fileList.append(filename[0])
self.dateList.append(self.datePart(filename[0]))
def datePart(self, filename = None, datetime = None):
"""
Return the date part of a NOAA weather data filename.
:param: String of the filename.
:param: datetime object.
:returns: String of the date part of the given parameter.
"""
assert filename == None or datetime == None, "One argument is allowed."
if filename:
newName = filename.replace("QCLCD", '')
newName = newName.replace(".zip", '')
return newName
if datetime:
return datetime.strftime('%Y-%m-%d')
def getLastDateLoaded(self, cursor):
"""
Return the last date of loaded weather data.
:returns: Last date.
"""
sql = """select wban, datetime, record_type from "%s"
ORDER BY datetime desc limit 1""" % WEATHER_DATA_TABLE
self.dbUtil.executeSQL(cursor, sql)
row = cursor.fetchone()
# self.logger.log('Date last loaded = %s' % row[1], 'info')
return row[1]
def getKeepList(self, fileList, cursor):
"""
The Keep List is the list of filenames of files containing data that are
*within* the month of the last loaded date or are beyond the last loaded
date.
:param: fileList: A list of files containing weather data.
:param: DB cursor.
:returns: List of weather data filenames to process.
"""
keepList = []
i = 0
for date in fileList:
self.logger.log('Examining date %s.' % date)
# The list date should be the last day of the month.
# It is the date that is compared against the last retrieved date.
listDate = dt.datetime.strptime(self.datePart(filename = date),
"%Y%m")
lastDay = calendar.monthrange(listDate.year, listDate.month)[1]
listDate = dt.datetime.strptime(
'%s-%s-%s' % (listDate.year, listDate.month, lastDay),
"%Y-%m-%d")
#.........这里部分代码省略.........
示例14: insertDataWrapper
# 需要导入模块: from sek.logger import SEKLogger [as 别名]
# 或者: from sek.logger.SEKLogger import log [as 别名]
result = insertDataWrapper(path)
pattern = 'Process-(\d+),'
jobString = str(multiprocessing.current_process())
match = re.search(pattern, jobString)
assert match.group(1) is not None, "Process ID was matched."
returnDict[match.group(1)] = result
if __name__ == '__main__':
processCommandLineArguments()
inserter = Inserter()
if COMMAND_LINE_ARGS.testing:
logger.log("Testing mode is ON.\n", 'info')
if COMMAND_LINE_ARGS.email:
logger.log("Email will be sent.\n", 'info')
msg = '' # Used for the notification message.
msgBody = '' # Used for the notification message.
databaseName = ''
if COMMAND_LINE_ARGS.testing:
databaseName = configer.configOptionValue("Database", "testing_db_name")
else:
databaseName = configer.configOptionValue("Database", "db_name")
msg = "Recursively inserting data to the database named %s." % databaseName
print msg
msgBody += msg + "\n"
示例15: MSGNotifier
# 需要导入模块: from sek.logger import SEKLogger [as 别名]
# 或者: from sek.logger.SEKLogger import log [as 别名]
class MSGNotifier(object):
"""
Provides notification service functionality for MSG data processing.
Email settings are stored in the local configuration.
Usage:
from msg_notifier import MSGNotifier
self.notifier = MSGNotifier()
Public API:
sendNotificationEmail(msgBody, testing = False):
Send msgBody as a notification to the mailing list defined in the
config file.
sendMailWithAttachments(msgBody, files = None, testing = False)
Send msgBody with files attached as a notification to the mailing
list defined in the config file.
lastReportDate(noticeType):
The last date where a notification of the given type was reported.
recordNotificationEvent(noticeType):
Record an event in the notification history.
"""
def __init__(self):
"""
Constructor.
"""
warnings.simplefilter('default')
warnings.warn("This module is deprecated in favor of SEKNotifier.",
DeprecationWarning)
self.config = MSGConfiger()
self.logger = SEKLogger(__name__, 'info')
self.connector = MSGDBConnector()
self.conn = self.connector.connectDB()
self.cursor = self.conn.cursor()
self.dbUtil = MSGDBUtil()
self.noticeTable = 'NotificationHistory'
self.notificationHeader = "This is a message from the Hawaii Smart " \
"Energy Project MSG Project notification " \
"system.\n\n"
self.noReplyNotice = '\n\nThis email account is not monitored. No ' \
'replies will originate from this ' \
'account.\n\nYou are receiving this message ' \
'because you are on the recipient list for ' \
'notifications for the Hawaii Smart Energy ' \
'Project.'
def sendNotificationEmail(self, msgBody, testing = False):
"""
This method is an alternative to the multipart method in
sendMailWithAttachments.
:param msgBody: The body of the message to be sent.
:param testing: True if running in testing mode.
:returns: True for success, False for an error.
"""
errorOccurred = False
user = self.config.configOptionValue('Notifications', 'email_username')
password = self.config.configOptionValue('Notifications',
'email_password')
fromaddr = self.config.configOptionValue('Notifications',
'email_from_address')
if testing:
toaddr = self.config.configOptionValue('Notifications',
'testing_email_recipients')
else:
toaddr = self.config.configOptionValue('Notifications',
'email_recipients')
server = smtplib.SMTP(self.config.configOptionValue('Notifications',
'smtp_server_and_port'))
try:
server.starttls()
except smtplib.SMTPException as detail:
errorOccurred = True
self.logger.log("Exception during SMTP STARTTLS: {}".format(detail),
'ERROR')
try:
server.login(user, password)
except smtplib.SMTPException as detail:
errorOccurred = True
self.logger.log("Exception during SMTP login: %s" % detail, 'ERROR')
senddate = datetime.now().strftime('%Y-%m-%d')
subject = "HISEP Notification"
msgHeader = "Date: {}\r\nFrom: {}\r\nTo: {}\r\nSubject: {" \
#.........这里部分代码省略.........