0

I created a username checker against the Ubisoft api. However the requests are fairly slow so I wanted to speed it up, and one thing I thought of was multithreading. I know about pools and such but I've got no clue how to use it in an api request like here.

def check():
    global checkedCount
    global availableCount

    headers = {

                'Method':'GET',
                'Authority':'public-ubiservices.ubi.com',
                'referer':'https://lb-prod-acc_ount-pdc.ubisoft.com',
                'Ubi-AppId':'c5393f10-7ac7-4b4f-90fa-21f8f3451a04',
                'Authorization': authToken,
                'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36',
                'Ubi-RequestedPlatformType':'uplay'}

    for name in usernameList:
        r = requests.get("https://public-ubiservices.ubi.com/v3/profiles?nameOnPlatform=" + name + "&platformType=uplay", headers=headers)  

        while r.status_code != 200: #retry on rate limit
            r = requests.get("https://public-ubiservices.ubi.com/v3/profiles?nameOnPlatform=" + name + "&platformType=uplay", headers=headers)  

        if not r.json()['profiles']:
            availableCount += 1
            checkedCount += 1
            print(f"{Fore.CYAN}[$]{Fore.RESET} {name} is available")

        else: 
            checkedCount += 1
            print(f"{Fore.CYAN}[$]{Fore.RESET} {name} is unavailable")

Don't say it's a duplicate question. Because I'm not trying to use multiple url's like other questions.

  • there shouldn't be much difference between using different urls and the same url with different arguments so this is a duplicate – Matiiss Sep 14 '21 at 19:43
  • But you are generating unique urls per request. Generally, you would take the stuff in the `for` and put it in a function. Then create a thread pool to run that function and feed it `usernameList`. If you see examples using multiple urls, just replace the urls with your names and build the urls in the worker funciton. – tdelaney Sep 14 '21 at 19:43
  • @tdelaney i'm stuck at how to implement it into the code. i'm trying [this example (solution 1)](https://stackoverflow.com/a/62007797/16427319). can you show a quick example of how it would be with my code? –  Sep 14 '21 at 20:33

0 Answers0