commit
Browse files- jsfiles/js_script.js +257 -3
- jsfiles/jslearn.html +10 -7
- jsfiles/jslearn.md +43 -0
- leetcodemore.ipynb +132 -69
- notebook_for_knit.ipynb +307 -0
jsfiles/js_script.js
CHANGED
@@ -1,6 +1,260 @@
|
|
1 |
-
main()
|
2 |
|
3 |
function main() {
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
}
|
|
|
|
|
|
|
|
|
|
1 |
|
2 |
function main() {
|
3 |
+
console.log("Hello World!");
|
4 |
+
}
|
5 |
+
main()
|
6 |
+
var main = function() {
|
7 |
+
console.log("Hello World!2");
|
8 |
+
}
|
9 |
+
main()
|
10 |
+
|
11 |
+
/* ========================================================================== */
|
12 |
+
/* if else: */
|
13 |
+
/* ========================================================================== */
|
14 |
+
|
15 |
+
var a = 5 > 4 ? 'yes' : 'no';
|
16 |
+
var b = 10 == '100' ? 'yes': 'no';
|
17 |
+
console.log(b, 'aaah', a)
|
18 |
+
|
19 |
+
|
20 |
+
main(85)
|
21 |
+
main(44)
|
22 |
+
main(98)
|
23 |
+
|
24 |
+
function main(grade) {
|
25 |
+
if (grade < 60) {
|
26 |
+
console.log('F');
|
27 |
+
} else if (grade < 70) {
|
28 |
+
console.log('D');
|
29 |
+
} else if (grade < 80) {
|
30 |
+
console.log('C');
|
31 |
+
} else if (grade < 90) {
|
32 |
+
console.log('B');
|
33 |
+
} else console.log('A');
|
34 |
+
}
|
35 |
+
|
36 |
+
/* ========================================================================== */
|
37 |
+
/* for loops; */
|
38 |
+
/* ========================================================================== */
|
39 |
+
|
40 |
+
for (let i = 0; i < 10; i++ ) { // for (assign, while, function apply)
|
41 |
+
console.log(i);
|
42 |
+
}
|
43 |
+
|
44 |
+
for (let i = 100; i >= 0; i-=5 ) {
|
45 |
+
console.log(i);
|
46 |
+
}
|
47 |
+
|
48 |
+
var data = [3, 7, 2, 9, 1, 11];
|
49 |
+
var sum = 0;
|
50 |
+
data.forEach(function(d){
|
51 |
+
sum += d;
|
52 |
+
console.log(sum);
|
53 |
+
});
|
54 |
+
|
55 |
+
var t = "Hello World";
|
56 |
+
for (let c of t) {
|
57 |
+
console.log(c);
|
58 |
+
}
|
59 |
+
|
60 |
+
|
61 |
+
|
62 |
+
var i=0
|
63 |
+
console.log('yes', i++<4, i, '\n') // i++ ==> i = i+1
|
64 |
+
while (i<5, i++<4) {
|
65 |
+
i += 2
|
66 |
+
console.log(i)
|
67 |
+
}
|
68 |
+
|
69 |
+
|
70 |
+
var i=0
|
71 |
+
var q="a string that cool"
|
72 |
+
do{
|
73 |
+
i++
|
74 |
+
console.log(q.charAt(2), m = q.split(/\s/))
|
75 |
+
for (let b = 0; (b<=1) | (b < m.length); b++) {
|
76 |
+
console.log(m[b])
|
77 |
+
}
|
78 |
+
}while(i<1)
|
79 |
+
|
80 |
+
|
81 |
+
// c to f temperature.
|
82 |
+
var main = function() {
|
83 |
+
var fahr;
|
84 |
+
fahr = prompt("Enter the temperature in F: ");
|
85 |
+
const ratio = 5.0/9.0;
|
86 |
+
let cel = (fahr - 32) * ratio;
|
87 |
+
writeln("The temperature in C is: " + cel);
|
88 |
+
}
|
89 |
+
|
90 |
+
main()
|
91 |
+
|
92 |
+
|
93 |
+
|
94 |
+
function removeVowels(s) {
|
95 |
+
const vowels = "aeiouAEIOU";
|
96 |
+
let sWithoutVowels = "";
|
97 |
+
for (let eachChar of s) {
|
98 |
+
// console.log(s, '===', eachChar, '===', vowels.indexOf(eachChar))
|
99 |
+
if (vowels.indexOf(eachChar) === -1) {
|
100 |
+
sWithoutVowels = sWithoutVowels + eachChar
|
101 |
+
}
|
102 |
+
}
|
103 |
+
return sWithoutVowels
|
104 |
+
}
|
105 |
+
|
106 |
+
console.log(removeVowels("asjdiajisjd1ijinfss"))
|
107 |
+
|
108 |
+
|
109 |
+
// array & set.
|
110 |
+
|
111 |
+
var s = new String('0');
|
112 |
+
console.log(s??false);
|
113 |
+
console.log(s);
|
114 |
+
|
115 |
+
|
116 |
+
var arr = []
|
117 |
+
console.log(arr instanceof Array, Array.isArray(arr))
|
118 |
+
|
119 |
+
var set = new Set([1, 2])
|
120 |
+
console.log(typeof set, typeof Array.from(set))
|
121 |
+
console.log(Array.from(set))
|
122 |
+
|
123 |
+
/* ========================================================================== */
|
124 |
+
/* 数组去重: */
|
125 |
+
/* ========================================================================== */
|
126 |
+
var arr = [1, 2, 2, 4, 9, 6, 7, 5, 2, 3, 5, 6, 5]
|
127 |
+
// console.log(Array.from(new Set(arr)))
|
128 |
+
console.log(arr, '\n',(new Set(arr)))
|
129 |
+
console.log(Array.from(new Set(arr)))
|
130 |
+
// set() 就可以去重
|
131 |
+
|
132 |
+
//2. write a function;
|
133 |
+
|
134 |
+
var arr = [1, 2, 2, 4, 9, 6, 7, 5, 2, 3, 5, 6, 5]
|
135 |
+
function gunique1(arr){
|
136 |
+
let newArr = [-1]
|
137 |
+
let arrsort= arr.sort()
|
138 |
+
for (let i=0; i<arr.length; i++){
|
139 |
+
if (arrsort[i] > newArr[newArr.length - 1]){
|
140 |
+
newArr.push(arrsort[i])
|
141 |
+
// console.log(arrsort[i], newArr[newArr.length - 1], arrsort[i] > newArr[newArr.length - 1])
|
142 |
+
}
|
143 |
+
}
|
144 |
+
newArr.shift() // removes the first element of an array
|
145 |
+
return console.log(newArr)
|
146 |
+
};
|
147 |
+
|
148 |
+
gunique1(arr)
|
149 |
+
|
150 |
+
//
|
151 |
+
var arr = [1, 2, 2, 4, 9, 6, 7, 5, 2, 3, 5, 6, 5]
|
152 |
+
function unique(arr) {
|
153 |
+
arr.sort()
|
154 |
+
let newArr = [arr[0]]
|
155 |
+
for (let i = 0; i < arr.length; i++) {
|
156 |
+
let item = arr[i] // item = 0 now.
|
157 |
+
if (newArr[newArr.length - 1] !== item) {
|
158 |
+
newArr.push(item)
|
159 |
+
}
|
160 |
+
}
|
161 |
+
return newArr
|
162 |
+
}
|
163 |
+
unique(arr)
|
164 |
+
|
165 |
+
// flatten array
|
166 |
+
var arr = [1, 2, [3, [4, 5]]]
|
167 |
+
console.log(arr.flat(Infinity))
|
168 |
+
|
169 |
+
|
170 |
+
var arr = [1, 2, [3, [4, 5]]]
|
171 |
+
function flat(arr) {
|
172 |
+
let str = JSON.stringify(arr).replace(/[\[|\]]/g, '')
|
173 |
+
str = `[${str}]`
|
174 |
+
return JSON.parse(str)
|
175 |
+
}
|
176 |
+
console.log(flat(arr))
|
177 |
+
|
178 |
+
|
179 |
+
|
180 |
+
/* ========================================================================== */
|
181 |
+
/* arrow functions in js */
|
182 |
+
/* ========================================================================== */
|
183 |
+
var materials = [
|
184 |
+
'Hydrogen',
|
185 |
+
'Helium',
|
186 |
+
'Lithium',
|
187 |
+
'Beryllium'
|
188 |
+
];
|
189 |
+
|
190 |
+
console.log(materials.map(material => material.length));
|
191 |
+
// expected output: Array [8, 6, 7, 9]
|
192 |
+
|
193 |
+
|
194 |
+
(function (a) {
|
195 |
+
return console.log(a + 100);
|
196 |
+
})(3)
|
197 |
+
|
198 |
+
// (a) => {
|
199 |
+
// return console.log(a + 100);
|
200 |
+
// }; //easier version. a => a + 100;
|
201 |
+
|
202 |
+
|
203 |
+
var materials = [
|
204 |
+
'Hydrogen',
|
205 |
+
'Helium',
|
206 |
+
'Lithium',
|
207 |
+
'Beryllium'
|
208 |
+
];
|
209 |
+
var b = ['sda','asda','asd', 'bsdf']
|
210 |
+
b.map((a,b)=>console.log(a+b+'aaaa')) // arrow function second element is index.
|
211 |
+
|
212 |
+
// sort arr
|
213 |
+
|
214 |
+
var arr = [2, 7, 0, 6, 1, 4, 8, 3]
|
215 |
+
console.log((arr) instanceof Array, typeof arr)
|
216 |
+
console.log(arr.sort())
|
217 |
+
console.log(arr.sort().reverse())
|
218 |
+
|
219 |
+
console.log(arr.sort((a, b) => a - b)) // 递增
|
220 |
+
console.log(arr.sort((a, b) => b - a)) // 递减
|
221 |
+
|
222 |
+
|
223 |
+
/* ========================================================================== */
|
224 |
+
/* class */
|
225 |
+
/* ========================================================================== */
|
226 |
+
|
227 |
+
function Animal(name, size) {
|
228 |
+
this.name = name
|
229 |
+
this.size = size
|
230 |
+
}
|
231 |
+
|
232 |
+
Animal.prototype.eat = function (food) {
|
233 |
+
console.log(this.name + "is eating " + food, "and " + this.name +' is getting fatter of ' + this.size)
|
234 |
+
}
|
235 |
+
|
236 |
+
var ani = new Animal('xiaoyou', '15 kilo')
|
237 |
+
ani.eat('banana')
|
238 |
+
// xiaoyouis eating banana and xiaoyou is getting fatter of 15 kilo
|
239 |
+
|
240 |
+
class Rectangle {
|
241 |
+
constructor(height, width) {
|
242 |
+
this.height = height;
|
243 |
+
this.width = width;
|
244 |
+
}
|
245 |
+
// Getter
|
246 |
+
get area() {
|
247 |
+
return this.calcArea();
|
248 |
+
}
|
249 |
+
// Method
|
250 |
+
calcArea() {
|
251 |
+
return this.height * this.width;
|
252 |
+
}
|
253 |
+
|
254 |
+
calcVolume(length){
|
255 |
+
return this.height * this.width * length;
|
256 |
+
}
|
257 |
}
|
258 |
+
const square = new Rectangle(10, 10);
|
259 |
+
console.log(square.area); // 100
|
260 |
+
console.log(square.calcVolume(22)); // 2200
|
jsfiles/jslearn.html
CHANGED
@@ -1,17 +1,20 @@
|
|
1 |
<!DOCTYPE html>
|
2 |
-
<script src="https://cdn.jsdelivr.net/npm/vue@2.7.7/dist/vue.js"></script>
|
3 |
<html>
|
4 |
<body>
|
5 |
<p>Before the script...</p>
|
6 |
|
7 |
<script>
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
-
|
12 |
-
<div id="app">
|
13 |
-
<button @click="count++">Count is: {{ count }}</button>
|
14 |
-
</div>
|
15 |
|
16 |
<p>...After the script.</p>
|
17 |
</body>
|
|
|
1 |
<!DOCTYPE html>
|
2 |
+
<!-- <script src="https://cdn.jsdelivr.net/npm/vue@2.7.7/dist/vue.js"></script> -->
|
3 |
<html>
|
4 |
<body>
|
5 |
<p>Before the script...</p>
|
6 |
|
7 |
<script>
|
8 |
+
var main = function() {
|
9 |
+
var fahr;
|
10 |
+
fahr = prompt("Enter the temperature in F: ");
|
11 |
+
const ratio = 5.0/9.0;
|
12 |
+
let cel = (fahr - 32) * ratio;
|
13 |
+
alert("The temperature in C is: " + cel);
|
14 |
+
}
|
15 |
+
main()
|
16 |
|
17 |
+
</script>
|
|
|
|
|
|
|
18 |
|
19 |
<p>...After the script.</p>
|
20 |
</body>
|
jsfiles/jslearn.md
CHANGED
@@ -1,6 +1,49 @@
|
|
1 |
```yaml
|
2 |
author: Siming Yan
|
3 |
title: jslearning
|
|
|
4 |
```
|
5 |
|
6 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
```yaml
|
2 |
author: Siming Yan
|
3 |
title: jslearning
|
4 |
+
url: https://runestone.academy/ns/books/published/JS4Python/TheBasics/loops.html
|
5 |
```
|
6 |
|
7 |
---
|
8 |
+
|
9 |
+
```javascript
|
10 |
+
|
11 |
+
|
12 |
+
function main() {
|
13 |
+
console.log("Hello World!");
|
14 |
+
}
|
15 |
+
main()
|
16 |
+
var main = function() {
|
17 |
+
console.log("Hello World!2");
|
18 |
+
}
|
19 |
+
main()
|
20 |
+
let a = 5 > 4 ? 'yes' : 'no';
|
21 |
+
let b = 10 == '100' ? 'yes': 'no';
|
22 |
+
console.log(a,'haha',b)
|
23 |
+
```
|
24 |
+
|
25 |
+
```javascript
|
26 |
+
main(85)
|
27 |
+
main(44)
|
28 |
+
main(98)
|
29 |
+
|
30 |
+
function main(grade) {
|
31 |
+
if (grade < 60) {
|
32 |
+
console.log('F');
|
33 |
+
} else if (grade < 70) {
|
34 |
+
console.log('D');
|
35 |
+
} else if (grade < 80) {
|
36 |
+
console.log('C');
|
37 |
+
} else if (grade < 90) {
|
38 |
+
console.log('B');
|
39 |
+
} else console.log('A');
|
40 |
+
}
|
41 |
+
|
42 |
+
|
43 |
+
```
|
44 |
+
|
45 |
+
|
46 |
+
|
47 |
+
|
48 |
+
|
49 |
+
|
leetcodemore.ipynb
CHANGED
@@ -2,75 +2,29 @@
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
-
"execution_count":
|
6 |
"metadata": {},
|
7 |
-
"outputs": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
"source": [
|
9 |
-
"
|
10 |
-
"
|
11 |
-
"
|
12 |
-
"
|
13 |
-
"
|
14 |
-
"\n",
|
15 |
-
"
|
16 |
-
"# \"\"\"\n",
|
17 |
-
"# 对每一行pd df_row 的循环. \n",
|
18 |
-
"# \"\"\"\n",
|
19 |
-
"# text = '''<p style=\"font-family:等线;font-size:10.5pt\">Dear \n",
|
20 |
-
"# <mark><b></b></mark> \n",
|
21 |
-
"# '''\n",
|
22 |
"\n",
|
23 |
-
"
|
24 |
-
"
|
25 |
-
"# msg = MIMEMultipart()\n",
|
26 |
-
"# msg['Subject'] = subject\n",
|
27 |
-
"# msg['From'] = account\n",
|
28 |
-
"# receivers = receivers\n",
|
29 |
-
"# msg['TO'] = receivers\n",
|
30 |
-
"# msg['Cc'] = ''\n",
|
31 |
-
"# text = msg.as_string()\n",
|
32 |
-
"# server.sendmail(account, receivers, text)\n",
|
33 |
-
"# # print('success')\n",
|
34 |
-
"# # server.quit()\n",
|
35 |
-
"# # time.sleep(2)\n",
|
36 |
-
" \n",
|
37 |
-
"# if __name__ == '__main__':\n",
|
38 |
-
"# server = smtplib.SMTP(\"smtp.office365.com\", 587)\n",
|
39 |
-
"# server.starttls()\n",
|
40 |
-
"# server.login('fyenneyenn@hotmail.com', 'NOmoreuse7-') \n",
|
41 |
-
"# print('connecting...')\n",
|
42 |
-
"# sendEmailwithFile('fyenneyenn@hotmail.com', server = server, receivers='fyenne@hotmail.com')\n",
|
43 |
-
"# server.quit()\n",
|
44 |
-
"import pandas as pd\n",
|
45 |
-
"a = pd.read_clipboard(sep = ',', header = None)\n",
|
46 |
-
"b = pd.read_clipboard(sep = ',', header = None); "
|
47 |
-
]
|
48 |
-
},
|
49 |
-
{
|
50 |
-
"cell_type": "code",
|
51 |
-
"execution_count": null,
|
52 |
-
"metadata": {},
|
53 |
-
"outputs": [],
|
54 |
-
"source": [
|
55 |
-
"b[0] = b[0].str.strip()"
|
56 |
-
]
|
57 |
-
},
|
58 |
-
{
|
59 |
-
"cell_type": "code",
|
60 |
-
"execution_count": null,
|
61 |
-
"metadata": {},
|
62 |
-
"outputs": [],
|
63 |
-
"source": [
|
64 |
-
"# pd.read_clipboard(header = None, sep = '\\n')"
|
65 |
-
]
|
66 |
-
},
|
67 |
-
{
|
68 |
-
"cell_type": "code",
|
69 |
-
"execution_count": null,
|
70 |
-
"metadata": {},
|
71 |
-
"outputs": [],
|
72 |
-
"source": [
|
73 |
-
"'ou_code' in list(a[0])"
|
74 |
]
|
75 |
},
|
76 |
{
|
@@ -366,6 +320,62 @@
|
|
366 |
"func_(infixexp)"
|
367 |
]
|
368 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
369 |
{
|
370 |
"cell_type": "code",
|
371 |
"execution_count": 175,
|
@@ -432,9 +442,51 @@
|
|
432 |
},
|
433 |
{
|
434 |
"cell_type": "code",
|
435 |
-
"execution_count":
|
436 |
"metadata": {},
|
437 |
-
"outputs": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
438 |
"source": [
|
439 |
"import requests \n",
|
440 |
"from bs4 import BeautifulSoup\n",
|
@@ -447,7 +499,7 @@
|
|
447 |
},
|
448 |
{
|
449 |
"cell_type": "code",
|
450 |
-
"execution_count":
|
451 |
"metadata": {},
|
452 |
"outputs": [],
|
453 |
"source": [
|
@@ -572,6 +624,17 @@
|
|
572 |
"\n",
|
573 |
"# # fig.show()"
|
574 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
575 |
}
|
576 |
],
|
577 |
"metadata": {
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stdout",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"cmpsc\n",
|
13 |
+
"bfjps\n"
|
14 |
+
]
|
15 |
+
}
|
16 |
+
],
|
17 |
"source": [
|
18 |
+
"def removeVowels(s):\n",
|
19 |
+
" vowels = \"aeiouAEIOU\"\n",
|
20 |
+
" sWithoutVowels = \"\"\n",
|
21 |
+
" for eachChar in s:\n",
|
22 |
+
" if eachChar not in vowels:\n",
|
23 |
+
" sWithoutVowels = sWithoutVowels + eachChar\n",
|
24 |
+
" return sWithoutVowels\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
"\n",
|
26 |
+
"print(removeVowels(\"compsci\"))\n",
|
27 |
+
"print(removeVowels(\"aAbEefIijOopUus\"))\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
]
|
29 |
},
|
30 |
{
|
|
|
320 |
"func_(infixexp)"
|
321 |
]
|
322 |
},
|
323 |
+
{
|
324 |
+
"cell_type": "code",
|
325 |
+
"execution_count": 2,
|
326 |
+
"metadata": {},
|
327 |
+
"outputs": [],
|
328 |
+
"source": [
|
329 |
+
"# a dp pract"
|
330 |
+
]
|
331 |
+
},
|
332 |
+
{
|
333 |
+
"cell_type": "code",
|
334 |
+
"execution_count": null,
|
335 |
+
"metadata": {},
|
336 |
+
"outputs": [],
|
337 |
+
"source": [
|
338 |
+
"# Python3 program to find a maximum\n",
|
339 |
+
"# product of a triplet in array\n",
|
340 |
+
"# of integers\n",
|
341 |
+
"import sys\n",
|
342 |
+
"\n",
|
343 |
+
"# Function to find a maximum\n",
|
344 |
+
"# product of a triplet in array\n",
|
345 |
+
"# of integers of size n\n",
|
346 |
+
"def maxProduct(arr, n):\n",
|
347 |
+
"\n",
|
348 |
+
"\t# if size is less than 3,\n",
|
349 |
+
"\t# no triplet exists\n",
|
350 |
+
"\tif n < 3:\n",
|
351 |
+
"\t\treturn -1\n",
|
352 |
+
"\n",
|
353 |
+
"\t# will contain max product\n",
|
354 |
+
"\tmax_product = -(sys.maxsize - 1)\n",
|
355 |
+
"\t\n",
|
356 |
+
"\tfor i in range(0, n - 2):\n",
|
357 |
+
"\t\tfor j in range(i + 1, n - 1):\n",
|
358 |
+
"\t\t\tfor k in range(j + 1, n):\n",
|
359 |
+
"\t\t\t\tmax_product = max(\n",
|
360 |
+
"\t\t\t\t\tmax_product, arr[i]\n",
|
361 |
+
"\t\t\t\t\t* arr[j] * arr[k])\n",
|
362 |
+
"\n",
|
363 |
+
"\treturn max_product\n",
|
364 |
+
"\n",
|
365 |
+
"# Driver Program\n",
|
366 |
+
"arr = [10, 3, 5, 6, 20]\n",
|
367 |
+
"n = len(arr)\n",
|
368 |
+
"\n",
|
369 |
+
"max = maxProduct(arr, n)\n",
|
370 |
+
"\n",
|
371 |
+
"if max == -1:\n",
|
372 |
+
"\tprint(\"No Tripplet Exits\")\n",
|
373 |
+
"else:\n",
|
374 |
+
"\tprint(\"Maximum product is\", max)\n",
|
375 |
+
"\n",
|
376 |
+
"# This code is contributed by Shrikant13\n"
|
377 |
+
]
|
378 |
+
},
|
379 |
{
|
380 |
"cell_type": "code",
|
381 |
"execution_count": 175,
|
|
|
442 |
},
|
443 |
{
|
444 |
"cell_type": "code",
|
445 |
+
"execution_count": 7,
|
446 |
"metadata": {},
|
447 |
+
"outputs": [
|
448 |
+
{
|
449 |
+
"ename": "ConnectTimeout",
|
450 |
+
"evalue": "HTTPConnectionPool(host='quotes.toscrape.com', port=80): Max retries exceeded with url: /author/Albert-Einstein/ (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x0000022B063F5AC0>, 'Connection to quotes.toscrape.com timed out. (connect timeout=5)'))",
|
451 |
+
"output_type": "error",
|
452 |
+
"traceback": [
|
453 |
+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
454 |
+
"\u001b[1;31mtimeout\u001b[0m Traceback (most recent call last)",
|
455 |
+
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\site-packages\\urllib3\\connection.py:174\u001b[0m, in \u001b[0;36mHTTPConnection._new_conn\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 173\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[1;32m--> 174\u001b[0m conn \u001b[39m=\u001b[39m connection\u001b[39m.\u001b[39;49mcreate_connection(\n\u001b[0;32m 175\u001b[0m (\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_dns_host, \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mport), \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mtimeout, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mextra_kw\n\u001b[0;32m 176\u001b[0m )\n\u001b[0;32m 178\u001b[0m \u001b[39mexcept\u001b[39;00m SocketTimeout:\n",
|
456 |
+
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\site-packages\\urllib3\\util\\connection.py:96\u001b[0m, in \u001b[0;36mcreate_connection\u001b[1;34m(address, timeout, source_address, socket_options)\u001b[0m\n\u001b[0;32m 95\u001b[0m \u001b[39mif\u001b[39;00m err \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[1;32m---> 96\u001b[0m \u001b[39mraise\u001b[39;00m err\n\u001b[0;32m 98\u001b[0m \u001b[39mraise\u001b[39;00m socket\u001b[39m.\u001b[39merror(\u001b[39m\"\u001b[39m\u001b[39mgetaddrinfo returns an empty list\u001b[39m\u001b[39m\"\u001b[39m)\n",
|
457 |
+
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\site-packages\\urllib3\\util\\connection.py:86\u001b[0m, in \u001b[0;36mcreate_connection\u001b[1;34m(address, timeout, source_address, socket_options)\u001b[0m\n\u001b[0;32m 85\u001b[0m sock\u001b[39m.\u001b[39mbind(source_address)\n\u001b[1;32m---> 86\u001b[0m sock\u001b[39m.\u001b[39;49mconnect(sa)\n\u001b[0;32m 87\u001b[0m \u001b[39mreturn\u001b[39;00m sock\n",
|
458 |
+
"\u001b[1;31mtimeout\u001b[0m: timed out",
|
459 |
+
"\nDuring handling of the above exception, another exception occurred:\n",
|
460 |
+
"\u001b[1;31mConnectTimeoutError\u001b[0m Traceback (most recent call last)",
|
461 |
+
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\site-packages\\urllib3\\connectionpool.py:699\u001b[0m, in \u001b[0;36mHTTPConnectionPool.urlopen\u001b[1;34m(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)\u001b[0m\n\u001b[0;32m 698\u001b[0m \u001b[39m# Make the request on the httplib connection object.\u001b[39;00m\n\u001b[1;32m--> 699\u001b[0m httplib_response \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_make_request(\n\u001b[0;32m 700\u001b[0m conn,\n\u001b[0;32m 701\u001b[0m method,\n\u001b[0;32m 702\u001b[0m url,\n\u001b[0;32m 703\u001b[0m timeout\u001b[39m=\u001b[39;49mtimeout_obj,\n\u001b[0;32m 704\u001b[0m body\u001b[39m=\u001b[39;49mbody,\n\u001b[0;32m 705\u001b[0m headers\u001b[39m=\u001b[39;49mheaders,\n\u001b[0;32m 706\u001b[0m chunked\u001b[39m=\u001b[39;49mchunked,\n\u001b[0;32m 707\u001b[0m )\n\u001b[0;32m 709\u001b[0m \u001b[39m# If we're going to release the connection in ``finally:``, then\u001b[39;00m\n\u001b[0;32m 710\u001b[0m \u001b[39m# the response doesn't need to know about the connection. Otherwise\u001b[39;00m\n\u001b[0;32m 711\u001b[0m \u001b[39m# it will also try to release it and we'll have a double-release\u001b[39;00m\n\u001b[0;32m 712\u001b[0m \u001b[39m# mess.\u001b[39;00m\n",
|
462 |
+
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\site-packages\\urllib3\\connectionpool.py:394\u001b[0m, in \u001b[0;36mHTTPConnectionPool._make_request\u001b[1;34m(self, conn, method, url, timeout, chunked, **httplib_request_kw)\u001b[0m\n\u001b[0;32m 393\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m--> 394\u001b[0m conn\u001b[39m.\u001b[39;49mrequest(method, url, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mhttplib_request_kw)\n\u001b[0;32m 396\u001b[0m \u001b[39m# We are swallowing BrokenPipeError (errno.EPIPE) since the server is\u001b[39;00m\n\u001b[0;32m 397\u001b[0m \u001b[39m# legitimately able to close the connection after sending a valid response.\u001b[39;00m\n\u001b[0;32m 398\u001b[0m \u001b[39m# With this behaviour, the received response is still readable.\u001b[39;00m\n",
|
463 |
+
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\site-packages\\urllib3\\connection.py:239\u001b[0m, in \u001b[0;36mHTTPConnection.request\u001b[1;34m(self, method, url, body, headers)\u001b[0m\n\u001b[0;32m 238\u001b[0m headers[\u001b[39m\"\u001b[39m\u001b[39mUser-Agent\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39m=\u001b[39m _get_default_user_agent()\n\u001b[1;32m--> 239\u001b[0m \u001b[39msuper\u001b[39;49m(HTTPConnection, \u001b[39mself\u001b[39;49m)\u001b[39m.\u001b[39;49mrequest(method, url, body\u001b[39m=\u001b[39;49mbody, headers\u001b[39m=\u001b[39;49mheaders)\n",
|
464 |
+
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\http\\client.py:1255\u001b[0m, in \u001b[0;36mHTTPConnection.request\u001b[1;34m(self, method, url, body, headers, encode_chunked)\u001b[0m\n\u001b[0;32m 1254\u001b[0m \u001b[39m\"\"\"Send a complete request to the server.\"\"\"\u001b[39;00m\n\u001b[1;32m-> 1255\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_send_request(method, url, body, headers, encode_chunked)\n",
|
465 |
+
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\http\\client.py:1301\u001b[0m, in \u001b[0;36mHTTPConnection._send_request\u001b[1;34m(self, method, url, body, headers, encode_chunked)\u001b[0m\n\u001b[0;32m 1300\u001b[0m body \u001b[39m=\u001b[39m _encode(body, \u001b[39m'\u001b[39m\u001b[39mbody\u001b[39m\u001b[39m'\u001b[39m)\n\u001b[1;32m-> 1301\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mendheaders(body, encode_chunked\u001b[39m=\u001b[39;49mencode_chunked)\n",
|
466 |
+
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\http\\client.py:1250\u001b[0m, in \u001b[0;36mHTTPConnection.endheaders\u001b[1;34m(self, message_body, encode_chunked)\u001b[0m\n\u001b[0;32m 1249\u001b[0m \u001b[39mraise\u001b[39;00m CannotSendHeader()\n\u001b[1;32m-> 1250\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_send_output(message_body, encode_chunked\u001b[39m=\u001b[39;49mencode_chunked)\n",
|
467 |
+
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\http\\client.py:1010\u001b[0m, in \u001b[0;36mHTTPConnection._send_output\u001b[1;34m(self, message_body, encode_chunked)\u001b[0m\n\u001b[0;32m 1009\u001b[0m \u001b[39mdel\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_buffer[:]\n\u001b[1;32m-> 1010\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49msend(msg)\n\u001b[0;32m 1012\u001b[0m \u001b[39mif\u001b[39;00m message_body \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[0;32m 1013\u001b[0m \n\u001b[0;32m 1014\u001b[0m \u001b[39m# create a consistent interface to message_body\u001b[39;00m\n",
|
468 |
+
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\http\\client.py:950\u001b[0m, in \u001b[0;36mHTTPConnection.send\u001b[1;34m(self, data)\u001b[0m\n\u001b[0;32m 949\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mauto_open:\n\u001b[1;32m--> 950\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mconnect()\n\u001b[0;32m 951\u001b[0m \u001b[39melse\u001b[39;00m:\n",
|
469 |
+
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\site-packages\\urllib3\\connection.py:205\u001b[0m, in \u001b[0;36mHTTPConnection.connect\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 204\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mconnect\u001b[39m(\u001b[39mself\u001b[39m):\n\u001b[1;32m--> 205\u001b[0m conn \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_new_conn()\n\u001b[0;32m 206\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_prepare_conn(conn)\n",
|
470 |
+
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\site-packages\\urllib3\\connection.py:179\u001b[0m, in \u001b[0;36mHTTPConnection._new_conn\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 178\u001b[0m \u001b[39mexcept\u001b[39;00m SocketTimeout:\n\u001b[1;32m--> 179\u001b[0m \u001b[39mraise\u001b[39;00m ConnectTimeoutError(\n\u001b[0;32m 180\u001b[0m \u001b[39mself\u001b[39m,\n\u001b[0;32m 181\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mConnection to \u001b[39m\u001b[39m%s\u001b[39;00m\u001b[39m timed out. (connect timeout=\u001b[39m\u001b[39m%s\u001b[39;00m\u001b[39m)\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m 182\u001b[0m \u001b[39m%\u001b[39m (\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mhost, \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mtimeout),\n\u001b[0;32m 183\u001b[0m )\n\u001b[0;32m 185\u001b[0m \u001b[39mexcept\u001b[39;00m SocketError \u001b[39mas\u001b[39;00m e:\n",
|
471 |
+
"\u001b[1;31mConnectTimeoutError\u001b[0m: (<urllib3.connection.HTTPConnection object at 0x0000022B063F5AC0>, 'Connection to quotes.toscrape.com timed out. (connect timeout=5)')",
|
472 |
+
"\nDuring handling of the above exception, another exception occurred:\n",
|
473 |
+
"\u001b[1;31mMaxRetryError\u001b[0m Traceback (most recent call last)",
|
474 |
+
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\site-packages\\requests\\adapters.py:439\u001b[0m, in \u001b[0;36mHTTPAdapter.send\u001b[1;34m(self, request, stream, timeout, verify, cert, proxies)\u001b[0m\n\u001b[0;32m 438\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m chunked:\n\u001b[1;32m--> 439\u001b[0m resp \u001b[39m=\u001b[39m conn\u001b[39m.\u001b[39;49murlopen(\n\u001b[0;32m 440\u001b[0m method\u001b[39m=\u001b[39;49mrequest\u001b[39m.\u001b[39;49mmethod,\n\u001b[0;32m 441\u001b[0m url\u001b[39m=\u001b[39;49murl,\n\u001b[0;32m 442\u001b[0m body\u001b[39m=\u001b[39;49mrequest\u001b[39m.\u001b[39;49mbody,\n\u001b[0;32m 443\u001b[0m headers\u001b[39m=\u001b[39;49mrequest\u001b[39m.\u001b[39;49mheaders,\n\u001b[0;32m 444\u001b[0m redirect\u001b[39m=\u001b[39;49m\u001b[39mFalse\u001b[39;49;00m,\n\u001b[0;32m 445\u001b[0m assert_same_host\u001b[39m=\u001b[39;49m\u001b[39mFalse\u001b[39;49;00m,\n\u001b[0;32m 446\u001b[0m preload_content\u001b[39m=\u001b[39;49m\u001b[39mFalse\u001b[39;49;00m,\n\u001b[0;32m 447\u001b[0m decode_content\u001b[39m=\u001b[39;49m\u001b[39mFalse\u001b[39;49;00m,\n\u001b[0;32m 448\u001b[0m retries\u001b[39m=\u001b[39;49m\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mmax_retries,\n\u001b[0;32m 449\u001b[0m timeout\u001b[39m=\u001b[39;49mtimeout\n\u001b[0;32m 450\u001b[0m )\n\u001b[0;32m 452\u001b[0m \u001b[39m# Send the request.\u001b[39;00m\n\u001b[0;32m 453\u001b[0m \u001b[39melse\u001b[39;00m:\n",
|
475 |
+
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\site-packages\\urllib3\\connectionpool.py:755\u001b[0m, in \u001b[0;36mHTTPConnectionPool.urlopen\u001b[1;34m(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)\u001b[0m\n\u001b[0;32m 753\u001b[0m e \u001b[39m=\u001b[39m ProtocolError(\u001b[39m\"\u001b[39m\u001b[39mConnection aborted.\u001b[39m\u001b[39m\"\u001b[39m, e)\n\u001b[1;32m--> 755\u001b[0m retries \u001b[39m=\u001b[39m retries\u001b[39m.\u001b[39;49mincrement(\n\u001b[0;32m 756\u001b[0m method, url, error\u001b[39m=\u001b[39;49me, _pool\u001b[39m=\u001b[39;49m\u001b[39mself\u001b[39;49m, _stacktrace\u001b[39m=\u001b[39;49msys\u001b[39m.\u001b[39;49mexc_info()[\u001b[39m2\u001b[39;49m]\n\u001b[0;32m 757\u001b[0m )\n\u001b[0;32m 758\u001b[0m retries\u001b[39m.\u001b[39msleep()\n",
|
476 |
+
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\site-packages\\urllib3\\util\\retry.py:574\u001b[0m, in \u001b[0;36mRetry.increment\u001b[1;34m(self, method, url, response, error, _pool, _stacktrace)\u001b[0m\n\u001b[0;32m 573\u001b[0m \u001b[39mif\u001b[39;00m new_retry\u001b[39m.\u001b[39mis_exhausted():\n\u001b[1;32m--> 574\u001b[0m \u001b[39mraise\u001b[39;00m MaxRetryError(_pool, url, error \u001b[39mor\u001b[39;00m ResponseError(cause))\n\u001b[0;32m 576\u001b[0m log\u001b[39m.\u001b[39mdebug(\u001b[39m\"\u001b[39m\u001b[39mIncremented Retry for (url=\u001b[39m\u001b[39m'\u001b[39m\u001b[39m%s\u001b[39;00m\u001b[39m'\u001b[39m\u001b[39m): \u001b[39m\u001b[39m%r\u001b[39;00m\u001b[39m\"\u001b[39m, url, new_retry)\n",
|
477 |
+
"\u001b[1;31mMaxRetryError\u001b[0m: HTTPConnectionPool(host='quotes.toscrape.com', port=80): Max retries exceeded with url: /author/Albert-Einstein/ (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x0000022B063F5AC0>, 'Connection to quotes.toscrape.com timed out. (connect timeout=5)'))",
|
478 |
+
"\nDuring handling of the above exception, another exception occurred:\n",
|
479 |
+
"\u001b[1;31mConnectTimeout\u001b[0m Traceback (most recent call last)",
|
480 |
+
"\u001b[1;32mc:\\Users\\dscshap3808\\Documents\\my_scripts_new\\stlit\\leetcodemore.ipynb Cell 17\u001b[0m in \u001b[0;36m<cell line: 5>\u001b[1;34m()\u001b[0m\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/dscshap3808/Documents/my_scripts_new/stlit/leetcodemore.ipynb#ch0000019?line=2'>3</a>\u001b[0m \u001b[39m# fetch the page to train\u001b[39;00m\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/dscshap3808/Documents/my_scripts_new/stlit/leetcodemore.ipynb#ch0000019?line=3'>4</a>\u001b[0m einstein_url \u001b[39m=\u001b[39m \u001b[39m'\u001b[39m\u001b[39mhttp://quotes.toscrape.com/author/Albert-Einstein/\u001b[39m\u001b[39m'\u001b[39m\n\u001b[1;32m----> <a href='vscode-notebook-cell:/c%3A/Users/dscshap3808/Documents/my_scripts_new/stlit/leetcodemore.ipynb#ch0000019?line=4'>5</a>\u001b[0m resp \u001b[39m=\u001b[39m requests\u001b[39m.\u001b[39;49mget(einstein_url, timeout \u001b[39m=\u001b[39;49m \u001b[39m5\u001b[39;49m)\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/dscshap3808/Documents/my_scripts_new/stlit/leetcodemore.ipynb#ch0000019?line=5'>6</a>\u001b[0m \u001b[39m# resp\u001b[39;00m\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/dscshap3808/Documents/my_scripts_new/stlit/leetcodemore.ipynb#ch0000019?line=6'>7</a>\u001b[0m \u001b[39massert\u001b[39;00m resp\u001b[39m.\u001b[39mstatus_code \u001b[39m==\u001b[39m \u001b[39m200\u001b[39m\n",
|
481 |
+
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\site-packages\\requests\\api.py:75\u001b[0m, in \u001b[0;36mget\u001b[1;34m(url, params, **kwargs)\u001b[0m\n\u001b[0;32m 64\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mget\u001b[39m(url, params\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs):\n\u001b[0;32m 65\u001b[0m \u001b[39mr\u001b[39m\u001b[39m\"\"\"Sends a GET request.\u001b[39;00m\n\u001b[0;32m 66\u001b[0m \n\u001b[0;32m 67\u001b[0m \u001b[39m :param url: URL for the new :class:`Request` object.\u001b[39;00m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 72\u001b[0m \u001b[39m :rtype: requests.Response\u001b[39;00m\n\u001b[0;32m 73\u001b[0m \u001b[39m \"\"\"\u001b[39;00m\n\u001b[1;32m---> 75\u001b[0m \u001b[39mreturn\u001b[39;00m request(\u001b[39m'\u001b[39;49m\u001b[39mget\u001b[39;49m\u001b[39m'\u001b[39;49m, url, params\u001b[39m=\u001b[39;49mparams, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n",
|
482 |
+
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\site-packages\\requests\\api.py:61\u001b[0m, in \u001b[0;36mrequest\u001b[1;34m(method, url, **kwargs)\u001b[0m\n\u001b[0;32m 57\u001b[0m \u001b[39m# By using the 'with' statement we are sure the session is closed, thus we\u001b[39;00m\n\u001b[0;32m 58\u001b[0m \u001b[39m# avoid leaving sockets open which can trigger a ResourceWarning in some\u001b[39;00m\n\u001b[0;32m 59\u001b[0m \u001b[39m# cases, and look like a memory leak in others.\u001b[39;00m\n\u001b[0;32m 60\u001b[0m \u001b[39mwith\u001b[39;00m sessions\u001b[39m.\u001b[39mSession() \u001b[39mas\u001b[39;00m session:\n\u001b[1;32m---> 61\u001b[0m \u001b[39mreturn\u001b[39;00m session\u001b[39m.\u001b[39;49mrequest(method\u001b[39m=\u001b[39;49mmethod, url\u001b[39m=\u001b[39;49murl, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n",
|
483 |
+
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\site-packages\\requests\\sessions.py:542\u001b[0m, in \u001b[0;36mSession.request\u001b[1;34m(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)\u001b[0m\n\u001b[0;32m 537\u001b[0m send_kwargs \u001b[39m=\u001b[39m {\n\u001b[0;32m 538\u001b[0m \u001b[39m'\u001b[39m\u001b[39mtimeout\u001b[39m\u001b[39m'\u001b[39m: timeout,\n\u001b[0;32m 539\u001b[0m \u001b[39m'\u001b[39m\u001b[39mallow_redirects\u001b[39m\u001b[39m'\u001b[39m: allow_redirects,\n\u001b[0;32m 540\u001b[0m }\n\u001b[0;32m 541\u001b[0m send_kwargs\u001b[39m.\u001b[39mupdate(settings)\n\u001b[1;32m--> 542\u001b[0m resp \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49msend(prep, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49msend_kwargs)\n\u001b[0;32m 544\u001b[0m \u001b[39mreturn\u001b[39;00m resp\n",
|
484 |
+
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\site-packages\\requests\\sessions.py:655\u001b[0m, in \u001b[0;36mSession.send\u001b[1;34m(self, request, **kwargs)\u001b[0m\n\u001b[0;32m 652\u001b[0m start \u001b[39m=\u001b[39m preferred_clock()\n\u001b[0;32m 654\u001b[0m \u001b[39m# Send the request\u001b[39;00m\n\u001b[1;32m--> 655\u001b[0m r \u001b[39m=\u001b[39m adapter\u001b[39m.\u001b[39;49msend(request, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n\u001b[0;32m 657\u001b[0m \u001b[39m# Total elapsed time of the request (approximately)\u001b[39;00m\n\u001b[0;32m 658\u001b[0m elapsed \u001b[39m=\u001b[39m preferred_clock() \u001b[39m-\u001b[39m start\n",
|
485 |
+
"File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\site-packages\\requests\\adapters.py:504\u001b[0m, in \u001b[0;36mHTTPAdapter.send\u001b[1;34m(self, request, stream, timeout, verify, cert, proxies)\u001b[0m\n\u001b[0;32m 501\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39misinstance\u001b[39m(e\u001b[39m.\u001b[39mreason, ConnectTimeoutError):\n\u001b[0;32m 502\u001b[0m \u001b[39m# TODO: Remove this in 3.0.0: see #2811\u001b[39;00m\n\u001b[0;32m 503\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39misinstance\u001b[39m(e\u001b[39m.\u001b[39mreason, NewConnectionError):\n\u001b[1;32m--> 504\u001b[0m \u001b[39mraise\u001b[39;00m ConnectTimeout(e, request\u001b[39m=\u001b[39mrequest)\n\u001b[0;32m 506\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39misinstance\u001b[39m(e\u001b[39m.\u001b[39mreason, ResponseError):\n\u001b[0;32m 507\u001b[0m \u001b[39mraise\u001b[39;00m RetryError(e, request\u001b[39m=\u001b[39mrequest)\n",
|
486 |
+
"\u001b[1;31mConnectTimeout\u001b[0m: HTTPConnectionPool(host='quotes.toscrape.com', port=80): Max retries exceeded with url: /author/Albert-Einstein/ (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x0000022B063F5AC0>, 'Connection to quotes.toscrape.com timed out. (connect timeout=5)'))"
|
487 |
+
]
|
488 |
+
}
|
489 |
+
],
|
490 |
"source": [
|
491 |
"import requests \n",
|
492 |
"from bs4 import BeautifulSoup\n",
|
|
|
499 |
},
|
500 |
{
|
501 |
"cell_type": "code",
|
502 |
+
"execution_count": null,
|
503 |
"metadata": {},
|
504 |
"outputs": [],
|
505 |
"source": [
|
|
|
624 |
"\n",
|
625 |
"# # fig.show()"
|
626 |
]
|
627 |
+
},
|
628 |
+
{
|
629 |
+
"cell_type": "code",
|
630 |
+
"execution_count": null,
|
631 |
+
"metadata": {
|
632 |
+
"vscode": {
|
633 |
+
"languageId": "javascript"
|
634 |
+
}
|
635 |
+
},
|
636 |
+
"outputs": [],
|
637 |
+
"source": []
|
638 |
}
|
639 |
],
|
640 |
"metadata": {
|
notebook_for_knit.ipynb
ADDED
@@ -0,0 +1,307 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 123,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [],
|
8 |
+
"source": [
|
9 |
+
"import pandas as pd\n",
|
10 |
+
"import plotly.express as px\n",
|
11 |
+
"import plotly.graph_objects as go\n",
|
12 |
+
"import io\n",
|
13 |
+
"import requests\n",
|
14 |
+
"import json\n",
|
15 |
+
"from bs4 import BeautifulSoup\n",
|
16 |
+
"import numpy as np\n",
|
17 |
+
"df = pd.read_json('./dataup/world_countries.json')\n",
|
18 |
+
"df = pd.json_normalize(df['features'])\n",
|
19 |
+
"proxy_dict = {\"http\": \"http://23.210.15.233:8080\"} \n",
|
20 |
+
"proxy_dicts = {\"https\": \"http://23.210.15.233:8080\"} \n"
|
21 |
+
]
|
22 |
+
},
|
23 |
+
{
|
24 |
+
"cell_type": "code",
|
25 |
+
"execution_count": 2,
|
26 |
+
"metadata": {},
|
27 |
+
"outputs": [],
|
28 |
+
"source": [
|
29 |
+
"# s = requests.get(\"https://github.com/plotly/datasets/blob/master/earthquakes-23k.csv\", proxies=proxy_dict)\n",
|
30 |
+
"# df = pd.read_csv(io.StringIO(s))\n"
|
31 |
+
]
|
32 |
+
},
|
33 |
+
{
|
34 |
+
"cell_type": "code",
|
35 |
+
"execution_count": 124,
|
36 |
+
"metadata": {},
|
37 |
+
"outputs": [],
|
38 |
+
"source": [
|
39 |
+
"t = requests.get(\"https://runestone.academy/ns/books/published/JS4Python/TheBasics/datatypes.html\", proxies=proxy_dicts, timeout=2)\n",
|
40 |
+
"tt = BeautifulSoup(t.content)"
|
41 |
+
]
|
42 |
+
},
|
43 |
+
{
|
44 |
+
"cell_type": "code",
|
45 |
+
"execution_count": 144,
|
46 |
+
"metadata": {},
|
47 |
+
"outputs": [
|
48 |
+
{
|
49 |
+
"data": {
|
50 |
+
"text/plain": [
|
51 |
+
"0 Python\n",
|
52 |
+
"1 JavaScript\n",
|
53 |
+
"2 Description\n",
|
54 |
+
"dtype: object"
|
55 |
+
]
|
56 |
+
},
|
57 |
+
"execution_count": 144,
|
58 |
+
"metadata": {},
|
59 |
+
"output_type": "execute_result"
|
60 |
+
}
|
61 |
+
],
|
62 |
+
"source": [
|
63 |
+
"tbtt_out = pd.DataFrame()\n",
|
64 |
+
"tbtt = tt.find_all('tr')\n",
|
65 |
+
"for i in tbtt:\n",
|
66 |
+
" pd.Series(\n",
|
67 |
+
" np.array(i.text.strip().split('\\n'))\n",
|
68 |
+
" ).to_frame().T\n",
|
69 |
+
" break\n",
|
70 |
+
"a"
|
71 |
+
]
|
72 |
+
},
|
73 |
+
{
|
74 |
+
"cell_type": "code",
|
75 |
+
"execution_count": 121,
|
76 |
+
"metadata": {},
|
77 |
+
"outputs": [
|
78 |
+
{
|
79 |
+
"data": {
|
80 |
+
"text/html": [
|
81 |
+
"<div>\n",
|
82 |
+
"<style scoped>\n",
|
83 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
84 |
+
" vertical-align: middle;\n",
|
85 |
+
" }\n",
|
86 |
+
"\n",
|
87 |
+
" .dataframe tbody tr th {\n",
|
88 |
+
" vertical-align: top;\n",
|
89 |
+
" }\n",
|
90 |
+
"\n",
|
91 |
+
" .dataframe thead th {\n",
|
92 |
+
" text-align: right;\n",
|
93 |
+
" }\n",
|
94 |
+
"</style>\n",
|
95 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
96 |
+
" <thead>\n",
|
97 |
+
" <tr style=\"text-align: right;\">\n",
|
98 |
+
" <th></th>\n",
|
99 |
+
" </tr>\n",
|
100 |
+
" </thead>\n",
|
101 |
+
" <tbody>\n",
|
102 |
+
" </tbody>\n",
|
103 |
+
"</table>\n",
|
104 |
+
"</div>"
|
105 |
+
],
|
106 |
+
"text/plain": [
|
107 |
+
"Empty DataFrame\n",
|
108 |
+
"Columns: []\n",
|
109 |
+
"Index: []"
|
110 |
+
]
|
111 |
+
},
|
112 |
+
"execution_count": 121,
|
113 |
+
"metadata": {},
|
114 |
+
"output_type": "execute_result"
|
115 |
+
}
|
116 |
+
],
|
117 |
+
"source": []
|
118 |
+
},
|
119 |
+
{
|
120 |
+
"cell_type": "code",
|
121 |
+
"execution_count": 10,
|
122 |
+
"metadata": {},
|
123 |
+
"outputs": [],
|
124 |
+
"source": [
|
125 |
+
"einstein_url = 'http://quotes.toscrape.com/author/Albert-Einstein/'\n",
|
126 |
+
"e = requests.get(einstein_url, proxies=proxy_dict, timeout = 3)\n"
|
127 |
+
]
|
128 |
+
},
|
129 |
+
{
|
130 |
+
"cell_type": "code",
|
131 |
+
"execution_count": 34,
|
132 |
+
"metadata": {},
|
133 |
+
"outputs": [],
|
134 |
+
"source": [
|
135 |
+
"soup = BeautifulSoup(e.content, 'lxml')"
|
136 |
+
]
|
137 |
+
},
|
138 |
+
{
|
139 |
+
"cell_type": "code",
|
140 |
+
"execution_count": 48,
|
141 |
+
"metadata": {},
|
142 |
+
"outputs": [
|
143 |
+
{
|
144 |
+
"data": {
|
145 |
+
"text/plain": [
|
146 |
+
"('text-decoration: none', 'Quotes to Scrape')"
|
147 |
+
]
|
148 |
+
},
|
149 |
+
"execution_count": 48,
|
150 |
+
"metadata": {},
|
151 |
+
"output_type": "execute_result"
|
152 |
+
}
|
153 |
+
],
|
154 |
+
"source": [
|
155 |
+
"soup.a['style'], soup.a.text"
|
156 |
+
]
|
157 |
+
},
|
158 |
+
{
|
159 |
+
"cell_type": "code",
|
160 |
+
"execution_count": 49,
|
161 |
+
"metadata": {},
|
162 |
+
"outputs": [
|
163 |
+
{
|
164 |
+
"data": {
|
165 |
+
"text/plain": [
|
166 |
+
"<h3 class=\"author-title\">Albert Einstein\n",
|
167 |
+
" </h3>"
|
168 |
+
]
|
169 |
+
},
|
170 |
+
"execution_count": 49,
|
171 |
+
"metadata": {},
|
172 |
+
"output_type": "execute_result"
|
173 |
+
}
|
174 |
+
],
|
175 |
+
"source": [
|
176 |
+
"soup.h3"
|
177 |
+
]
|
178 |
+
},
|
179 |
+
{
|
180 |
+
"cell_type": "code",
|
181 |
+
"execution_count": 78,
|
182 |
+
"metadata": {},
|
183 |
+
"outputs": [
|
184 |
+
{
|
185 |
+
"data": {
|
186 |
+
"text/plain": [
|
187 |
+
"[<h3 class=\"author-title\">Albert Einstein\n",
|
188 |
+
" </h3>]"
|
189 |
+
]
|
190 |
+
},
|
191 |
+
"execution_count": 78,
|
192 |
+
"metadata": {},
|
193 |
+
"output_type": "execute_result"
|
194 |
+
}
|
195 |
+
],
|
196 |
+
"source": [
|
197 |
+
"soup.find_all(\"h3\", {\"class\": \"author-title\"})"
|
198 |
+
]
|
199 |
+
},
|
200 |
+
{
|
201 |
+
"cell_type": "code",
|
202 |
+
"execution_count": 79,
|
203 |
+
"metadata": {},
|
204 |
+
"outputs": [
|
205 |
+
{
|
206 |
+
"data": {
|
207 |
+
"text/plain": [
|
208 |
+
"(<h3 class=\"author-title\">Albert Einstein\n",
|
209 |
+
" </h3>,\n",
|
210 |
+
" [<h3 class=\"author-title\">Albert Einstein\n",
|
211 |
+
" </h3>],\n",
|
212 |
+
" [<h3 class=\"author-title\">Albert Einstein\n",
|
213 |
+
" </h3>])"
|
214 |
+
]
|
215 |
+
},
|
216 |
+
"execution_count": 79,
|
217 |
+
"metadata": {},
|
218 |
+
"output_type": "execute_result"
|
219 |
+
}
|
220 |
+
],
|
221 |
+
"source": [
|
222 |
+
"soup.select_one('.author-title'), soup.select('[class^=author-ti]'), soup.select('[class*=titl]')"
|
223 |
+
]
|
224 |
+
},
|
225 |
+
{
|
226 |
+
"cell_type": "markdown",
|
227 |
+
"metadata": {},
|
228 |
+
"source": [
|
229 |
+
"---"
|
230 |
+
]
|
231 |
+
},
|
232 |
+
{
|
233 |
+
"cell_type": "code",
|
234 |
+
"execution_count": null,
|
235 |
+
"metadata": {},
|
236 |
+
"outputs": [],
|
237 |
+
"source": [
|
238 |
+
"fig = px.choropleth_mapbox(df, geojson=df, locations='fips', color='unemp',\\\n",
|
239 |
+
" color_continuous_scale=\"Viridis\",\n",
|
240 |
+
" range_color=(0, 12),\n",
|
241 |
+
" mapbox_style=\"carto-positron\",\n",
|
242 |
+
" zoom=3, \n",
|
243 |
+
" center = {\"lat\": 37.0902, \"lon\": -95.7129},\n",
|
244 |
+
" opacity=0.5,\n",
|
245 |
+
" labels={'unemp':'unemployment rate'}\n",
|
246 |
+
" )\n",
|
247 |
+
"fig.update_layout(margin={\"r\":0,\"t\":0,\"l\":0,\"b\":0})\n",
|
248 |
+
"fig.show()"
|
249 |
+
]
|
250 |
+
},
|
251 |
+
{
|
252 |
+
"cell_type": "code",
|
253 |
+
"execution_count": 8,
|
254 |
+
"metadata": {},
|
255 |
+
"outputs": [],
|
256 |
+
"source": [
|
257 |
+
"fig = go.Figure(go.Scattermapbox(\n",
|
258 |
+
" mode = \"markers+lines\",\n",
|
259 |
+
" lon = [10, 20, 30],\n",
|
260 |
+
" lat = [10, 20,30],\n",
|
261 |
+
" marker = {'size': 10}))\n",
|
262 |
+
"\n",
|
263 |
+
"fig.add_trace(go.Scattermapbox(\n",
|
264 |
+
" mode = \"markers+lines\",\n",
|
265 |
+
" lon = [-50, -60,40],\n",
|
266 |
+
" lat = [30, 10, -20],\n",
|
267 |
+
" marker = {'size': 10}))\n",
|
268 |
+
"\n",
|
269 |
+
"fig.update_layout(\n",
|
270 |
+
" margin ={'l':0,'t':0,'b':0,'r':0},\n",
|
271 |
+
" mapbox = {\n",
|
272 |
+
" 'style': \"carto-positron\",# \"stamen-terrain\",\n",
|
273 |
+
" 'center': {'lon': -20, 'lat': -20},\n",
|
274 |
+
" 'zoom': 2})\n",
|
275 |
+
"\n",
|
276 |
+
"# fig.show()"
|
277 |
+
]
|
278 |
+
}
|
279 |
+
],
|
280 |
+
"metadata": {
|
281 |
+
"kernelspec": {
|
282 |
+
"display_name": "Python 3.8.8 ('siming')",
|
283 |
+
"language": "python",
|
284 |
+
"name": "python3"
|
285 |
+
},
|
286 |
+
"language_info": {
|
287 |
+
"codemirror_mode": {
|
288 |
+
"name": "ipython",
|
289 |
+
"version": 3
|
290 |
+
},
|
291 |
+
"file_extension": ".py",
|
292 |
+
"mimetype": "text/x-python",
|
293 |
+
"name": "python",
|
294 |
+
"nbconvert_exporter": "python",
|
295 |
+
"pygments_lexer": "ipython3",
|
296 |
+
"version": "3.8.8"
|
297 |
+
},
|
298 |
+
"orig_nbformat": 4,
|
299 |
+
"vscode": {
|
300 |
+
"interpreter": {
|
301 |
+
"hash": "2537094cdaaf8cbca77398104c426db43a9f1c17b808f90867ef58a7e69b756d"
|
302 |
+
}
|
303 |
+
}
|
304 |
+
},
|
305 |
+
"nbformat": 4,
|
306 |
+
"nbformat_minor": 2
|
307 |
+
}
|