-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsabe.py
87 lines (68 loc) · 2.6 KB
/
sabe.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
# Sanallaştırılmış bilgisayar verisi ve kolay web sayfası oluşturucusu
from flask import Flask, render_template, request
from colorama import init
from termcolor import colored
import webbrowser
import flask
from waitress import serve
init()
class Sabe:
"""Sabe web uygulamarını daha kolay ve hızlı şekilde yapabilmek için yazılmıştır"""
def __init__(self):
self.app = Flask(__name__)
self.route_list = []
self.url_list = []
self.version = "2.0.1"
def info(self):
print("Sabe © Kerem ata\n\nSabe kolay web sitesi oluşturmak için yazılmış bir frameworkdür\nTemelinde flask bulunmaktadır")
def version(self):
"""return version"""
return self.version
def render_website(self, route, url):
"""get file content render content (cannot get css or js file(s))"""
try:
import requests
except:
print(colored("requests modülü bulunamadı", "red"))
try:
url = requests.get(url)
@self.app.route(route)
def page():
return url.text
self.url_list.append(url)
except requests.exceptions.MissingSchema:
#print(colored(f"Geçersiz Url: Bunu mu demek istedinizi? (https://{url})", "red"))
print(colored(f"Geçersiz Url: Bunu mu demek istediniz? (https://{url})", "red"))
def url_routes(self):
"""return all websites urls"""
return(self.url_routes)
def routes(self):
"""return all routes"""
return(self.route_list)
def route(self, route, code):
"""add route for application"""
self.route_list.append(route)
@self.app.route(route)
def page():
return code
def error_page_add(self, error_code, code):
"""Add error page for application"""
if error_code == "404":
@self.app.errorhandler(404)
def not_found(e):
return code
elif error_code == "500":
@self.app.errorhandler(500)
def server_error(e):
return code
else:
print(colored(f"Hata kodu {error_code} bulunamadı", "red"))
def render_file(self, filename, encoding="utf8"):
"""Render files (default encoding=utf8)"""
with open(filename, encoding=encoding) as filecontant:
return filecontant.read()
def run(self):
"""Run application"""
self.app.run()
def __str__(self):
return "<Sabe>"