0% found this document useful (0 votes)
57 views1 page

Check User Online Status in Batches

The document contains a Python script that checks the online status of users in batches using an API. It processes the results to categorize users as online or in-game and includes a delay between batch requests. The script prints the online and in-game users for each batch and the final results after all batches are processed.

Uploaded by

abdogamer200618
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views1 page

Check User Online Status in Batches

The document contains a Python script that checks the online status of users in batches using an API. It processes the results to categorize users as online or in-game and includes a delay between batch requests. The script prints the online and in-game users for each batch and the final results after all batches are processed.

Uploaded by

abdogamer200618
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import requests

import time

# List of user IDs


user_ids = [

# Function to check online status in batches


def check_online_status_batch(batch):
url = "https://presence.roproxy.com/v1/presence/"
params = {"userIds": ",".join(map(str, batch))}
response = requests.get(url, params=params)
if response.status_code == 200:
return response.json()
else:
print(f"Error fetching batch: {response.status_code}")
return {}

# Function to process results


def process_results(results):
online_users = []
in_game_users = []
for user_id, presence_data in results.items():
user_presence_type = presence_data.get("userPresenceType")
if user_presence_type == 1:
online_users.append(user_id)
elif user_presence_type == 2:
in_game_users.append(user_id)
return online_users, in_game_users

# Main script
batch_size = 15
delay = 10 # seconds
all_online_users = []
all_in_game_users = []

for i in range(0, len(user_ids), batch_size):


batch = user_ids[i:i + batch_size]
print(f"Checking batch: {batch}")
results = check_online_status_batch(batch)
online_users, in_game_users = process_results(results)
all_online_users.extend(online_users)
all_in_game_users.extend(in_game_users)
print(f"Online Users: {online_users}")
print(f"In-Game Users: {in_game_users}")
if i + batch_size < len(user_ids): # Add delay unless it's the last batch
print(f"Waiting {delay} seconds before next batch...")
time.sleep(delay)

print("\nFinal Results:")
print(f"All Online Users: {all_online_users}")
print(f"All In-Game Users: {all_in_game_users}")

You might also like