Spaces:
Sleeping
Sleeping
File size: 2,140 Bytes
1b46501 9b5d53c 1b46501 2e1e8ea 1b46501 9b5d53c 1b46501 |
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 |
import os
import re
import random
from supabase.client import ClientOptions
from supabase import create_client, Client
from dotenv import load_dotenv
load_dotenv()
user_name_to_range = {'Kerem': (700001, 900000), 'Mehmet': (1, 500000), 'Ege': (500001, 700000), 'Ömer': (700001, 1013817)}
url: str = os.environ.get("SUPABASE_URL")
key: str = os.environ.get("SUPABASE_KEY")
supabase: Client = create_client(url, key, options=ClientOptions(postgrest_client_timeout=300))
def eso_replace_string(from_: str, to_: str, text: str):
# Regex pattern:
# \w*1\w* - En az bir '1' içeren kelimeleri bulur.
# Ancak bu, sadece "1" içeren tek karakterleri de içerebilir ve bu yüzden toplam uzunluğu kontrol ediyoruz.
pattern = fr'\b\w*{from_}\w*\b'
# Metindeki tüm kelimeler üzerinde dön
for word in re.findall(pattern, text):
# Eğer kelime en az 2 karakter içeriyorsa ve en az bir harf içeriyorsa
if len(word) > 1 and re.search("[a-zA-Z]", word):
modified_word = word.replace(from_, to_)
text = text.replace(word, modified_word)
return text
# Dosyayı açıp içeriğini okuyan ve içeriği bir string olarak döndüren fonksiyon
def dosyayi_oku(dosya_yolu):
try:
with open(dosya_yolu, 'r', encoding='iso-8859-9') as dosya:
icerik = dosya.read()
return icerik
except FileNotFoundError:
print("Dosya bulunamadı.")
except Exception as e:
print(f"Bir hata oluştu: {e}")
def get_next_row_id(user_name: str):
row_range = user_name_to_range[user_name]
data, count = supabase.table('eso-tr').select('id').gte('id', row_range[0]).lt('id', row_range[1]).eq('done', False).order('id', desc=False).limit(1).execute()
text_id = data[1][0]['id']
return text_id
def get_text_by_row_id(id: int):
data, count = supabase.table('eso-tr').select('text').eq('id', id).limit(1).execute()
text = data[1][0]['text']
return text
def add_updated_text_to_db(id: int, text: str):
data, count = supabase.table('eso-tr').update({'updated_text': text, 'done': True}).eq('id', id).execute()
|