Geoffrey-Django/GeoffreyApp/background_tasks.py

22 lines
549 B
Python

from GeoffreyApp.models import Player
from GeoffreyApp.minecraft_api import grab_playername
from apscheduler.schedulers.background import BackgroundScheduler
def update_usernames():
players = Player.objects.all()
for player in players:
mc_username = grab_playername(player.mc_uuid)
if player.name != mc_username:
player.name = mc_username
player.save()
def run_tasks():
scheduler = BackgroundScheduler()
scheduler.add_job(update_usernames, 'interval', minutes=10)
scheduler.start()