1. docker运行 pyppeteer

    docker运行 puppeteer/pyppeteer

    2020/01/11 技术

  2. 百度/腾讯 ocr 试用

    百度/腾讯 ocr 试用

    2020/01/10 技术

  3. 页面元素选择

    页面元素选择

    2020/01/09 技术

  4. python pickle 实践

    python pickle 实践

    2020/01/08 技术

  5. k3s 安装加速

    k3s 安装加速

    2020/01/03 技术

  6. FFmpeg 使用总结

    FFmpeg 使用总结 1. 提取音频 # 提取 mp3 音轨 ffmpeg -y -i input.mp4 -write_xing 0 output.mp3 2. 音频转码 # mp3 转 pcm ffmpeg -y -i input.mp3 -acodec pcm_s16le -f s16le -ac 1 -ar 16k ouput.wav

    2020/01/02 技术

  7. Systemd 教程

    Systemd 教程 1. systemd 管理 autossh 创建 autossh.service 文件, 配置服务: [Unit] Description=Auto SSH Tunnel After=network-online.target [Service] User=root Type=simple ExecStart=/usr/bin/autossh -p 22 -M 23 -NR 'localhost:23:localhost:22' root@remote.com ExecReload=/bin/kill -HUP $MAINPID KillMode=process Restart=always [Install] WantedBy=multi-user.target WantedBy=graphical.target 执行命令, 运行 autossh : apt update && apt install autossh -y chmod 644 autossh.service cp autossh.service /lib/systemd/system/ systemctl enable systemd-networkd-wait-online systemctl enable autossh systemctl start autossh

    2019/12/30 技术

  8. mysql 1366 错误解决

    mysql 1366 错误解决 问题描述 在配置某个服务时,使用到 mysql docker 服务。启动服务出现错误, 查看日志, 发现操作 mysql 时出现如下错误提示: Error 1366: Incorrect string value: '\xE8\x8A\x9D\xE9\xBA\xBB...' for column 'Code' at row 1 解决方案 检索后,得知,是 mysql 服务端与客户端 编码不匹配造成的。 客户端使用 utf8mb4 编码。 mysql 启动 docker 时,没指定服务端编码,通过在 mysql 启动命令中增加 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci 重启 docker 后,问题解决。 mysql docker-compose.yml配置 如下: mysql-server: image: mysql:5.7 container_name: mysql-server hostname: mysql-server volumes: - db-mysql:/var/lib/mysql environment: - MYSQL_ROOT_PASSWORD=data123 - MYSQL_DATABASE=data - MYSQL_USER=data - MYSQL_PASSWORD=data123 command: ['mysqld', '--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci'] networks: - data-network

    2019/12/29 技术

  9. docker-compose 笔记

    docker-compose 笔记

    2019/12/28 技术

  10. sqlite 使用总结

    sqlite 使用总结 SQLite官方文档 Appropriate Uses For SQLite 指出: SQLite does not compete with client/server databases. SQLite competes with fopen(). SQLite的竞争对手是fopen(相当于 python 中的 open)。 1. 存储文本数据集 存在一个大规模的文本数据集, 以 (index/int, hash/str, content/str)的形式存储,使用方式仅是通过搜索 index 或 hash, 获取文本信息。此外, 该数据集的读取,都在一个进程中执行。 在这种特殊的应用场景中, 如果将数据集存储到诸如 mysql, mongo 等数据库中, 会造成资源的浪费。这时候, sqlite 便可以派上用场。 import logging import os import sqlite3 from collections import namedtuple TextModel = namedtuple("TextModel", field_names=["index", "hash_id", "content"]) _cur_dir = os.path.dirname(__file__) class SqliteTextDao(object): def __init__(self, db_file: str, logger: logging.Logger = None): self.db_file = db_file self.logger = logger or logging.getLogger(self.__class__.__name__) def search(self, index_list: [int]) -> [(int, str, str)]: """ 搜索 """ conn = self._get_connect() try: args = list(set(index_list)) sql = "SELECT INDEX, HASHID, CONTENT from TEXTDB where ID IN ({})".format(",".join(["?" for _ in range(len(args))])) cursor = conn.cursor().execute(sql, args) return [(row[0], row[1], row[2]) for row in cursor] except Exception as e: self.logger.error(e) def insert(self, hash_id: str, content: str, index: int): """ 插入数据 """ conn = self._get_connect() try: sql = "INSERT INTO TEXTDB(INDEX, HASHID, CONTENT) VALUES (?, ?, ?)" conn.cursor().execute(sql, (index, hash_id, content)) conn.commit() except Exception as e: self.logger.error(e) return None finally: conn.close() def _get_connect(self): """ 创建模型 """ if not os.path.exists(self.db_file): conn = sqlite3.connect(self.db_file) c = conn.cursor() c.execute('''CREATE TABLE TEXTDB (INDEX INTEGER PRIMARY KEY, HASHID CHAR(32) NOT NULL, CONTENT TEXT);''') conn.commit() conn.close() return sqlite3.connect(self.db_file) def list_instance_by_index(self, index_list: [int]) -> [TextModel]: """ 根据 index 返回 数据模型 列表 :param index_list: :return: :rtype: list of TextModel """ index_list = [int(_index) for _index in list(set(index_list))] # numpy 来源的 index 可能类型不一样 instance_dict = {} for index, hash_id, content in self.search(index_list=index_list): instance_dict[int(index)] = TextModel(index=int(index), hash_id=hash_id, content=content) result_list = [] for index in index_list: result_list.append(instance_dict.get(index)) return result_list 2. sqlite sql 用例参考 2.1 list instance # uid in uid_list "SELECT UID from DB1 where UID IN ({})".format(",".join(["?" for _ in range(len(uid_list))])) # uid in uid_list && has_detail "SELECT UID from DB1 where UID IN ({}) AND DETAIL != '' ".format(",".join(["?" for _ in range(len(uid_list))])) # uid in uid_list && !has_detail "SELECT UID from DB1 where UID IN ({}) AND DETAIL = '' ".format(",".join(["?" for _ in range(len(uid_list))])) 2.2 insert only uid not exists # UID 是 CHAR(32) UNIQUE NOT NULL 'INSERT OR IGNORE INTO DB1 (ID, UID, VALUE) values (NULL, ?, ? ) '

    2019/11/29 技术