月度归档: 2024 年 11 月

  • python-Celery应用场景

    Celery使用场景

    1. 异步任务(函数)
      一些耗时操作交给celery执行-视频转码,邮件发送,消息推送
    2. 定时任务
      定时推送消息,定时爬取一些数据,定时统计一些数据等
    3. 延迟任务
      提交任务后,等一段时间再执行任务

     

  • C++数值转换

    #include <iostream>
    #include <string>
    #include <cmath>
    
    int main() {
    	// 数字转字符串
    	int num = 123;
    	std::string strNum = std::to_string(num);
    	std::cout << "数字转字符串: " << strNum << std::endl;
    	
    	// 字符转数字
    	std::string strInt = "456";
    	int intNum = std::stoi(strInt);
    	std::cout << "字符转数字: " << intNum << std::endl;
    	
    	// 字符转浮点数
    	std::string strFloat = "789.01";
    	float floatNum = std::stof(strFloat);
    	std::cout << "字符转浮点数: " << floatNum << std::endl;
    	
    	// 浮点数转字符
    	float floatNum2 = 123.45f;
    	std::string strFloat2 = std::to_string(floatNum2);
    	std::cout << "浮点数转字符: " << strFloat2 << std::endl;
    	
    	// 双精度转字符
    	double doubleNum = 123.456;
    	std::string strDouble = std::to_string(doubleNum);
    	std::cout << "双精度转字符: " << strDouble << std::endl;
    	
    	// 字符转双精度
    	std::string strDouble2 = "789.101";
    	double doubleNum2 = std::stod(strDouble2);
    	std::cout << "字符转双精度: " << doubleNum2 << std::endl;
    	
    	return 0;
    }

     

  • 油猴js脚本-自动修改百度贴吧域名jump2.bdim为tieba.baidu

    // ==UserScript==
    // @name 自动修改百度贴吧域名jump2.bdim为tieba.baidu
    // @namespace http://tampermonkey.net/
    // @version 2024-11-12
    // @description 自动修改百度贴吧域名jump2.bdim为tieba.baidu
    // @author rkey
    // @match https://jump2.bdimg.com/*
    // @icon https://www.google.com/s2/favicons?sz=64&domain=bdimg.com
    // @grant none
    // ==/UserScript==

    (function() {
    ‘use strict’;
    getUrl();
    // Your code here…
    })();

    function getUrl(){
    var url = window.location.href;
    console.log(“当前网址是:”+url); // 输出应该会类似这样:http://example.com/page.html
    var newStr = url.replace(“jump2.bdimg”, “tieba.baidu”);
    console.log(“当前修改后的网址是:”+newStr);
    window.location.href = newStr;
    }

  • python3.13安装pipreqs-0.4.13

    这个库是用来查询当前项目使用的库都有哪些,在项目文件夹里进入cmd,输入

    pipreqs ./

    以下是安装日志

    C:\Users\rkey\Desktop\测试\video>pip install pipreqs
    Collecting pipreqs
    Downloading pipreqs-0.4.13-py2.py3-none-any.whl.metadata (7.4 kB)
    Collecting docopt (from pipreqs)
    Downloading docopt-0.6.2.tar.gz (25 kB)
    Installing build dependencies … done
    Getting requirements to build wheel … done
    Preparing metadata (pyproject.toml) … done
    Collecting yarg (from pipreqs)
    Downloading yarg-0.1.10-py2.py3-none-any.whl.metadata (4.5 kB)
    Requirement already satisfied: requests in c:\application\python\python313\lib\site-packages (from yarg->pipreqs) (2.32.3)
    Requirement already satisfied: charset-normalizer<4,>=2 in c:\application\python\python313\lib\site-packages (from requests->yarg->pipreqs) (3.4.0)
    Requirement already satisfied: idna<4,>=2.5 in c:\application\python\python313\lib\site-packages (from requests->yarg->pipreqs) (3.10)
    Requirement already satisfied: urllib3<3,>=1.21.1 in c:\application\python\python313\lib\site-packages (from requests->yarg->pipreqs) (2.2.3)
    Requirement already satisfied: certifi>=2017.4.17 in c:\application\python\python313\lib\site-packages (from requests->yarg->pipreqs) (2024.8.30)
    Downloading pipreqs-0.4.13-py2.py3-none-any.whl (33 kB)
    Downloading yarg-0.1.10-py2.py3-none-any.whl (13 kB)
    Building wheels for collected packages: docopt
    Building wheel for docopt (pyproject.toml) … done
    Created wheel for docopt: filename=docopt-0.6.2-py2.py3-none-any.whl size=13775 sha256=2fcda2e9e4af051ca230ea2873eafc9c42dde535ff98d238a8c604a79104d44d
    Stored in directory: c:\users\rkey\appdata\local\pip\cache\wheels\0b\1d\03\175286677fb5a1341cc3e4755bf8ec0ed08f3329afd67446b0
    Successfully built docopt
    Installing collected packages: docopt, yarg, pipreqs
    Successfully installed docopt-0.6.2 pipreqs-0.4.13 yarg-0.1.10

    [notice] A new release of pip is available: 24.2 -> 24.3.1
    [notice] To update, run: python.exe -m pip install –upgrade pip

  • 简单示例:flask把当前数据库的数据同步到远程的数据库上

    在Flask应用中同步数据到远程数据库通常涉及到以下几个步骤:

    1. 建立数据库连接:创建到本地数据库和远程数据库的连接。
    2. 读取本地数据:从本地数据库读取需要同步的数据。
    3. 写入远程数据库:将读取的数据写入远程数据库。
    4. 处理异常和冲突:确保在数据同步过程中处理任何异常和数据冲突。
    5. 保持数据一致性:确保同步过程中数据的一致性和完整性。

    以下是一个简化的示例,展示了如何使用Python的sqlite3模块将SQLite数据库的数据同步到另一个SQLite数据库。对于其他类型的数据库(如MySQL、PostgreSQL等),你可能需要使用不同的数据库适配器(如mysql-connector-pythonpsycopg2)并调整SQL语法。

    示例:同步SQLite数据库到远程SQLite数据库

    import sqlite3
    from flask import Flask
    
    app = Flask(__name__)
    
    def sync_db(local_db_path, remote_db_path):
        # 连接到本地数据库
        local_conn = sqlite3.connect(local_db_path)
        local_cursor = local_conn.cursor()
        
        # 连接到远程数据库
        remote_conn = sqlite3.connect(remote_db_path)
        remote_cursor = remote_conn.cursor()
        
        try:
            # 从本地数据库读取数据
            local_cursor.execute("SELECT * FROM your_table")
            rows = local_cursor.fetchall()
            
            # 将读取的数据写入远程数据库
            for row in rows:
                remote_cursor.execute("INSERT INTO your_table VALUES (?, ?, ?)", row)
            
            # 提交事务
            remote_conn.commit()
        except Exception as e:
            # 处理异常
            print(f"An error occurred: {e}")
        finally:
            # 关闭游标和连接
            local_cursor.close()
            remote_cursor.close()
            local_conn.close()
            remote_conn.close()
    
    @app.route('/sync')
    def sync():
        # 调用同步函数
        sync_db('path/to/local.db', 'path/to/remote.db')
        return 'Databases synchronized'
    
    if __name__ == '__main__':
        app.run(debug=True)

    注意事项:

    • 数据冲突:如果远程数据库中已经存在相同的数据,直接插入可能会导致冲突。你可能需要在插入前检查数据是否存在,或者使用数据库的ON CONFLICTON DUPLICATE KEY UPDATE语句来处理冲突。
    • 数据一致性:在同步过程中,确保数据的一致性和完整性是非常重要的。考虑使用事务来确保操作的原子性。
    • 性能问题:如果数据量很大,同步操作可能会很慢。在这种情况下,你可能需要考虑使用批处理或异步处理来提高性能。
    • 安全性:确保远程数据库的连接是安全的,特别是在处理敏感数据时。使用加密连接和验证机制来保护数据传输。

    这个示例仅适用于SQLite数据库。对于其他类型的数据库,你需要根据数据库的特定特性和语法进行调整。

  • python3.13安装everytools

    pip install everytools
    Requirement already satisfied: everytools in c:\application\python\python313\lib\site-packages (0.0.1.2)
    Requirement already satisfied: pandas in c:\application\python\python313\lib\site-packages (from everytools) (2.2.3)
    Requirement already satisfied: numpy>=1.26.0 in c:\application\python\python313\lib\site-packages (from pandas->everytools) (2.1.3)
    Requirement already satisfied: python-dateutil>=2.8.2 in c:\application\python\python313\lib\site-packages (from pandas->everytools) (2.9.0.post0)
    Requirement already satisfied: pytz>=2020.1 in c:\application\python\python313\lib\site-packages (from pandas->everytools) (2024.2)
    Requirement already satisfied: tzdata>=2022.7 in c:\application\python\python313\lib\site-packages (from pandas->everytools) (2024.2)
    Requirement already satisfied: six>=1.5 in c:\application\python\python313\lib\site-packages (from python-dateutil>=2.8.2->pandas->everytools) (1.16.0)

    [notice] A new release of pip is available: 24.2 -> 24.3.1
    [notice] To update, run: python.exe -m pip install –upgrade pip

  • 鼠标

    今天在电脑上扒出来了一个[图吧工具箱],里面有一个软件:[鼠标单机变双击测试器V2.0],让我想起了以前买的一批有问题的鼠标,打游戏的时候,点击过快就会自动切回桌面,

    然后我试了试这个鼠标,然后试了试我现在正常的鼠标,发现以前那批鼠标有很大概率会单机变双击.

    于是我网上找了找如何拆鼠标的教程,发现鼠标的脚垫一般下面会隐藏螺丝,拆掉螺丝即可看到主板,拆掉鼠标壳子之后,试了试鼠标,

    发现也不会单机变双击啊,然后把壳子又装回去了,发现单机变双击的现象好了.反复测试了几百次,依然没问题,好奇怪.

    打会儿游戏又变回去了,又变成单机变双击了.

  • python3.13安装moviepy

    C:\Users\rkey>pip install moviepy
    Collecting moviepy
    Downloading moviepy-1.0.3.tar.gz (388 kB)
    Installing build dependencies … done
    Getting requirements to build wheel … done
    Preparing metadata (pyproject.toml) … done
    Collecting decorator<5.0,>=4.0.2 (from moviepy)
    Downloading decorator-4.4.2-py2.py3-none-any.whl.metadata (4.2 kB)
    Collecting tqdm<5.0,>=4.11.2 (from moviepy)
    Downloading tqdm-4.67.0-py3-none-any.whl.metadata (57 kB)
    Collecting requests<3.0,>=2.8.1 (from moviepy)
    Downloading requests-2.32.3-py3-none-any.whl.metadata (4.6 kB)
    Collecting proglog<=1.0.0 (from moviepy)
    Downloading proglog-0.1.10-py3-none-any.whl.metadata (639 bytes)
    Requirement already satisfied: numpy>=1.17.3 in c:\application\python\python313\lib\site-packages (from moviepy) (2.1.3)
    Collecting imageio<3.0,>=2.5 (from moviepy)
    Downloading imageio-2.36.0-py3-none-any.whl.metadata (5.2 kB)
    Collecting imageio-ffmpeg>=0.2.0 (from moviepy)
    Downloading imageio_ffmpeg-0.5.1-py3-none-win_amd64.whl.metadata (1.6 kB)
    Collecting pillow>=8.3.2 (from imageio<3.0,>=2.5->moviepy)
    Downloading pillow-11.0.0-cp313-cp313-win_amd64.whl.metadata (9.3 kB)
    Requirement already satisfied: setuptools in c:\application\python\python313\lib\site-packages (from imageio-ffmpeg>=0.2.0->moviepy) (75.5.0)
    Collecting charset-normalizer<4,>=2 (from requests<3.0,>=2.8.1->moviepy)
    Downloading charset_normalizer-3.4.0-cp313-cp313-win_amd64.whl.metadata (34 kB)
    Collecting idna<4,>=2.5 (from requests<3.0,>=2.8.1->moviepy)
    Downloading idna-3.10-py3-none-any.whl.metadata (10 kB)
    Collecting urllib3<3,>=1.21.1 (from requests<3.0,>=2.8.1->moviepy)
    Downloading urllib3-2.2.3-py3-none-any.whl.metadata (6.5 kB)
    Collecting certifi>=2017.4.17 (from requests<3.0,>=2.8.1->moviepy)
    Downloading certifi-2024.8.30-py3-none-any.whl.metadata (2.2 kB)
    Requirement already satisfied: colorama in c:\application\python\python313\lib\site-packages (from tqdm<5.0,>=4.11.2->moviepy) (0.4.6)
    Downloading decorator-4.4.2-py2.py3-none-any.whl (9.2 kB)
    Downloading imageio-2.36.0-py3-none-any.whl (315 kB)
    Downloading imageio_ffmpeg-0.5.1-py3-none-win_amd64.whl (22.6 MB)
    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 22.6/22.6 MB 576.2 kB/s eta 0:00:00
    Downloading proglog-0.1.10-py3-none-any.whl (6.1 kB)
    Downloading requests-2.32.3-py3-none-any.whl (64 kB)
    Downloading tqdm-4.67.0-py3-none-any.whl (78 kB)
    Downloading certifi-2024.8.30-py3-none-any.whl (167 kB)
    Downloading charset_normalizer-3.4.0-cp313-cp313-win_amd64.whl (102 kB)
    Downloading idna-3.10-py3-none-any.whl (70 kB)
    Downloading pillow-11.0.0-cp313-cp313-win_amd64.whl (2.6 MB)
    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.6/2.6 MB 587.8 kB/s eta 0:00:00
    Downloading urllib3-2.2.3-py3-none-any.whl (126 kB)
    Building wheels for collected packages: moviepy
    Building wheel for moviepy (pyproject.toml) … done
    Created wheel for moviepy: filename=moviepy-1.0.3-py3-none-any.whl size=110766 sha256=b1634b04eacbf78e39b726a6011b7b7cf96ba9191977b4e89f54922c15931df4
    Stored in directory: c:\users\rkey\appdata\local\pip\cache\wheels\ee\0c\ac\4c0c65f1289060c39182ba74294d8b72d03600d619663e8935
    Successfully built moviepy
    Installing collected packages: urllib3, tqdm, pillow, imageio-ffmpeg, idna, decorator, charset-normalizer, certifi, requests, proglog, imageio, moviepy
    Successfully installed certifi-2024.8.30 charset-normalizer-3.4.0 decorator-4.4.2 idna-3.10 imageio-2.36.0 imageio-ffmpeg-0.5.1 moviepy-1.0.3 pillow-11.0.0 proglog-0.1.10 requests-2.32.3 tqdm-4.67.0 urllib3-2.2.3

    [notice] A new release of pip is available: 24.2 -> 24.3.1
    [notice] To update, run: python.exe -m pip install –upgrade pip

  • cmd获取指定视频的时长

    在Windows的命令提示符(cmd)中,你可以使用ffprobe命令来获取视频文件的时长。ffprobeFFmpeg工具包的一部分,它是一个强大的多媒体框架,可以用来处理视频和音频文件。

    以下是如何使用ffprobe获取视频文件时长的步骤:

    1. 安装FFmpeg: 如果你还没有安装FFmpeg,你需要先下载并安装它。你可以从FFmpeg官网下载适合Windows的版本,并将其解压到一个目录。
    2. 将FFmpeg添加到系统路径: 将FFmpegbin目录添加到你的系统环境变量Path中,这样你就可以在任何命令提示符下使用ffprobe命令。
    3. 使用ffprobe获取视频时长: 打开命令提示符(cmd),然后输入以下命令:
      ffprobe -i "C:\path\to\your\video.mp4" -show_entries format=duration -v quiet -of csv="p=0:s=x"

      这里的-i后面跟着的是视频文件的路径,-show_entries指定要显示的信息(这里是format=duration),-v quiet是减少输出信息,-of csv="p=0:s=x"是输出格式,p=0表示打印第一个流的信息,s=x表示输出的字符串。

      这条命令会输出视频的时长,单位是秒。

    如果你不想安装FFmpeg,你也可以使用Windows自带的wmplayer(Windows Media Player)来获取视频时长,但这种方法可能不如ffprobe准确:

    wmplayer "C:\path\to\your\video.mp4" /playerversion 11 /fullscreen false /playstate 2-1

    这条命令会输出视频的元数据,包括时长,但输出的信息量较大,需要你从中找到时长信息。

    请注意,将C:\path\to\your\video.mp4替换为你的视频文件的实际路径。

  • python3.13安装opencv-contrib-python

    C:\Users\rkey>pip install –user opencv-contrib-python
    Collecting opencv-contrib-python
    Using cached opencv_contrib_python-4.10.0.84-cp37-abi3-win_amd64.whl.metadata (20 kB)
    Requirement already satisfied: numpy>=1.21.2 in c:\application\python\python313\lib\site-packages (from opencv-contrib-python) (2.1.3)
    Using cached opencv_contrib_python-4.10.0.84-cp37-abi3-win_amd64.whl (45.5 MB)
    Installing collected packages: opencv-contrib-python
    Successfully installed opencv-contrib-python-4.10.0.84

    [notice] A new release of pip is available: 24.2 -> 24.3.1
    [notice] To update, run: python.exe -m pip install –upgrade pip