First pass on username update background task
parent
a4d71858bf
commit
7dc93e4439
|
@ -1,7 +1,7 @@
|
|||
from django.db.models import Q, F
|
||||
from GeoffreyApp.models import *
|
||||
from GeoffreyApp.api.BotErrors import *
|
||||
from GeoffreyApp.api.MinecraftAccountInfoGrabber import *
|
||||
from GeoffreyApp.minecraft_api import *
|
||||
|
||||
post_list = []
|
||||
get_list = []
|
||||
|
|
4
apps.py
4
apps.py
|
@ -11,7 +11,9 @@ class GeoffreyAppConfig(AppConfig):
|
|||
verbose_name = "Geoffrey: Minecraft Web Database"
|
||||
|
||||
def ready(self):
|
||||
subprocess.run('screen -X -S "{0}" quit'.format("geoffrey"), shell=True)
|
||||
import GeoffreyApp.background_tasks as background_tasks
|
||||
background_tasks.run_tasks()
|
||||
#subprocess.run('screen -X -S "{0}" quit'.format("geoffrey"), shell=True)
|
||||
#subprocess.run(
|
||||
# 'screen -S geoffrey -d -m {} {}'.format(sys.executable, path),
|
||||
# shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
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()
|
Loading…
Reference in New Issue