-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathint4_reader.py
More file actions
221 lines (188 loc) · 118 KB
/
int4_reader.py
File metadata and controls
221 lines (188 loc) · 118 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import os
import importlib.util
import time
import math
from datetime import datetime
import subprocess
import requests # Requests modülünü dahil ettik
# Modül yükleme fonksiyonu
def load_module(module_name):
try:
if module_name.endswith(".py"):
spec = importlib.util.spec_from_file_location("module", module_name)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
else:
raise ImportError("Sadece .py uzantılı dosyalar yüklenebilir.")
except Exception as e:
print(f"Modül yüklenirken hata: {e}")
# print fonksiyonu (Python'daki print işlevi)
def int4_print(message):
try:
print(message)
except Exception as e:
print(f"Print hatası: {e}")
# WiFi ağlarını tarama
def scan_wifi():
try:
print("WiFi ağları taranıyor...")
result = subprocess.run(['nmcli', 'dev', 'wifi'], capture_output=True, text=True)
print(result.stdout)
except Exception as e:
print(f"WiFi tarama hatası: {e}")
# WiFi ağına bağlanma
def connect_wifi(ssid, password):
try:
print(f"{ssid} ağına bağlanıyor...")
subprocess.run(['nmcli', 'dev', 'wifi', 'connect', ssid, 'password', password], check=True)
print(f"{ssid} ağına başarıyla bağlanıldı.")
except Exception as e:
print(f"Bağlantı hatası: {e}")
# HTTP GET isteği
def http_get(url):
try:
response = requests.get(url)
if response.status_code == 200:
print(f"GET isteği başarılı! Yanıt: {response.text}")
else:
print(f"GET isteği başarısız! Hata Kodu: {response.status_code}")
except Exception as e:
print(f"GET isteği hatası: {e}")
# HTTP POST isteği
def http_post(url, data):
try:
response = requests.post(url, data=data)
if response.status_code == 200:
print(f"POST isteği başarılı! Yanıt: {response.text}")
else:
print(f"POST isteği başarısız! Hata Kodu: {response.status_code}")
except Exception as e:
print(f"POST isteği hatası: {e}")
# JSON verisi işleme
def handle_json(url):
try:
response = requests.get(url)
if response.status_code == 200:
data = response.json()
print(f"JSON verisi: {data}")
else:
print(f"JSON isteği başarısız! Hata Kodu: {response.status_code}")
except Exception as e:
print(f"JSON işleme hatası: {e}")
# Web sayfası çekme
def fetch_webpage(url):
try:
response = requests.get(url)
if response.status_code == 200:
print(f"Web sayfası içeriği: {response.text[:200]}...") # İlk 200 karakteri yazdırıyoruz
else:
print(f"Web sayfası çekme hatası! Hata Kodu: {response.status_code}")
except Exception as e:
print(f"Web sayfası hatası: {e}")
# Fonksiyonlar ve işlemler
def test(module_name):
try:
__import__(module_name)
print(f"{module_name} başarıyla yüklü.")
except ImportError:
print(f"{module_name} eksik.")
def wait(seconds):
try:
time.sleep(int(seconds))
except ValueError:
print("Hatalı bekleme süresi.")
def each(iterable, function):
try:
for item in iterable:
function(item)
except Exception as e:
print(f"Each döngüsü hatası: {e}")
def block(function, *args):
try:
return function(*args)
except Exception as e:
print(f"Block hatası: {e}")
def conditional(statement, true_block, false_block):
try:
if statement:
block(true_block)
else:
block(false_block)
except Exception as e:
print(f"Koşul hatası: {e}")
# switch fonksiyonu (Koşul yapıları için)
def switch(value, *cases):
for case in cases:
if case[0] == value:
return case[1]()
return None
# assert fonksiyonu (Test ve doğrulama)
def assert_equal(expected, actual):
if expected != actual:
raise AssertionError(f"Beklenen: {expected}, Gerçek: {actual}")
# int4 okuyucu (Ruby diline özgü kodlar)
def int4_reader(file_path):
if not os.path.exists(file_path):
print("Dosya bulunamadı.")
return
with open(file_path, "r", encoding="utf-8") as file:
for line in file:
line = line.strip()
if not line or line.startswith("#"): # Yorum satırlarını atla
continue
try:
if line.startswith("Load"):
module_name = line.split("Load")[-1].strip()
load_module(module_name)
elif line.startswith("print"):
message = line.split("print", 1)[-1].strip()
int4_print(message)
elif line.startswith("def"):
parts = line.split(":", 1)
function_name = parts[0].replace("def", "").strip()
function_body = parts[1].strip()
define_function(function_name, function_body)
elif line.startswith("test"):
module_name = line.split("test")[-1].strip()
test(module_name)
elif line.startswith("wait"):
seconds = line.split("wait")[-1].strip()
wait(seconds)
elif line.startswith("scan_wifi"):
scan_wifi()
elif line.startswith("connect_wifi"):
params = line.split("connect_wifi")[-1].strip()
ssid, password = params.split(",")
connect_wifi(ssid.strip(), password.strip())
elif line.startswith("disconnect_wifi"):
disconnect_wifi()
elif line.startswith("get_connected_wifi"):
get_connected_wifi()
elif line.startswith("http_get"):
url = line.split("http_get")[-1].strip()
http_get(url)
elif line.startswith("http_post"):
params = line.split("http_post")[-1].strip()
url, data = params.split(",")
http_post(url.strip(), data.strip())
elif line.startswith("handle_json"):
url = line.split("handle_json")[-1].strip()
handle_json(url)
elif line.startswith("fetch_webpage"):
url = line.split("fetch_webpage")[-1].strip()
fetch_webpage(url)
else:
os.system(line)
except Exception as e:
print(f"Hata: {e}")
pass_card()
# pass_card (hata yakalama ve geçiş komutu)
def pass_card():
pass
# Fonksiyon çalıştırma örneği
if __name__ == "__main__":
try:
int4_reader("ornek.int4") # .int4 dosyasını çalıştır
except Exception as e:
print(f"Genel hata: {e}")
pass_card()