-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsnipet_cpde.json
More file actions
executable file
·93 lines (85 loc) · 2.43 KB
/
snipet_cpde.json
File metadata and controls
executable file
·93 lines (85 loc) · 2.43 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
{
"config logging": {
"prefix": "log",
"body": [
"logging.basicConfig(level=logging.INFO,format='%(asctime)s - %(levelname)s : %(message)s')",
"$2"
],
"description": "auto import logging"
},
"config import": {
"prefix": "import",
"body": [
"import pymongo",
"import requests",
"import logging",
"import json",
"import re",
"from urllib.parse import urljoin",
"from pyquery import PyQuery as pq",
"$2"
],
"description": "auto import logging"
},
"config import selenium ": {
"prefix": "selenium",
"body": [
"from selenium import webdriver",
"from selenium.common.exceptions import TimeoutException",
"from selenium.webdriver.common.keys import Keys",
"from selenium.webdriver.common.by import By",
"from selenium.webdriver.support import expected_conditions as EC ",
"from selenium.webdriver.support.wait import WebDriverWait",
"$2"
],
"description": "auto import selenium files"
},
"作者和时间注释": {
"prefix": "file",
"body": [
" # ",
" # Created by preference on $CURRENT_YEAR/$CURRENT_MONTH/$CURRENT_DATE",
" # Author: AlfredZKY",
" # Files:$TM_FILENAME",
" # WorkPlace:$WORKSPACE_NAME",
" # ",
"$0"
],
"description": "添加作者和时间注释"
},
"headless": {
"prefix": "headless",
"body": [
"# 开头无头模式",
"options = webdriver.ChromeOptions()",
"options.add_argument('--headless')",
"browser = webdriver.Chrome(options=options)",
"$0",
"# 实例化一个浏览器对象",
"TIME_OUT = 10",
"browser = webdriver.Chrome(options=options)",
],
"description": "配置无头模式"
},
"mongo": {
"prefix": "mongo",
"body": [
"import pymongo",
"MONGO_CONNECT_STRING = 'mongodb://127.0.0.1:27017'",
"MONGO_DB_NAME = 'movies'",
"MONGO_COLLECTION_NAME='movies'",
"client = pymongo.MongoClient(MONGO_CONNECT_STRING)",
"db = client[MONGO_DB_NAME]",
"collection = db[MONGO_COLLECTION_NAME]",
"$0",
"def save_data_to_mongo(data):",
"\t # 这里实际上是 upsert 参数,如果把这个设置为 True,则可以做到存在即更新,不存在即插入的功能,更新会根据第一个参数设置的 name 字段,所以这样可以防止数据库中出现同名的电影数据。",
"\t collection.update_one({",
"\t 'name':data.get('name')",
"\t },{",
"\t '$set':data",
"\t },upsert=True)"
],
"description": "配置mongo"
},
}