def handler_goodbye(self, method): self.visits_counter() time = datetime.now().hour parting = "day" if time in range(9, 19) else "night" msg = f"Good {parting}!" respond_200(self, msg, "text/plain")
def theme_GEThandler(self): sessions = self.load_user_session(THEME) if not sessions: sessions = self.get_default_theme() html_file = PAGES_DIR / "theme" / "index.html" theme_page = self.get_content(html_file).format(**sessions) respond_200(self, theme_page, "text/html")
def hello_GEThandler(self): sessions = self.load_user_session(SESSION) or self.build_query_args() name = self.build_name(sessions) age = self.build_age(sessions) born = None if age: year = datetime.now().year born = year - int(age) html_file = PAGES_DIR / "hello" / "index.html" cont_html = self.get_content(html_file).format(name=name, year=born) respond_200(self, cont_html, "text/html")
def handler_job(self, method): self.visits_counter() json_file = PAGES_DIR / "job" / "job.json" html_file = PAGES_DIR / "job" / "index.html" job_json = self.load_json_file(json_file) cont_html = self.get_content(html_file) html = "" for name, dates in job_json.items(): started = dates["start"] ended = dates["end"] or "now" msg = cont_html.format(name=name, started=started, ended=ended) # msg = json.dumps(job_json, sort_keys=True, indent=4) html += msg respond_200(self, html, "text/html")
def handler_count(self, method): #t = datetime.now() html_file = PAGES_DIR / "counter" / "index.html" cont_json = self.load_json_file(COUNTER) #cont_json = self.get_json(COUNTER) cont_html = self.get_content(html_file) html = "" #for (dates, stats) in cont_json.items(): # распаковали словарь дата: остальное, перевили дату в читабельный вид # dates = datetime.strptime(dates, "%Y-%m-%d") # cont_json[dates] = stats # #del cont_json[dates] #today = {} #for d, s in cont_json.items(): # if d.date() == t.date(): # for p, v in s.items(): # today[p] = today.get(p, 0) + v for page, visits in cont_json.items(): msg = cont_html.format(page=page, visits=visits) html += msg respond_200(self, html, "text/html")
def handler_education(self, method): self.visits_counter() html = PAGES_DIR / "education" / "index.html" content = self.get_content(html) respond_200(self, content, "text/html")
def handler_index(self, method): self.visits_counter() html = MYPROJECT_DIR / "index.html" content = self.get_content(html) respond_200(self, content, "text/html")