使用数据存储中的属性写入文件

发布于 2024-12-15 21:22:53 字数 615 浏览 3 评论 0原文

我想要一个以逗号分隔的列表,其中包含我的应用程序存储的所有电子邮件地址。它对于常规请求来说太大了,并且将其写入 blobstore 也是一个太大的请求:

class CSVHandler(webapp2.RequestHandler):
    def get(self):
        entities = Entity.all().fetch(10000)
        s = ''
        for entity in entities:
            s= s+","+str(entity.email)       
        file_name = files.blobstore.create(mime_type='application/octet-stream')     
        with files.open(file_name, 'a') as f:
          f.write(s)    
        files.finalize(file_name)    
        blob_key = files.blobstore.get_blob_key(file_name)

我可以将其作为任务、队列、后端或其他东西来实现吗?

预先感谢您的任何建议

I want a comma-separated list of all the email addresses my application stores. It's too large for a regular request and writing it to the blobstore is also a too large request:

class CSVHandler(webapp2.RequestHandler):
    def get(self):
        entities = Entity.all().fetch(10000)
        s = ''
        for entity in entities:
            s= s+","+str(entity.email)       
        file_name = files.blobstore.create(mime_type='application/octet-stream')     
        with files.open(file_name, 'a') as f:
          f.write(s)    
        files.finalize(file_name)    
        blob_key = files.blobstore.get_blob_key(file_name)

Can I do it as a task, a queue, a backend or something else instead?

Thank you in advance for any suggestion

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倾城月光淡如水﹏ 2024-12-22 21:22:53

不要尝试在单个写入操作中保存整个文件,而是将其分块写入 blobstore。使用csv模块将使这变得更容易,允许您逐步编写它。

Instead of trying to save the entire file in a single write operation, write it to the blobstore in chunks. Using the csv module will make this easier, allowing you to write it progressively.

苹果你个爱泡泡 2024-12-22 21:22:53

您可能应该使用内置的批量加载器工具,该工具可以通过远程 API 下载所有对象并将所选字段保存为 CSV 格式。

You should probably use the built-in bulkloader tool, which can download all objects via the remote API and save selected fields into CSV format.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文