File size: 2,590 Bytes
fd1fd71
 
 
 
 
 
 
 
84e7abf
fd1fd71
 
 
d885278
fd1fd71
 
cdfff16
 
 
fd1fd71
 
 
 
 
 
cdfff16
 
 
 
 
 
 
 
 
 
fd1fd71
cdfff16
 
 
 
fd1fd71
cdfff16
 
fd1fd71
cdfff16
 
 
fd1fd71
 
 
 
 
d885278
 
cdfff16
 
 
 
7f45073
cdfff16
7f45073
cdfff16
 
d885278
cdfff16
fd1fd71
 
cdfff16
 
 
fd1fd71
cdfff16
 
d885278
cdfff16
 
 
 
 
 
 
 
d885278
fd1fd71
d885278
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
import enkacard
import enkacard.encbanner
import enkanetwork
import asyncio
from flask import Flask, jsonify, request
import requests
from io import BytesIO
from enkanetwork import EnkaNetworkAPI
import os

enka_update = EnkaNetworkAPI()

app = Flask(__name__)

async def card(id, designtype):
    async with enkacard.encbanner.ENC(uid = str(id)) as encard:
        return await encard.creat(template = (2 if str(designtype) == "2" else 1))
    
@app.route("/<int:id>")
def characters(id):
    try:
        characters = []
        result = asyncio.run(card(id, request.args.get('design')))
        for dt in result.card:
         with BytesIO() as byte_io: 
            dt.card.save(byte_io, "PNG")
            byte_io.seek(0)
            image_url = upload_image(byte_io)
            
            characters.append({
                "name": dt.name,
                "url": image_url
            })
        return jsonify({'response': characters}) 
    except enkanetwork.exception.VaildateUIDError:
        # return jsonify({'error': 'Invalid UID. Please check your UID.'}), 400 

        return jsonify({'error': 'Invalid UID. Please check your UID.'})

    except enkacard.enc_error.ENCardError:
        # return jsonify({'error': 'Enable display of the showcase in the game or add characters there.'}), 400 
        return jsonify({'error': 'Enable display of the showcase in the game or add characters there.'})
    except Exception as e:

        return jsonify({'error': 'UNKNOWN ERR' + e.__str__()})


@app.route("/")
def hello_world():
    return 'AMERICA YA HALLO!!'

@app.route("/update_char")
def upload():
    data_dir = "/tmp/data"

    if not os.path.exists(data_dir):
        os.makedirs(data_dir)

    data_dir = "/tmp/langs"

    if not os.path.exists(data_dir):
        os.makedirs(data_dir)
    asyncio.run(update_genshin())
    return 'Update smth ig!!'

def upload_image(data):
    url = "https://telegra.ph/upload"
    files = {'file': ('file', data, "image/png")}  
    response = requests.post(url, files=files)
    
    if response.status_code != 200:
        raise Exception(f"HTTP Error: {response.status_code}")
    
    try:
        body = response.json()
        if isinstance(body, list) and 'src' in body[0]:
            return "https://telegra.ph" + body[0]['src']
        else:
            raise Exception(f"Telegraph error: {body.get('error', 'Unknown error')}")
    except (ValueError, KeyError, IndexError) as e:
        raise Exception(f"Failed to parse response: {str(e)}")
    
if __name__ == "__main__":
    app.run(debug=False, use_reloader=False)