-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.py
More file actions
70 lines (41 loc) · 1.56 KB
/
common.py
File metadata and controls
70 lines (41 loc) · 1.56 KB
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 -*-
__author__ = 'ipetrash'
from datetime import datetime
import sys
import logging
def save_current_html(doc):
"""Функция принимает QWebElement и сохраняет в файл, возвращая имя файла."""
t = datetime.today().time()
file_name = t.strftime("%H.%M.%S") + ".html"
with open(file_name, mode='w', encoding='utf8') as f:
f.write(doc.toOuterXml())
return file_name
def get_logger(name, file='log.txt', encoding='utf8'):
log = logging.getLogger(name)
log.setLevel(logging.DEBUG)
formatter = logging.Formatter('[%(asctime)s] %(filename)s[LINE:%(lineno)d] %(levelname)-8s %(message)s')
fh = logging.FileHandler(file, encoding=encoding)
fh.setLevel(logging.DEBUG)
ch = logging.StreamHandler(stream=sys.stdout)
ch.setLevel(logging.DEBUG)
fh.setFormatter(formatter)
ch.setFormatter(formatter)
log.addHandler(fh)
log.addHandler(ch)
return log
class MoswarBotError(Exception):
pass
class MoswarElementIsMissError(MoswarBotError):
pass
class MoswarClosedError(MoswarBotError):
def __init__(self, reason):
super().__init__('Сайт закрыт. Причина:\n"{}".'.format(reason))
class MoswarButtonIsMissError(MoswarElementIsMissError):
def __init__(self, title_button):
super().__init__('Не найдена кнопка "{}".'.format(title_button))
class MoswarAuthError(MoswarBotError):
pass
LOGIN = 'ilya.petrash@inbox.ru'
PASSWORD = '0JHQu9GPRnVjazop'
CONFIG_FILE = 'config'