简体   繁体   English

如何在整个一周(白天和黑夜)每 5 分钟轻松且廉价地运行一个简单的 python 脚本?

[英]How to easily and cheaply run a simply python script every 5 mins for a whole week - day and night?

I want to run a very simple python script (or any language) which collects data from an api at regular 5 minute intervals and saves the data.我想运行一个非常简单的 python 脚本(或任何语言),它每隔 5 分钟从 api 收集数据并保存数据。 I need this process to run for a whole week - day and night.我需要这个过程运行一整周 - 白天和黑夜。 I can't keep my laptop on all week so I guess I will need this to run on some kind of server.我不能让我的笔记本电脑整周都开着,所以我想我需要它才能在某种服务器上运行。

What is the cheapest and easiest way for me to do something like this?对我来说做这样的事情最便宜和最简单的方法是什么? This is an incredibly simple script so I don't want to spend ages setting up a complicated server which is ultimately overkill for a task like this.这是一个非常简单的脚本,所以我不想花很多时间来设置一个复杂的服务器,这对于这样的任务来说最终是多余的。

Pseudocode:伪代码:

# Every 5 minutes for a whole week:

data = call_api(url)
write_csv(data)

You're going to need a cloud server as it's the cheapest option if u can't setup a system at home.您将需要一个云服务器,因为如果您无法在家中设置系统,它是最便宜的选择。 I'll 2nd what furas said about pythonanywhere.com.我将第二次 furas 所说的关于 pythonanywhere.com 的内容。 I use their $5 a month plan to run simple tasks like this.我使用他们每月 5 美元的计划来运行这样的简单任务。 You can cancel anytime so if it's just 1 week then you pay $5 for your account, that's it.您可以随时取消,所以如果只有 1 周,那么您为您的帐户支付 5 美元,仅此而已。

There is no messing around with setup either, just upload your main.py and schedule as task in the dashboard.设置也没有混乱,只需上传您的 main.py 并将其安排为仪表板中的任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM