xxx777xxxASD
commited on
python file i feeded to Claude in order to make him write the extension
Browse files
main.py
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import json
|
3 |
+
|
4 |
+
def get_middle(val1, val2):
|
5 |
+
return int((val1+val2)/2)
|
6 |
+
|
7 |
+
|
8 |
+
def page_exists(url, API_KEY):
|
9 |
+
headers = {
|
10 |
+
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36',
|
11 |
+
'CH-API-KEY': API_KEY}
|
12 |
+
|
13 |
+
text_result = requests.get(url, headers=headers).text
|
14 |
+
json_result = json.loads(text_result)
|
15 |
+
|
16 |
+
if json_result["data"]["nodes"]:
|
17 |
+
return True
|
18 |
+
else:
|
19 |
+
return False
|
20 |
+
|
21 |
+
def find_page(url, max_value, API_KEY):
|
22 |
+
max_possible_result = max_value
|
23 |
+
|
24 |
+
next_to_check = max_possible_result
|
25 |
+
max_good_result = -1
|
26 |
+
min_none_result = 9999
|
27 |
+
count = 0
|
28 |
+
|
29 |
+
while True:
|
30 |
+
|
31 |
+
if page_exists(replace_page_number(url, next_to_check), API_KEY):
|
32 |
+
print("+ found characters at page ", next_to_check)
|
33 |
+
if max_good_result < next_to_check:
|
34 |
+
max_good_result = next_to_check
|
35 |
+
if max_good_result != -1 and min_none_result != 9999:
|
36 |
+
next_to_check = get_middle(max_good_result, min_none_result)
|
37 |
+
else:
|
38 |
+
next_to_check = int(next_to_check + next_to_check/2)
|
39 |
+
|
40 |
+
else:
|
41 |
+
print("- no characters at page ", next_to_check)
|
42 |
+
if min_none_result > next_to_check:
|
43 |
+
min_none_result = next_to_check
|
44 |
+
if max_good_result != -1 and min_none_result != 9999:
|
45 |
+
next_to_check = get_middle(max_good_result, min_none_result)
|
46 |
+
else:
|
47 |
+
next_to_check = int(next_to_check/2)
|
48 |
+
count += 1
|
49 |
+
|
50 |
+
if max_good_result == next_to_check:
|
51 |
+
print("\n[VALUE FOUND]: ", next_to_check)
|
52 |
+
print("[FINISHED IN]: ", count, " turns!")
|
53 |
+
break
|
54 |
+
|
55 |
+
|
56 |
+
def replace_page_number(url, new_page): # Changes page number in url
|
57 |
+
base_url, query_string = url.split('?', 1)
|
58 |
+
query_params = query_string.split('&')
|
59 |
+
updated_params = []
|
60 |
+
for param in query_params:
|
61 |
+
if param.startswith('page='):
|
62 |
+
updated_params.append(f'page={new_page}')
|
63 |
+
else:
|
64 |
+
updated_params.append(param)
|
65 |
+
|
66 |
+
updated_query_string = '&'.join(updated_params)
|
67 |
+
return f"{base_url}?{updated_query_string}"
|
68 |
+
|
69 |
+
test = "https://api.chub.ai/search?excludetopics=&first=20&page=1&namespace=characters&search=&include_forks=true&nsfw=true&nsfw_only=false&require_custom_prompt=false&require_images=false&require_expressions=false&nsfl=true&asc=false&min_tokens=50&max_tokens=100000&chub=true&require_lore=false&exclude_mine=true&require_lore_embedded=false&require_lore_linked=false&sort=default&topics=Female,Redhead&venus=true&count=false"
|
70 |
+
|