# -*- encoding: utf-8 -*- # import os, urllib.parse, traceback virtual_env = os.path.expanduser('~/projects/world-it-planet/env') activate_this = os.path.join(virtual_env, 'bin/activate_this.py') exec(open(activate_this).read(), dict(__file__=activate_this)) import random, time from datetime import datetime #декларативное определение from sqlalchemy import Column, Integer, String, create_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker from sqlalchemy import desc #---------------------------------- Variables ---------- #---------------------------------- Variables End ---------- def application(env, start_response): out_s = "" #Инициализация SQLLite basedir = os.path.abspath(os.path.dirname(__file__)) SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'hhtm.db') engine = create_engine(SQLALCHEMY_DATABASE_URI, pool_pre_ping=True) Base = declarative_base() class Vacancies(Base): __tablename__ = 'vacancies' id = Column(Integer, primary_key=True, autoincrement=True) title = Column(String(512)) city = Column(String(20)) specialization = Column(String(255)) href = Column(String(512)) donor = Column(String(255)) vacancy_id = Column(Integer) vacancy_date = Column(Integer) parse_date = Column(Integer) employer = Column(String(255)) canal_city_id = Column(Integer) canal_city_date = Column(Integer) canal_spec_id = Column(Integer) canal_spec_date = Column(Integer) def __init__(self, title, city, specialization, href, donor, vacancy_id, vacancy_date, parse_date, employer, canal_city_id, canal_city_date, canal_spec_id, canal_spec_date): self.title = title self.city = city self.specialization = specialization self.href = href self.donor = donor self.vacancy_id = vacancy_id self.vacancy_date = vacancy_date self.parse_date = parse_date self.employer = employer self.canal_city_id = canal_city_id self.canal_city_date = canal_city_date self.canal_spec_id = canal_spec_id self.canal_spec_date = canal_spec_date def __repr__(self): return "" % (self.title, self.specialization, self.href) class Log(Base): __tablename__ = 'log' id = Column(Integer, primary_key=True, autoincrement=True) action = Column(String(64)) status = Column(String(64)) time = Column(Integer) donor = Column(String(64)) city = Column(String(20)) specialization = Column(String(20)) vacancies_count = Column(Integer) canal_id = Column(String(64)) def __init__(self, action, status, time, donor, city, specialization, vacancies_count, canal_id): self.action = action self.status = status self.time = time self.donor = donor self.city = city self.specialization = specialization self.vacancies_count = vacancies_count self.canal_id = canal_id def __repr__(self): return "" % (self.action, self.status) # Создание таблицы Base.metadata.create_all(engine) Session = sessionmaker(bind=engine) session = Session() out_s += "" log = session.query(Log).order_by(desc(Log.id))[0:50] for item in log: date_time = datetime.fromtimestamp(item.time) s_date = date_time.strftime("%d %m %Y %H:%M:%S") out_s += f"" out_s += "
" start_response('200 OK', [('Content-Type','text/html')]) b = out_s.encode('utf-8') return [b]
DateActionStatusDonorСitySpecializationVacancies CountCanal ID
{s_date}{item.action}{item.status}{item.donor}{item.city}{item.specialization}{item.vacancies_count}{item.canal_id}