<commit_before>from time import sleep

from providers.popularity.provider import PopularityProvider
from utils.torrent_util import remove_bad_torrent_matches, torrent_to_movie

IDENTIFIER = "rarbg"

# API Documentation: https://torrentapi.org/apidocs_v2.txt

class Provider(PopularityProvider):
    def get_popular(self):
        base = "https://torrentapi.org/pubapi_v2.php?"

        token_params = {
            "get_token": "get_token",
            "app_id": "<PASSWORD>",
        }
        url_token = base + self.urlencode(token_params)
        data_token = self.parse_json(url_token, cache=False)

        params = {
            "token": data_token["token"],
            "mode": "list",
            "sort": "seeders",
            "category": "14;48;17;44;45;47;42;46",
            "limit": 100,
            "app_id": "nephele",
        }

        url = base + self.urlencode(params)
        data_movies = self.parse_json(url, cache=False)

        tries = 1
        while "error" in data_movies and tries < 10:
            print("Error returned, retrying in 1 sec")
            sleep(1)
            data_movies = self.parse_json(url, cache=False)
            tries += 1

        names = [item["filename"] for item in data_movies["torrent_results"]]
<commit_msg>Sleep 2 seconds between requests.<commit_after>from time import sleep

from providers.popularity.provider import PopularityProvider
from utils.torrent_util import remove_bad_torrent_matches, torrent_to_movie

IDENTIFIER = "rarbg"

# API Documentation: https://torrentapi.org/apidocs_v2.txt

class Provider(PopularityProvider):
    def get_popular(self):
        base = "https://torrentapi.org/pubapi_v2.php?"

        token_params = {
            "get_token": "get_token",
            "app_id": "<PASSWORD>",
        }
        url_token = base + self.urlencode(token_params)
        data_token = self.parse_json(url_token, cache=False)

        sleep(2)

        params = {
            "token": data_token["token"],
            "mode": "list",
            "sort": "seeders",
            "category": "14;48;17;44;45;47;42;46",
            "limit": 100,
            "app_id": "nephele",
        }
        url = base + self.urlencode(params)
        data_movies = self.parse_json(url, cache=False)

        tries = 1
        while "error" in data_movies and tries < 10:
            print("Error returned, retrying in 1 sec")
            sleep(2)
            data_movies = self.parse_json(url, cache=False)
            tries += 1

        names = [item["filename"] for item in data_movies["torrent_results"]]

{'fraction_non_alphanumeric': 0.11776136805285659, 'fraction_numerical': 0.021764477263894286, 'mean_word_length': 2.391304347826087, 'pattern_counts': {'":': 16, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3195563', 'n_tokens_mistral': 845, 'n_tokens_neox': 790, 'n_words': 167}