forked from caspartse/eBooksAssistant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.py
executable file
·75 lines (68 loc) · 1.79 KB
/
common.py
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
71
72
73
74
75
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# 标准库
import argparse
import base64
import codecs
from collections import namedtuple
import datetime
from hashlib import md5
import math
import os
import re
import secrets
import subprocess
import threading
from time import sleep, time
import traceback
from urllib.parse import urlparse
from uuid import uuid4
# 第三方库
import arrow
import bottle
from bottle import Bottle, run, request, response, abort, error, static_file, redirect
import jwt
import orjson as json
import psycopg2
from psycopg2 import pool
from rapidfuzz import fuzz
import redis
import requests
from selenium.common.exceptions import TimeoutException, NoSuchElementException, WebDriverException
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from seleniumbase import Driver
import yaml
# 防止命名冲突
assert json != "json"
CURRENT_PATH = os.path.dirname(os.path.abspath(__file__))
# 加载数据库配置
with open(f'{CURRENT_PATH}/config/db_config.yaml', encoding='utf-8') as f:
DB_CONFIG = yaml.safe_load(f)
# Postgres 连接池
minconn = 1
maxconn = 200
PG_CONFIG = DB_CONFIG['postgresql']
db_pool = psycopg2.pool.SimpleConnectionPool(
minconn,
maxconn,
host=PG_CONFIG['host'],
port=PG_CONFIG['port'],
dbname=PG_CONFIG['dbname'],
user=PG_CONFIG['username'],
password=PG_CONFIG['password']
)
# Redis 连接池
RD_CONFIG = DB_CONFIG['redis']
rd_pool = redis.ConnectionPool(
host=RD_CONFIG['host'],
port=RD_CONFIG['port'],
password=RD_CONFIG['password'],
db=RD_CONFIG['db'],
decode_responses=True
)
rd = redis.Redis(connection_pool=rd_pool)
if __name__ == '__main__':
pass