我正在使用带有谷歌日历 API 的 Flask/SqlAlchemy 应用程序。本质上,我正在创建一个事件数据库。这是一个精简的类片段:
# Flask. We just need the basic stuff in this common moduel
from flask import Flask
# flask SQLAlchemy
from flask.ext.sqlalchemy import SQLAlchemy
# Sort
from sqlalchemy import desc,asc,and_
# Datetime
from datetime import datetime, date
class FlyingEvent(db.Model):
# Event Data
event_id = db.Column(db.Text, primary_key=True)
updated_datetime = db.Column(db.DateTime)
start_date = db.Column(db.DateTime)
end_date = db.Column(db.DateTime)
status = db.Column(db.Text)
creator_email = db.Column(db.Text)
summary = db.Column(db.Text)
description = db.Column(db.Text)
# Flying-specific entries
flying = db.Column(db.Boolean)
tach_start = db.Column(db.Float)
tach_end = db.Column(db.Float)
def extract_hours():
def get_digits(line):
if re.compare('[\d\.]+', line):
return line
else:
return None
try:
right_now=date.today()
if self.flying and self.end_date.date() < right_now:
lines = self.description.split('\n')
self.tach_start = get_digits(lines[0])
self.tach_end = get_digits(lines[1])
except Exception as e:
raise Exception('%r, Could not parse tach %r %r' % (e, self,
right_now))
这引发了一个异常(我用对象的 repr 重新引发):
Exception: AttributeError("'module' object has no attribute 'compare'",), Could not parse tach { "event_id": u'go8bl9i615f7e7qljuoun9bqgk', "update_datetime": datetime.datetime(2013, 4, 12, 23, 58, 54, 371000), "start_date": datetime.datetime(2013, 4, 4, 0, 0), "end_date": datetime.datetime(2013, 4, 5, 0, 0), "status": u'confirmed', "creator_email": u'jordanzaretsky@gmail.com', "summary": u'jordan 10.6 to 10.9', "description": u'1010.7\n1010.9', "flying": True, "tach_start": 1010.7, "tach_end": 1010.9} datetime.date(2013, 4, 14)
在我看来,self.end_date 是一个 datetime 对象(我正在使用它的 .date()),而 right_now 是一个 datetime.date()。
我错过了什么?