imperialwool commited on
Commit
5b1514b
1 Parent(s): 09f5da5

forgor about routes lmao

Browse files
app.py CHANGED
@@ -27,11 +27,13 @@ def ratelimit_handler(e): return render_template('badgateway.html')
27
  @app.route('/yt/api/v1', methods=['POST'])
28
  @app.route('/recognize/api/v1', methods=['POST'])
29
  @app.route('/osu/api/v1', methods=['POST'])
 
30
  def emptyPath(): return {}
31
 
32
  @app.route('/yt/api/v1/<path:path>', methods=['POST'])
33
  @app.route('/recognize/api/v1/<path:path>', methods=['POST'])
34
  @app.route('/osu/api/v1/<path:path>', methods=['POST'])
 
35
  def emptyApiWA(path): return {"status": "error", "error_code": 100, "error_details": "No method like that found"}
36
 
37
  #icon
@@ -55,6 +57,13 @@ def getFull(): return ytApi.getFull(request)
55
  @app.route('/yt/api/v1/get-preview', methods=['POST'])
56
  def getPreview(): return ytApi.getPreview(request)
57
 
 
 
 
 
 
 
 
58
  ###############
59
  #OSU API
60
  @app.route('/osu/api/v1/find-song', methods=['POST'])
 
27
  @app.route('/yt/api/v1', methods=['POST'])
28
  @app.route('/recognize/api/v1', methods=['POST'])
29
  @app.route('/osu/api/v1', methods=['POST'])
30
+ @app.route('/jokes/api/v1', methods=['POST'])
31
  def emptyPath(): return {}
32
 
33
  @app.route('/yt/api/v1/<path:path>', methods=['POST'])
34
  @app.route('/recognize/api/v1/<path:path>', methods=['POST'])
35
  @app.route('/osu/api/v1/<path:path>', methods=['POST'])
36
+ @app.route('/jokes/api/v1/<path:path>', methods=['POST'])
37
  def emptyApiWA(path): return {"status": "error", "error_code": 100, "error_details": "No method like that found"}
38
 
39
  #icon
 
57
  @app.route('/yt/api/v1/get-preview', methods=['POST'])
58
  def getPreview(): return ytApi.getPreview(request)
59
 
60
+ ###############
61
+ #JOKES API
62
+ @app.route('/jokes/api/v1/get', methods=['POST'])
63
+ def getJoke(): return jokes.getJoke(request)
64
+ @app.route('/jokes/api/v1/sources', methods=['POST'])
65
+ def getJokesSources(): return jokes.getSources(request)
66
+
67
  ###############
68
  #OSU API
69
  @app.route('/osu/api/v1/find-song', methods=['POST'])
routes/__init__.py CHANGED
@@ -1,3 +1,4 @@
 
1
  from .ytApi import *
2
  from .osuApi import *
3
  from .helpers import *
 
1
+ from .jokes import *
2
  from .ytApi import *
3
  from .osuApi import *
4
  from .helpers import *
routes/jokes/__init__.py CHANGED
@@ -1 +1,2 @@
1
- from .getJoke import *
 
 
1
+ from .getJoke import *
2
+ from .getSources import *
routes/jokes/getJoke.py CHANGED
@@ -1,5 +1,6 @@
1
  import re
2
  from .. import helpers
 
3
  from random import randint
4
  from requests import get as reqget
5
  from random import choice as randchoice
@@ -11,9 +12,7 @@ def getJoke(request):
11
  else: lang = lang.lower()
12
 
13
  source = helpers.getFromRequest(request, "source")
14
- availableSources = {
15
- "ru": ["nekdo", "baneks", "anekdot", "shytok", "anekdotytoday", "4tob", "anepedia"]
16
- }
17
  if not source or source not in availableSources[lang]: source = randchoice(availableSources[lang])
18
 
19
  try:
@@ -40,6 +39,7 @@ def getJoke(request):
40
  elif source == "anepedia":
41
  site = reqget("https://www.anepedia.mobi/%D0%A1%D0%BB%D1%83%D1%87%D0%B0%D0%B9%D0%BD%D1%8B%D0%B9_%D0%B0%D0%BD%D0%B5%D0%BA%D0%B4%D0%BE%D1%82").content.decode()
42
  joke = re.sub(r'<a\b[^>]*>', '', site.partition('<div align="left" class="bodytext">')[2].partition("<img src")[0]).replace("</a>", "").replace("<br />", "\n").replace("<br/>", "\n").replace("<br>", "\n").strip()
 
43
 
44
  return {"status": "pass", "details": {"code": 200, "result": joke}}
45
  except Exception as e:
 
1
  import re
2
  from .. import helpers
3
+ from . import getSources
4
  from random import randint
5
  from requests import get as reqget
6
  from random import choice as randchoice
 
12
  else: lang = lang.lower()
13
 
14
  source = helpers.getFromRequest(request, "source")
15
+ availableSources = getSources()
 
 
16
  if not source or source not in availableSources[lang]: source = randchoice(availableSources[lang])
17
 
18
  try:
 
39
  elif source == "anepedia":
40
  site = reqget("https://www.anepedia.mobi/%D0%A1%D0%BB%D1%83%D1%87%D0%B0%D0%B9%D0%BD%D1%8B%D0%B9_%D0%B0%D0%BD%D0%B5%D0%BA%D0%B4%D0%BE%D1%82").content.decode()
41
  joke = re.sub(r'<a\b[^>]*>', '', site.partition('<div align="left" class="bodytext">')[2].partition("<img src")[0]).replace("</a>", "").replace("<br />", "\n").replace("<br/>", "\n").replace("<br>", "\n").strip()
42
+ else: return {"status": "error", "details": { "error_code": 133, "error_details": "Invalid source" }}, 400
43
 
44
  return {"status": "pass", "details": {"code": 200, "result": joke}}
45
  except Exception as e:
routes/jokes/getSources.py ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ def sources():
2
+ return {
3
+ "ru": ["nekdo", "baneks", "anekdot", "shytok", "anekdotytoday", "4tob", "anepedia"]
4
+ }