所以我的Google App Engine(Python)中有一个textproperty变量。我通过远程api将数据导出到csv。
import csv
class Tower_of_London_History(db.Model):
email = db.StringProperty(required=True)
start_datetime = db.DateTimeProperty(required=True)
end_datetime = db.DateTimeProperty(required=True)
duration_to_first_move = db.IntegerProperty(required=True)
completed = db.BooleanProperty(required=True)
tower_type = db.StringProperty(required=True)
duration = db.IntegerProperty(required=True)
total_violations = db.IntegerProperty(required=True)
total_legal_moves = db.IntegerProperty(required=True)
time_type = db.StringProperty(required=True)
move_time_stamps = db.TextProperty(required=True)
timezone = db.StringProperty(required=False)
utc_to_local_delta = db.IntegerProperty(required=False)
def exportToCsvTower_of_London_History(query, csvFileName, delimiter):
with open(csvFileName, 'wb') as csvFile:
csvWriter = csv.writer(csvFile, delimiter=delimiter, quotechar='|', quoting=csv.QUOTE_MINIMAL)
writeHeaderTower_of_London_History(csvWriter)
rowsPerQuery = 1000
totalRowsSaved = 0
cursor = None
areMoreRows = True
while areMoreRows:
if cursor is not None:
query.with_cursor(cursor)
items = query.fetch(rowsPerQuery)
cursor = query.cursor()
currentRows =0
for item in items:
saveItemTower_of_London_History(csvWriter, item)
currentRows += 1
totalRowsSaved += currentRows
areMoreRows = currentRows >= rowsPerQuery
print 'Saved ' + str(totalRowsSaved) + ' rows'
print 'Finished saving all rows.'
def writeHeaderTower_of_London_History(csvWriter):
csvWriter.writerow(['email', 'start_datetime', 'end_datetime', 'duration_to_first_move (seconds)', 'completed',
'tower_type', 'duration (seconds)', 'total_violations', 'total_legal_moves', 'time_type',
'move_time_stamps', 'timezone', 'utc_to_local_delta (mins)']) #Output csv header
def saveItemTower_of_London_History(csvWriter, item):
csvWriter.writerow([item.email, item.start_datetime, item.end_datetime, item.duration_to_first_move,
item.completed, item.tower_type, item.duration, item.total_violations, item.total_legal_moves,
item.time_type, item.move_time_stamps, item.timezone, item.utc_to_local_delta]) # Save items in preferred format
query = Tower_of_London_History.gql("ORDER BY email")
exportToCsvTower_of_London_History(query, 'moment_exported_csv_files/tower_of_london_history.csv', ',')
我收到以下错误
BadValueError: Property move_time_stamps is 3085 bytes long; it must be 1500 or less.
有关您的信息,我使用以下命令运行该程序: (在终端上) remote_api_shell.py -s APP ID import file_name
我想知道是否有任何方法可以将大于1500字节的TextProperty导出为Excel CSV。
这是完整的痕迹
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "export_moment_data.py", line 568, in <module>
exportToCsvTower_of_London_History(query, 'moment_exported_csv_files/tower_of_london_history.csv', ',')
File "export_moment_data.py", line 387, in exportToCsvTower_of_London_History
items = query.fetch(rowsPerQuery)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/db/__init__.py", line 2161, in fetch
return list(self.run(limit=limit, offset=offset, **kwargs))
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/db/__init__.py", line 2330, in next
return self.__model_class.from_entity(self.__iterator.next())
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/db/__init__.py", line 1445, in from_entity
return cls(None, _from_entity=entity, **entity_values)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/db/__init__.py", line 973, in __init__
prop.__set__(self, value)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/db/__init__.py", line 617, in __set__
value = self.validate(value)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/db/__init__.py", line 2855, in validate
% (self.name, len(value), self.MAX_LENGTH))
BadValueError: Property move_time_stamps is 3085 bytes long; it must be 1500 or less.