凭海临风的IT江湖

  • 首页

  • 关于

  • 标签

  • 分类

  • 归档

  • 站点地图

  • 公益 404

  • 时间轴

  • 搜索

python操作sqlite3

发表于 2019-05-28 | 更新于 2022-08-18 | 分类于 python
本文字数: 6.8k | 阅读时长 ≈ 6 分钟

sqlite3 简介

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
SQLite数据库是一款非常小巧的嵌入式开源数据库软件,也就是说
没有独立的维护进程,所有的维护都来自于程序本身。
在python中,使用sqlite3创建数据库的连接,当我们指定的数据库文件不存在的时候
连接对象会自动创建数据库文件;如果数据库文件已经存在,则连接对象不会再创建
数据库文件,而是直接打开该数据库文件。
连接对象可以是硬盘上面的数据库文件,也可以是建立在内存中的,在内存中的数据库
执行完任何操作后,都不需要提交事务的(commit)

创建在硬盘上面: conn = sqlite3.connect('c:\\test\\test.db')
创建在内存上面: conn = sqlite3.connect('"memory:')

下面我们一硬盘上面创建数据库文件为例来具体说明:
conn = sqlite3.connect('c:\\test\\hongten.db')
其中conn对象是数据库链接对象,而对于数据库链接对象来说,具有以下操作:

commit() --事务提交
rollback() --事务回滚
close() --关闭一个数据库链接
cursor() --创建一个游标

cu = conn.cursor()
这样我们就创建了一个游标对象:cu
在sqlite3中,所有sql语句的执行都要在游标对象的参与下完成
对于游标对象cu,具有以下具体操作:

execute() --执行一条sql语句
executemany() --执行多条sql语句
close() --游标关闭
fetchone() --从结果中取出一条记录
fetchmany() --从结果中取出多条记录
fetchall() --从结果中取出所有记录
scroll() --游标滚动
阅读全文 »

selenium元素操作封装

发表于 2019-05-28 | 更新于 2022-08-18 | 分类于 自动化测试
本文字数: 1.7k | 阅读时长 ≈ 2 分钟

selenium 常用的元素定位操作

Selenium提供了8种定位方式。

  • id
  • name
  • class name
  • tag name
  • link text
  • partial link text
  • xpath
  • css selector

这8种定位方式在Python selenium中所对应的方法为:

  • find_element_by_id()

  • find_element_by_name()

  • find_element_by_class_name()

  • find_element_by_tag_name()

  • find_element_by_link_text()

  • find_element_by_partial_link_text()

  • find_element_by_xpath()

  • find_element_by_css_selector()

阅读全文 »

使用selenium访问爱奇艺网站

发表于 2019-05-28 | 更新于 2022-08-18 | 分类于 自动化测试
本文字数: 1.3k | 阅读时长 ≈ 1 分钟

使用selenium访问爱奇艺网站

selenium 是一种常用的自动化测试工具。它支持各种浏览器,包括 Chrome,Safari,Firefox 等主流界面式浏览器,如果你在这些浏览器里面安装一个 Selenium 的插件,还可以通过录制,快速生成脚本。

selenium 支持多种主流的开发语言,比如Ruby,java,python,javascript。

环境搭建

python3.7.3

运行 pip install selenium 就可以直接下载最新的selenium版本

准备

浏览器:chrome 70.0.3538.77

操作系统:win7

selenium版本: 3.14.1

chromedriver: https://npm.taobao.org/mirrors/chromedriver/70.0.3538.97/

使用selenium 打开和关闭浏览器

1
2
3
4
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("http://www.iqiyi.com/")
driver.quit()
阅读全文 »

Hello World

发表于 2019-05-28 | 更新于 2022-08-18
本文字数: 357 | 阅读时长 ≈ 1 分钟

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment

copy maven dependencies to a folder

发表于 2016-09-30 | 更新于 2022-08-18 | 分类于 java
本文字数: 1.4k | 阅读时长 ≈ 1 分钟

copy maven dependencies to a folder

background

一个简单的需求,当你的同事需要调试代码的时候,他并不想建立maven环境,这时候依赖的jar包 该如何导出呢?

no code say nothing

这时候你需要的是maven-dependency-plugin。

添加依赖配置

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
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<!-- copy-dependency plugin -->
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<versionRange>[1.0.0,)</versionRange>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>

此处的<outputDirectory> 指定了你导出jar包的路径.

执行命令 mvn dependency:copy-dependencies

查看项目多了一个/alternateLocation目录,并且依赖的jar包都下载到这个目录下了。

how to use nginx on windows

发表于 2016-09-27 | 更新于 2022-08-18 | 分类于 nginx
本文字数: 947 | 阅读时长 ≈ 1 分钟

how to use nginx on windows

1. Download nginx lastest release from here.

2. unzip to your local driver. eg: c:/apps/nginx

3. start nginx

1
2
cd c:/apps/nginx
start nginx

4. monitoring nginx process

1
2
3
4
5
tasklist /fi "imagename eq nginx.exe"
Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
nginx.exe 11700 Console 1 10,696 K
nginx.exe 1160 Console 1 11,180 K

notice
一个是主进程(main process),另一个是工作进程(work process).如果启动失败,请查看错误日志logs\error.log

5. visit http://localhost:8080

6. configuration file nginx.conf

reference config

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
error_log  logs/error.log;
http {
include mime.types;
default_type application/octet-stream;
server {
listen 8080;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
...
}

7. the command list of nginx:

1
2
3
4
nginx -s stop   快速退出
nginx -s quit 优雅退出
nginx -s reload 更换配置,启动新的工作进程,优雅的关闭以往的工作进程
nginx -s reopen 重新打开日志文件

how git changing author info

发表于 2016-09-22 | 更新于 2022-08-18 | 分类于 git
本文字数: 1.1k | 阅读时长 ≈ 1 分钟

how git changing author info

背景

  1. gitlab中的统计视图是根据用户的信息统计工作量
  2. 迁移git repo中经常会遇到用户和邮箱不一致的情况

解决思路

那么如何修改已经推送到远程的author信息呢?

github 官方提供的建议如何变更用户信息

同时也有类似的项托管在github上,git-tips-blame-someone-else

思路基本一致,就是替换提交记录、分支、标签里的author信息。

方案

1.打开终端或命令行(git bash)

2.创建一个你项目的全新裸库

1
2
git clone --bare https://github.com/user/repo.git
cd repo.git

3.复制粘贴脚本,并根据你的信息修改下面的变量:

1
2
3
OLD_EMAIL
CORRECT_NAME
CORRECT_EMAIL

脚本replace.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/sh

git filter-branch --env-filter '

OLD_EMAIL="your-old-email@example.com"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="your-correct-email@example.com"

if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_AUTHOR_NAME="$CORRECT_NAME"
export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags

4.执行这个脚本

sh replace.sh

5.察看Git历史有没有错误

git log

6.强制推送到远程

git push --force --tags origin 'refs/heads/*'

7.清除repo.git仓库

1
2
cd ..
rm -rf repo.git

how to understand git detached HEAD

发表于 2016-08-08 | 更新于 2022-08-18
本文字数: 1.8k | 阅读时长 ≈ 2 分钟

场景

远程有一个develop分支,我想获取到本地,但是clone该项目的时候这个远程分支还没有创建,于是执行 git checkout commit_id(develop) 提示如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ git checkout f7c774b
Checking out files: 100% (357/357), done.
Note: checking out 'f7c774b'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

git checkout -b new_branch_name

HEAD is now at f7c774b... update jeffsui.github.io

出现 detached from ...

此时用git branch -av察看分支

1
2
3
4
5
6
7
$ git branch -av
* (detached from f7c774b) f7c774b update jeffsui.github.io
master 6ce1857 Site updated: 2016-08-07 22:09:10
remotes/origin/HEAD -> origin/master
remotes/origin/develop f7c774b update jeffsui.github.io
remotes/origin/gh-pages 1eee93f Site updated: 2016-02-13 21:03:46
remotes/origin/master 6ce1857 Site updated: 2016-08-07 22:09:10

所谓的 detached HEAD 其实就是HEAD指向的是一个commit而不指向任何一个branch的临时分支,翻译过来就是游离.

众所周知,每一个分支都对应了一个commit,git checkout其实就是修改HEAD文件内容,让它指向不同的分支.

如何让detached HEAD所处分支指向远程分支

此时的分支你可以执行commit操作,但是无法push到远程分支。
那么我们如何把游离状态的分支指向我们指定的远程分支呢。

1
2
3
$ git fetch origin develop:develop
From https://github.com/jeffsui/jeffsui.github.io
* [new branch] develop -> develop

继续执行git branch -av 命令查看分支

1
2
3
4
5
6
7
8
$ git branch -av
* (detached from f7c774b) f7c774b update jeffsui.github.io
develop f7c774b update jeffsui.github.io
master 6ce1857 Site updated: 2016-08-07 22:09:10
remotes/origin/HEAD -> origin/master
remotes/origin/develop f7c774b update jeffsui.github.io
remotes/origin/gh-pages 1eee93f Site updated: 2016-02-13 21:03:46
remotes/origin/master 6ce1857 Site updated: 2016-08-07 22:09:10

此时我们发现多了一个develop分支指向了远程develop 分支,这样我们就可以通过命令git push origin develop:develop到远程分支了。

更简洁的方法

git fetch origin develop:develop

or

git checkount -b origin develop:develop 这样可以直接获取远程分支并创建一个本地分支。

my-angle

发表于 2016-02-15 | 更新于 2022-08-18
本文字数: 0 | 阅读时长 ≈ 1 分钟

windows-mongodb-install

发表于 2016-02-13 | 更新于 2022-08-18 | 分类于 db
本文字数: 961 | 阅读时长 ≈ 1 分钟

windows下mongodb安装

下载mongodb

http://www.mongodb.org/downloads

选择自定义安装

本机路径为:d:\tools\mongodb

建立如下文件目录

数据库路径:d:\tools\mongodb\db
日志路径:d:\tools\mongodb\log
配置文件目录d:\tools\mongodb\etc
建立配置文件d:\tools\mongodb\etc\mongodb.conf

1
2
3
4
5
6
dbpath=d:\tools\mongodb\db #数据库路径
logpath=d:\tools\mongodb\log\mongodb.log #日志输出文件路径
logappend=true #错误日志采用追加模式,配置这个选项后mongodb的日志会追加到现有的日志文件,而不是从新创建一个新文件
journal=true #启用日志文件,默认启用
quiet=true #这个选项可以过滤掉一些无用的日志信息,若需要调试使用请设置为false
port=27017 #端口号 默认为27017

启动服务

切换到d:\tools\mongodb\bin 目录下:

  • 普通启动

mongod --config d:\tools\mongodb\etc\mongodb.conf

  • 注册为windows服务

mongod --config d:\tools\mongodb\etc\mongodb.conf --install

补充

  • windows服务卸载

mongod --remove --serviceName "MongoDB"

  • 启动服务
    net start mongodb

启动成功后,通过浏览器访问 http://localhost:27017 ,看到下面的文字,证明启动服务成功!

It looks like you are trying to access MongoDB over HTTP on the native driver port.

  • 关闭服务
    net stop mongodb

图形化工具

官方提供的很全:https://docs.mongodb.org/ecosystem/tools/administration-interfaces/

  • mongo express –Nodejs

  • MongoBooster

  • UMongo

  • MongoHub

  • MongoVUE –.NET

1…13141516
Jeff Sui

Jeff Sui

153 日志
40 分类
175 标签
RSS
GitHub E-Mail
  • 20201
  • 2to31
  • Boolean1
  • Centos2
  • Exception1
  • GIL1
  • GitGutter1
  • Tkinter1
  • TypeScript2
  • XML2
  • __all__1
  • _thread1
  • app1
  • argparse2
  • array1
  • atexit1
  • bisect1
  • calendar1
  • centos1
  • checkbox1
  • cmath1
  • cmd1
  • code1
  • collections.abc1
  • concurrent1
  • conda1
  • context-manager-types1
  • cookies1
  • copy1
  • coroutines1
  • csv1
  • cygwin1
  • dataclasses1
  • dbm1
  • dict1
  • dictionary1
  • difflib1
  • dis1
  • django4
  • docker3
  • doctest1
  • dom1
  • eclipse1
  • enum1
  • es61
  • esp323
  • esptool1
  • ffmpeg1
  • filecmp1
  • fileinput1
  • fractions1
  • functools1
  • futures1
  • gc1
  • generator1
  • git4
  • gitcafe1
  • github1
  • glob1
  • heapq1
  • hexo2
  • html.parser1
  • http2
  • http.server1
  • ios1
  • iterator1
  • itertools1
  • java3
  • javascript6
  • javaweb2
  • jdk1
  • jira1
  • json1
  • juypter1
  • keyword1
  • linecache1
  • linter1
  • linux2
  • lite-server1
  • m3u81
  • maven4
  • micorpython1
  • micropython2
  • minidom1
  • modulefinder1
  • mongodb1
  • mybatis1
  • mysql1
  • nbextension1
  • nginx1
  • nodejs2
  • ollama1
  • oop1
  • operator1
  • os1
  • os.path1
  • others1
  • pathlib1
  • photo1
  • pickle1
  • pprint1
  • pwd1
  • pycharm1
  • python99
  • python31
  • queue1
  • re1
  • readline1
  • registry2
  • registry-ui2
  • reprlib1
  • rust1
  • sax1
  • sched1
  • select1
  • selectors1
  • selenium3
  • shutil1
  • socket1
  • sort1
  • spring1
  • sqlite32
  • ssm1
  • standar_library1
  • standard_library78
  • statistics1
  • string2
  • sublime1
  • tempfile1
  • this1
  • thread1
  • timeit1
  • turtle2
  • types1
  • uPycraft1
  • unittest1
  • urllib.robotparser1
  • uuid1
  • uv1
  • venv1
  • vite1
  • vscode1
  • vue31
  • weakref1
  • web test2
  • webbrowser1
  • webrepl1
  • windows3
  • xml2
  • 二维码1
  • 办公1
  • 博客3
  • 坑1
  • 字典1
  • 异步1
  • 循环1
  • 感悟1
  • 持续集成1
  • 搭建1
  • 搭建博客1
  • 文章1
  • 新特性1
  • 杂记3
  • 版本管理2
  • 短网址1
  • 禅道1
  • 笔记1
  • 约束1
  • 网易音乐1
  • 美化1
  • 自动化测试1
  • 软件工程1
  • 逆向工程1
  • 闭包1
  • 项目管理2
© 2015 – 2026 Jeff Sui | 827k | 12:32
由 Hexo 强力驱动 v3.9.0
|
主题 – NexT.Gemini v7.1.1
|
0%