class Setting(object): #path rss_icon_path = "" main_log_path = '' #public config log_enable = True debuging = True persian_timezone_seconds = 0 home_page_news = 0 crawl_interval = 0 log_level=0 #shared objects sid = None log = LogUtil(enable=False) db = {} database = MySQLDatabase(None) def __init__(self, params): ''' Constructor ''' pass
class Setting(object): #path rss_icon_path = "" main_log_path = '' #public config log_enable = True debuging = True persian_timezone_seconds = 0 home_page_news = 0 crawl_interval = 0 log_level=0 #shared objects sid = None log = LogUtil(enable=False) db = {} database = MySQLDatabase(None) def __init__(self, params): pass def init_setting(app_info): mode = app_info.get('app:main','mode') Setting.db['host'] = app_info.get('yeksatr:config','db_host') Setting.db['db_name'] = app_info.get('yeksatr:config','db_name') Setting.db['user'] = app_info.get('yeksatr:config','db_user') Setting.db['pass'] = app_info.get('yeksatr:config','db_pass') Setting.mode = mode Setting.rss_icon_path = app_info.get('yeksatr:config','rss_icon_path') Setting.main_log_path = app_info.get('yeksatr:config','main_log_path') #public config Setting.log_enable = app_info.getboolean('yeksatr:config','log_enable') Setting.debuging = app_info.getboolean('yeksatr:config','debuging') Setting.persian_timezone_seconds =app_info.getint('yeksatr:config','persian_timezone_seconds') Setting.home_page_news = app_info.getint('yeksatr:config','home_page_news') Setting.crawl_interval = app_info.getint('yeksatr:config','crawl_interval') Setting.log_level = app_info.getint('yeksatr:config','log_level') Setting.log = LogUtil(Setting.main_log_path,Setting.log_level,Setting.log_enable) def init_db(): try: try: Setting.database.close() except Exception as e: Setting.log.log_exception(e,' error in closing previus connection (Setting.init_db): ') pass Setting.database.init(Setting.db['db_name'], host=Setting.db['host'],passwd = Setting.db['pass'], user = Setting.db['user']) except Exception as ex: Setting.log.log_exception(ex,' error in connecting to database: ') def test(request,a): print(request,a)
def InitSetting(app_info): mode = app_info.get('app:main','mode') Setting.db['host'] = app_info.get('yeksatr:config','db_host') Setting.db['db_name'] = app_info.get('yeksatr:config','db_name') Setting.db['user'] = app_info.get('yeksatr:config','db_user') Setting.db['pass'] = app_info.get('yeksatr:config','db_pass') Setting.rss_icon_path = app_info.get('yeksatr:config','rss_icon_path') Setting.main_log_path = app_info.get('yeksatr:config','main_log_path') #public config Setting.log_enable = app_info.getboolean('yeksatr:config','log_enable') Setting.debuging = app_info.getboolean('yeksatr:config','debuging') Setting.persian_timezone_seconds =app_info.getint('yeksatr:config','persian_timezone_seconds') Setting.home_page_news = app_info.getint('yeksatr:config','home_page_news') Setting.crawl_interval = app_info.getint('yeksatr:config','crawl_interval') Setting.log_level = app_info.getint('yeksatr:config','log_level') Setting.log = LogUtil(Setting.main_log_path,Setting.log_level,Setting.log_enable)
class Setting(object): temp_var = "ya" #path rss_icon_path = "/static/images/favicons/" main_log_path = 'log/error.log' session_dir = 'log/session' cookie_path = '/' include_path = ["src", "src/libs", "src/libs/html5lib"] #public config log_enable = True debuging = True persian_timezone_seconds = 4.5 * 60 * 60 session_timeout = 1 * 60 * 60 #1hour home_page_news = 50 crawl_interval = 5 * 60 #shared objects sid = None error_log = LogUtil(main_log_path, log_enable, debuging) db = { 'host': '127.0.0.1', 'db_name': 'beta_yeksatr', 'user': '******', 'pass': '******' } database = MySQLDatabase(None) def __init__(self, params): ''' Constructor ''' pass
import sys, traceback from pyramid.view import view_config, notfound_view_config from pyramid.response import Response from pyramid.renderers import render_to_response from yeksatr.backend.helpers.utility import * from yeksatr.backend.helpers.logutil import LogUtil from yeksatr.backend.helpers.setting import Setting, InitDB from yeksatr.backend.feed.rssreader import RssReader from yeksatr.backend.orm.news import NewsWorker from yeksatr.backend.feed.newsagent import NewsAgent from yeksatr.backend.orm.user import UserWorker Setting.error_log = LogUtil(Setting.main_log_path, Setting.log_enable, Setting.debuging) Setting.error_log.WriteLog("starting app") @view_config(route_name='inn') def index2(request): return Response(PrettyDate(10800)) @view_config(route_name='UpdateNews') def UpdateNews(request): try: InitDB() rr = RssReader() return Response("res is " + str(rr.Read())) except Exception as ex: Setting.error_log.LogException(ex)