我想使用cron schedule来读取文本文件的每一行。
cron:
- description: read a line of text file
url: /read
schedule: every 1 minutes
但是GAE只允许在不修改的情况下读取文本文件。
如何让请求read
知道前一行已被读取,并且应该读取下一行。我不想将所有读取行存储在数据存储区中然后进行查询,检查文本行是否在数据存储区中,bla bla,因为我有数百万行。
请指教。我正在考虑Google Drive Api,有什么想法吗?感谢
更新:我可以这样做吗
with open('text.txt', 'r') as f:
txt= f.readlines()
f.close()
t = txt[line_num]
DO SOMETHING
line_num = line_num+1
deferred.defer( read_deferred, line_num, _countdown = 60 ) # 60 sec = 1 min
在其他地方,我通过调用
来触发deferred.defer( read_deferred, 0, _countdown = 60 ) # 60 sec = 1 min
答案 0 :(得分:1)
def read_deferred(last_pos) :
f = open( ... )
if last_pos : f.seek(last_pos)
# here you read the next line and do whatever you like,
# just don't go further and return once you hit EOF
last_pos = f.tell()
deferred.defer( read_deferred, last_pos, _countdown = 60 ) # 60 sec = 1 min
你第一次称它为:
deferred.defer( read_deferred, _countdown = 60 ) # 60 sec = 1 min