def get_records(self, start_timestamp=0, end_timestamp=None):
"""Gets records from the table between the specified timestamps.
Args:
Timestamps are given in seconds since epoch.
Returns a list of dicts, each of the form: {
'id': 3,
'record_timestamp': 1341556432,
'imsi': 'IMSI901550000000084',
'ipaddr': '192.168.99.3',
'uploaded_bytes': 5567,
'downloaded_bytes': 9987,
'uploaded_bytes_delta': 74,
'downloaded_bytes_delta': 139
}
"""
start = psycopg2.TimestampFromTicks(start_timestamp)
if not end_timestamp:
end_timestamp = time.time()
end = psycopg2.TimestampFromTicks(end_timestamp)
template = ('select * from %s where record_timestamp >= %s'
' and record_timestamp <= %s')
command = template % (self.table_name, start, end)
with self.connection.cursor(
cursor_factory=psycopg2.extras.RealDictCursor) as cursor:
cursor.execute(command)
self.connection.commit()
return cursor.fetchall()
gprs_database.py 文件源码
python
阅读 35
收藏 0
点赞 0
评论 0
评论列表
文章目录