File size: 1,846 Bytes
82676b8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""حزمة المساعدات العامة المستخدمة في النظام"""

import streamlit as st
import pandas as pd
import numpy as np
import os
import sqlite3

from .utils import (
    create_directory_if_not_exists,
    get_data_folder,
    format_time,
    get_user_info,
    load_css,
    render_credits,
    load_icons,
    format_number,
    format_currency,
    styled_button,
    filter_dataframe,
    get_file_extension,
    extract_numbers_from_text
)

def get_connection():
    """
    إنشاء اتصال وهمي لقاعدة البيانات للاستخدام عند عدم توفر اتصال PostgreSQL
    
    الإرجاع:
        اتصال وهمي لقاعدة البيانات
    """
    # إنشاء مجلد البيانات إذا لم يكن موجوداً
    data_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'data')
    os.makedirs(data_dir, exist_ok=True)
    
    # إنشاء اتصال قاعدة بيانات SQLite محلية
    db_path = os.path.join(data_dir, 'local_db.sqlite')
    conn = sqlite3.connect(db_path)
    
    # إعادة محاكاة سلوك اتصال PostgreSQL
    conn.execute = conn.cursor().execute
    
    # إضافة وظيفة وهمية للاقتطاع (commit) والإغلاق
    original_close = conn.close
    def enhanced_close():
        conn.commit()
        original_close()
    conn.close = enhanced_close
    
    return conn

__all__ = [
    'create_directory_if_not_exists',
    'get_data_folder',
    'format_time',
    'get_user_info',
    'load_css',
    'render_credits',
    'load_icons',
    'format_number',
    'format_currency',
    'styled_button',
    'filter_dataframe',
    'get_file_extension',
    'extract_numbers_from_text',
    'get_connection'
]