备忘录(一)

备忘

连接数据库

连接本地数据库的时候一定要记得把 VPN 代理关闭,否则连接失败。

http://www.postgresqltutorial.com/postgresql-python/connect/

PostgreSQL SELECT

UUID

http://www.postgresqltutorial.com/postgresql-uuid/

limit

http://www.postgresqltutorial.com/postgresql-limit/

upsert

1)UPSERT

UPSERT 是 INSERT, ON CONFLICT UPDATE 的简写,简而言之就是:插入数据,正常时写入,主键冲突时更新。以下给个简单的例子:

— 创建测试表,并插入一条数据

1
2
CREATE TABLE customer (cust_id INTEGER PRIMARY KEY, name TEXT);
INSERT INTO customer VALUES (100, ’Big customer’);

— 常规INSERT语句,主键冲突,报错

1
2
3
4
INSERT INTO customer VALUES (100, ’Non-paying customer’);
ERROR: duplicate key value violates unique constraint
"customer_pkey"
DETAIL: Key (cust_id)=(100) already exists.

— 新特性,主键冲突时,自动更新数据

1
2
INSERT INTO customer VALUES (100, ’Non-paying customer’)
ON CONFLICT (cust_id) DO UPDATE SET name = EXCLUDED.name;

SELECT * FROM customer;
cust_id | name
————-+——————————-
100 | Non-paying customer

Cannot INSERT: ERROR: array value must start with “{” or dimension information

https://stackoverflow.com/a/31519156/6920589


获取百度首页的文档树

1
2
3
4
5
6
7
8
9
10
11
12
13
14
>>> html_doc = urllib.request.urlopen("https://www.baidu.com").read()
>>> standard_html = BeautifulSoup(html_doc, 'html.parser')
>>> standard_html
<html>
<head>
<script>
location.replace(location.href.replace("https://","http://"));
</script>
</head>
<body>
<noscript><meta content="0;url=http://www.baidu.com/" http-equiv="refresh"/></noscript>
</body>
</html>
>>>

1. find_all() 找到所有标签

例如,从文档中找到所有 <a> 标签的链接:

1
2
3
4
5
for link in soup.find_all('a'):
print(link.get('href'))
# http://example.com/elsie
# http://example.com/lacie
# http://example.com/tillie

2. get_text() 获取标签与标签之间的内容

find_all() 方法用于定位 HTML 文本中的标签,get_text() 方法用于获取标签与标签之间的内容。注意,通常用 find_all() 得到的是一个 list,获取标签之间的内容还要通过索引一下。

1
2
3
4
5
6
7
>>> a = standard_html.find_all('script')
[<script>
location.replace(location.href.replace("https://","http://"));
</script>]

>>> a[0].get_text()
'\r\n\t\tlocation.replace(location.href.replace("https://","http://"));\r\n\t'

3. decompose

该方法将当前节点移除文档树。

1
2
3
4
5
6
7
8
9
10
>>> standard_html.script.decompose()
>>> standard_html
<html>
<head>

</head>
<body>
<noscript><meta content="0;url=http://www.baidu.com/" http-equiv="refresh"/></noscript>
</body>
</html>

参考链接

  1. BeautifulSoup4 中文文档
  2. BeautifulSoup4 decompose()
  3. BeautifulSoup4 get_text()
  4. BeautifulSoup4 find_all()

source

在当前Shell环境中从指定文件读取和执行命令,命令返回退出状态。

读取和执行/root/.bash_profile文件。

1
[root@localhost ~]# source ~/.bash_profile

unzip

解压缩文件

http://wangchujiang.com/linux-command/c/unzip.html

unzip test.zip 将压缩文件text.zip在当前目录下解压缩。

将压缩文件text.zip在指定目录/tmp下解压缩,如果已有相同的文件存在,要求unzip命令不覆盖原先的文件,unzip -n test.zip -d /tmp

查看压缩文件目录,但不解压,unzip -v test.zip

将压缩文件 test.zip 在指定目录 /tmp 下解压缩,如果已有相同的文件存在,要求 unzip 命令覆盖原先的文件,unzip -o test.zip -d tmp/


Another git process seems to be running in this repository

https://stackoverflow.com/a/40453027/6920589

还有一个原因,就是同时向 Git 添加了太多的文件,一个一个添加就不会出现这个问题。


列表合并

https://zhidao.baidu.com/question/328728387.html


人工智能标记语言 AIML

知识单元(knowledge unit),包含输入问题、输出问题和可选正文(optional context)。

根据用户的问题而回复的模板,问题

推荐阅读

https://www.pandorabots.com/pandora/pics/wallaceaimltutorial.html

https://www.v2ex.com/t/41072

继续阅读本站其他精彩文章

  1. 机器学习
  2. 编程语言
  3. 技术碎碎念
  4. 读书笔记
------本文结束,欢迎收藏本站、分享、评论或联系作者!------
点击查看
赠人玫瑰 手有余香
0%