35 lines
1.3 KiB
Python
35 lines
1.3 KiB
Python
import os
|
|
import logging
|
|
from vrcapi import get_group_instances
|
|
from testing import fake_group_instances
|
|
from datetime import datetime
|
|
from db import DBGroupInstance, get_session
|
|
|
|
log_level = os.getenv("LOG_LEVEL")
|
|
logging.basicConfig(level=log_level)
|
|
session = get_session()
|
|
|
|
# Commit the group instance data in the DB
|
|
def store_instance_data(instance):
|
|
try:
|
|
db_instance = DBGroupInstance(
|
|
timestamp=datetime.now(),
|
|
instance_id=instance.instance_id,
|
|
world_name=instance.world.name,
|
|
member_count=instance.member_count,
|
|
delivered=False # Discord delivery, always false until separate job marks it as True
|
|
)
|
|
session.add(db_instance)
|
|
session.commit()
|
|
logging.info("Instance log added")
|
|
except Exception as e:
|
|
logging.error(f"Exception while adding instance log: {e}")
|
|
session.rollback()
|
|
|
|
if __name__ == "__main__":
|
|
group_instances = get_group_instances() # Call the VRChat API and pull group instance data
|
|
if not group_instances:
|
|
logging.info("No group instances were found! Nothing to do...") # Since this will run in a cron job, the program ends here
|
|
else:
|
|
for instance in group_instances:
|
|
store_instance_data(instance) # Send instance data to the DB |