haha yes
This commit is contained in:
parent
eb723e5221
commit
2432117bf3
62
avatar-server.py
Normal file
62
avatar-server.py
Normal file
|
@ -0,0 +1,62 @@
|
|||
import os
|
||||
import json
|
||||
import urllib
|
||||
from urllib.request import Request, urlopen
|
||||
from pyfiglet import Figlet
|
||||
from flask import Flask, send_file, jsonify
|
||||
from subprocess import call
|
||||
from sys import platform as _platform
|
||||
|
||||
if _platform == 'win32' or _platform == 'win64':
|
||||
call('cls', shell=True)
|
||||
elif _platform == 'linux' or _platform == 'linux2':
|
||||
call('clear', shell=True)
|
||||
|
||||
f = Figlet(font='stop')
|
||||
print(f.renderText('Avatar-Server'))
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 1
|
||||
|
||||
avatar_dir = "avatars"
|
||||
|
||||
if not os.path.exists(avatar_dir):
|
||||
os.makedirs(avatar_dir)
|
||||
|
||||
@app.route("/status")
|
||||
def serverStatus():
|
||||
return jsonify({
|
||||
"response": 200,
|
||||
"status": 1
|
||||
})
|
||||
|
||||
@app.route("/<int:uid>")
|
||||
def serveAvatar(uid):
|
||||
avatarPath = "{}/0.png".format(avatar_dir)
|
||||
try:
|
||||
supportGIF = False
|
||||
url="https://new.ez-pp.farm/api/v1/users?id={}".format(uid)
|
||||
req = Request(url, headers={'User-Agent': 'Mozilla/5.0', 'X-Ripple-Token': 'yes'})
|
||||
web_byte = urlopen(req)
|
||||
web_read = web_byte.read()
|
||||
webpage = web_read.decode('utf-8')
|
||||
result = json.loads(webpage)
|
||||
|
||||
if result and result["privileges"]:
|
||||
if (result["privileges"] & 1 << 2) != 0:
|
||||
supportGIF = True
|
||||
|
||||
if os.path.isfile("{}/{}.gif".format(avatar_dir, uid)) and supportGIF:
|
||||
avatarPath = "{}/{}.gif".format(avatar_dir, uid)
|
||||
else:
|
||||
if os.path.isfile("{}/{}.png".format(avatar_dir, uid)):
|
||||
avatarPath = "{}/{}.png".format(avatar_dir, uid)
|
||||
except urllib.error.HTTPError:
|
||||
pass
|
||||
return send_file(avatarPath)
|
||||
|
||||
@app.errorhandler(404)
|
||||
def page_not_found(error):
|
||||
return send_file("{}/0.png".format(avatar_dir))
|
||||
|
||||
app.run(host="0.0.0.0", port=5000)
|
Loading…
Reference in New Issue
Block a user