ztxi / app.py
Geek7's picture
Update app.py
4f67db7 verified
raw
history blame
3.46 kB
from flask import Flask, jsonify
from flask_cors import CORS
import subprocess
import IP2Location
app = Flask(__name__)
CORS(app) # Enable CORS for all routes
# Load IPv4 & IPv6 databases (Download and place in same folder)
IPV4_BIN = "PX2.LITE.IPV4.BIN"
IPV6_BIN = "PX2.LITE.IPV6.BIN"
db_ipv4 = IP2Location.IP2Location(IPV4_BIN)
db_ipv6 = IP2Location.IP2Location(IPV6_BIN)
@app.route('/')
def home():
return ""
# Define ECPM values for different countries based on timezones
ECPM_VALUES = {
"America/New_York": 60, # USA (Eastern)
"America/Chicago": 58, # USA (Central)
"America/Denver": 55, # USA (Mountain)
"America/Los_Angeles": 52, # USA (Pacific)
"Europe/London": 70, # UK
"Europe/Paris": 65, # France
"Europe/Berlin": 67, # Germany
"Europe/Zurich": 66, # Switzerland
"Europe/Copenhagen": 64, # Denmark
"Europe/Madrid": 63, # Spain
"Europe/Rome": 62, # Italy
"Europe/Stockholm": 68, # Sweden
"Europe/Oslo": 69, # Norway
"America/Sao_Paulo": 45, # Brazil
"Australia/Sydney": 75, # Australia
"Europe/Chisinau": 55, # Moldova
"Europe/Amsterdam": 66, # Netherlands
"Europe/Lisbon": 61, # Portugal
"Europe/Brussels": 64, # Belgium
"Pacific/Auckland": 80 # New Zealand
}
@app.route('/get_ecpm_player', methods=['GET'])
def get_ecpm():
# Get timezone from request
user_timezone = request.args.get('timezone', 'Unknown')
# Get corresponding ECPM value
ecpm_value = ECPM_VALUES.get(user_timezone, 50) # Default to 50 if not found
return jsonify({"ecpm": ecpm_value, "timezone": user_timezone})
def check_proxy(ip):
try:
db = db_ipv6 if ":" in ip else db_ipv4 # Use correct database
record = db.get_all(ip)
proxy_type = record.proxy_type
return proxy_type not in ["", "-"] # Proxy detected if type is not empty
except Exception as e:
print(f"Error checking IP: {e}")
return False
@app.route("/check-ip", methods=["GET"])
def check_ip():
user_ip = request.headers.get("X-Forwarded-For", request.remote_addr) # Get real IP
is_proxy = check_proxy(user_ip)
return jsonify({
"ip": user_ip,
"proxy_detected": is_proxy
})
@app.route('/get_latest_version', methods=['GET'])
def get_latest_version():
latest_version = "31.0" # Use snake_case for internal Python variables
return jsonify({'latestVersion': latest_version}) # Use camelCase in JSON response
@app.route('/get_latest_version2', methods=['GET'])
def get_latest_version2():
latest_version = "7.0" # Use snake_case for internal Python variables
return jsonify({'latestVersion': latest_version}) # Use camelCase in JSON response
# API endpoint returning hardcoded features
@app.route('/api/features')
def get_features():
features = [
# {"name": "πŸš€ Fast", "description": "Quick response time with optimized performance."}
]
return jsonify(features)
# API endpoint returning hardcoded features
@app.route('/api/features2')
def get_features2():
features = [
# {"name": "πŸš€ Fast", "description": "Quick response time with optimized performance."}
]
return jsonify(features)
if __name__ == '__main__':
subprocess.Popen(["python", "wk.py"]) # Start awake.py
app.run(host='0.0.0.0', port=7860)