-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
tests.py
165 lines (136 loc) · 5.62 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import argparse
import aiohttp
import asyncio
import booru
import os
class Wrapper(object):
def __init__(self):
self.gelbooru = booru.Gelbooru()
self.rule34 = booru.Rule34()
self.tbib = booru.Tbib()
self.safebooru = booru.Safebooru()
self.xbooru = booru.Xbooru()
self.realbooru = booru.Realbooru()
self.hypnohub = booru.Hypnohub()
self.danbooru = booru.Danbooru()
self.atfbooru = booru.Atfbooru()
self.yandere = booru.Yandere()
self.konachan = booru.Konachan()
self.konachan_net = booru.Konachan_Net()
self.lolibooru = booru.Lolibooru()
self.e621 = booru.E621()
self.e926 = booru.E926()
self.derpibooru = booru.Derpibooru()
self.furbooru = booru.Furbooru()
self.behoimi = booru.Behoimi()
self.paheal = booru.Paheal()
@staticmethod
async def fetch(imgboard: str, search: str):
"""Fetches the data from safebooru.
Parameters
----------
imgboard : str
The imageboard to be searched.
search : str
The search term to be used.
Returns
-------
dict
The data that represents the search from separate booru
"""
data = await imgboard.search(query=search)
print("Data", data, len(booru.resolve(data)))
image = await imgboard.search_image(query=search)
print("Image", image, len(booru.resolve(image)))
gacha = await imgboard.search(query=search, gacha=True)
print("Gacha", gacha)
async def tags_completion(imgboard: str, search: str, base: str):
tags = await imgboard.find_tags(query=search)
print(base, tags)
Base = Wrapper()
Internal = booru.utils.constant.Api()
parse = argparse.ArgumentParser(description="Booru tests")
parse.add_argument("-api", action="store_true")
parse.add_argument("-build", action="store_true")
parse.add_argument("-gelbooru", action="store", type=str)
parse.add_argument("-rule34", action="store", type=str)
parse.add_argument("-tbib", action="store", type=str)
parse.add_argument("-safebooru", action="store", type=str)
parse.add_argument("-xbooru", action="store", type=str)
parse.add_argument("-realbooru", action="store", type=str)
parse.add_argument("-hypnohub", action="store", type=str)
parse.add_argument("-danbooru", action="store", type=str)
parse.add_argument("-atfbooru", action="store", type=str)
parse.add_argument("-yandere", action="store", type=str)
parse.add_argument("-konachan", action="store", type=str)
parse.add_argument("-konachan_net", action="store", type=str)
parse.add_argument("-lolibooru", action="store", type=str)
parse.add_argument("-e6", action="store", type=str)
parse.add_argument("-e9", action="store", type=str)
parse.add_argument("-derpibooru", action="store", type=str)
parse.add_argument("-furbooru", action="store", type=str)
parse.add_argument("-behoimi", action="store", type=str)
parse.add_argument("-paheal", action="store", type=str)
parse.add_argument("-changelog", action="store_true")
parse.add_argument("-wildcard", action="store", type=str)
args = parse.parse_args()
async def main():
if args.gelbooru:
await Wrapper.fetch(Base.gelbooru, args.gelbooru)
elif args.rule34:
await Wrapper.fetch(Base.rule34, args.rule34)
elif args.tbib:
await Wrapper.fetch(Base.tbib, args.tbib)
elif args.safebooru:
await Wrapper.fetch(Base.safebooru, args.safebooru)
elif args.xbooru:
await Wrapper.fetch(Base.xbooru, args.xbooru)
elif args.realbooru:
await Wrapper.fetch(Base.realbooru, args.realbooru)
elif args.hypnohub:
await Wrapper.fetch(Base.hypnohub, args.hypnohub)
elif args.danbooru:
await Wrapper.fetch(Base.danbooru, args.danbooru)
elif args.atfbooru:
await Wrapper.fetch(Base.atfbooru, args.atfbooru)
elif args.yandere:
await Wrapper.fetch(Base.yandere, args.yandere)
elif args.konachan:
await Wrapper.fetch(Base.konachan, args.konachan)
elif args.konachan_net:
await Wrapper.fetch(Base.konachan_net, args.konachan_net)
elif args.lolibooru:
await Wrapper.fetch(Base.lolibooru, args.lolibooru)
elif args.e6:
await Wrapper.fetch(Base.e621, args.e6)
elif args.e9:
await Wrapper.fetch(Base.e926, args.e9)
elif args.derpibooru:
await Wrapper.fetch(Base.derpibooru, args.derpibooru)
elif args.furbooru:
await Wrapper.fetch(Base.furbooru, args.furbooru)
elif args.behoimi:
await Wrapper.fetch(Base.behoimi, args.behoimi)
elif args.paheal:
await Wrapper.fetch(Base.paheal, args.paheal)
elif args.wildcard:
await Wrapper.tags_completion(Base.danbooru, args.wildcard, Base.danbooru)
await Wrapper.tags_completion(Base.gelbooru, args.wildcard, Base.gelbooru)
await Wrapper.tags_completion(Base.rule34, args.wildcard, Base.rule34)
await Wrapper.tags_completion(Base.yandere, args.wildcard, Base.yandere)
elif args.build:
print(booru.__version__)
elif args.changelog:
os.system('git-changelog -o CHANGELOG.md -s angular -t angular .')
elif args.api:
for api in booru.utils.constant.list_api():
res = booru.utils.constant.get_hostname(api)
if res == "http://behoimi.org":
Internal.headers = Internal.behoimi_bypass
async with aiohttp.ClientSession(headers=Internal.headers) as resp:
async with resp.get(res) as data:
print(f"{api} : {data.status}")
else:
print("No arguments given")
if __name__ == "__main__":
asyncio.run(main())