Conditions | 3 |
Total Lines | 17 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | #by Linaname |
||
32 | def get_image(query): |
||
33 | params = { |
||
34 | "page": "dapi", |
||
35 | "s": "post", |
||
36 | "q": "index", |
||
37 | "json": "1", |
||
38 | "tags": query, |
||
39 | } |
||
40 | response = requests.get("https://gelbooru.com/index.php", params=params) |
||
41 | if not response.text: |
||
42 | return None, None |
||
43 | result_list = response.json() |
||
44 | if not result_list: |
||
45 | return None, None |
||
46 | post = random.choice(result_list) |
||
47 | direct_link, page_link = post.get("file_url"), "https://gelbooru.com/index.php?page=post&s=view&id="+str(post.get("id")) |
||
48 | return direct_link, page_link |
||
49 |