0

I have a little problem. So I'm importing jsondata from an url to a project of mine. The Data will be stored in cache and outputed to discord. So that's because the project is running 24/7 and at the moment my Data only updates when I'm restarting it. So I'm searching for a way to update the data.

In the codeblock you see how I import the data. Is there a way to include a function that updates the "data"?

It wouldn't be a problem if I loose the old data, when I'm importing the new one.

The Project should work in Python 3.7 and 3.8

I can't use time.sleep in a normal function, because it sleeps the whole discord bot

from urllib import request
response = urllib.request.urlopen(url)
data = json.loads(response.read())```
jelhan
  • 6,149
  • 1
  • 19
  • 35
Krokofant
  • 1
  • 1
  • Does this answer your question? [How do I get a Cron like scheduler in Python?](https://stackoverflow.com/questions/373335/how-do-i-get-a-cron-like-scheduler-in-python) – Kent Shikama Nov 11 '19 at 00:17
  • Or just use a crontab to run your script every so often. – Kent Shikama Nov 11 '19 at 00:17
  • I can't use time.sleep, because it sleeps my whole discord bot... – Krokofant Nov 11 '19 at 00:47
  • You could do as caches usually do, and check whether the data is too old as it's used. That way you don't need a background process to update the data – the only drawback is that it may take a while longer to access the data when it's too old. – AKX Nov 11 '19 at 13:33

0 Answers0