Skip to content

Commit 6a9320c

Browse files
committedOct 21, 2022
Build out a bulk payload tester
1 parent 3cfd29a commit 6a9320c

File tree

2 files changed

+112
-15
lines changed

2 files changed

+112
-15
lines changed
 

‎payload-test-bulk.ipynb

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "02e294a0",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"## Want to try a bulk download example?\n",
11+
"\n",
12+
"## This is just to get random words generated. \n",
13+
"from nltk.corpus import words\n",
14+
"import random\n",
15+
"\n",
16+
"\n",
17+
"\n",
18+
"import requests\n",
19+
"from tqdm import tqdm\n",
20+
"import datetime\n",
21+
"\n",
22+
"import os\n",
23+
"\n",
24+
"payload = {\n",
25+
" \"maintext1\": \"This is a test. Let's see Tyler's dog! Indianapolis-area homes for sale drop to $259,450 median price\",\n",
26+
" \"shape1\": \"facebook\",\n",
27+
" \"textcolor1\": \"black\",\n",
28+
" \"transparency1\": \"medium\" \n",
29+
"}\n",
30+
"\n",
31+
"# It takes a while to generate the sample texts. This is where you want to bring in your texts.\n",
32+
"sampletexts = []\n",
33+
"for i in range(0, 100):\n",
34+
" wordswanted = random.randrange(3, 30)\n",
35+
" rand_words = ' '.join(random.sample(words.words(), wordswanted))\n",
36+
" sampletexts.append(rand_words)\n",
37+
"\n",
38+
" \n",
39+
"# Normal program stuff starts here \n",
40+
"baseurl = \"http://localhost:5000/generate/\"\n",
41+
"\n",
42+
"downloaddir = \"downloads/\"\n",
43+
"os.makedirs(downloaddir, exist_ok=True)\n",
44+
"\n",
45+
"textlog = {}\n",
46+
"for sampletext in tqdm(sampletexts):\n",
47+
" payload['maintext1'] = sampletext\n",
48+
" r = requests.get(baseurl, data=payload)\n",
49+
" filename = downloaddir + r.headers['Content-Disposition'].split(\"filename=\")[-1]\n",
50+
" if os.path.exists(filename): # Do not clobber an existing file, for all sorts of reasons\n",
51+
" print(f\"Will NOT overwrite {filename}\")\n",
52+
" else:\n",
53+
" with open(filename, \"wb\") as outfile:\n",
54+
" outfile.write(r.content)\n",
55+
" # print(f\"Saved file as {filename}\")\n",
56+
" textlog[filename] = payload"
57+
]
58+
}
59+
],
60+
"metadata": {
61+
"kernelspec": {
62+
"display_name": "Python 3",
63+
"language": "python",
64+
"name": "python3"
65+
},
66+
"language_info": {
67+
"codemirror_mode": {
68+
"name": "ipython",
69+
"version": 3
70+
},
71+
"file_extension": ".py",
72+
"mimetype": "text/x-python",
73+
"name": "python",
74+
"nbconvert_exporter": "python",
75+
"pygments_lexer": "ipython3",
76+
"version": "3.7.2"
77+
}
78+
},
79+
"nbformat": 4,
80+
"nbformat_minor": 5
81+
}

‎payload-test.ipynb ‎payload-test-single.ipynb

+31-15
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 19,
5+
"execution_count": null,
66
"id": "59a3288b",
77
"metadata": {},
88
"outputs": [],
@@ -14,7 +14,7 @@
1414
},
1515
{
1616
"cell_type": "code",
17-
"execution_count": 21,
17+
"execution_count": null,
1818
"id": "2d318a23",
1919
"metadata": {},
2020
"outputs": [],
@@ -29,7 +29,7 @@
2929
},
3030
{
3131
"cell_type": "code",
32-
"execution_count": 25,
32+
"execution_count": null,
3333
"id": "bfb573c5",
3434
"metadata": {},
3535
"outputs": [],
@@ -42,7 +42,7 @@
4242
},
4343
{
4444
"cell_type": "code",
45-
"execution_count": 22,
45+
"execution_count": null,
4646
"id": "5adea828",
4747
"metadata": {},
4848
"outputs": [],
@@ -52,7 +52,7 @@
5252
},
5353
{
5454
"cell_type": "code",
55-
"execution_count": 23,
55+
"execution_count": null,
5656
"id": "3285f3c9",
5757
"metadata": {},
5858
"outputs": [],
@@ -62,18 +62,10 @@
6262
},
6363
{
6464
"cell_type": "code",
65-
"execution_count": 24,
65+
"execution_count": null,
6666
"id": "58c5fec5",
6767
"metadata": {},
68-
"outputs": [
69-
{
70-
"name": "stdout",
71-
"output_type": "stream",
72-
"text": [
73-
"Saved file as test-2022-10-21-11-38-23-628721.jpg\n"
74-
]
75-
}
76-
],
68+
"outputs": [],
7769
"source": [
7870
"if os.path.exists(filename): # Do not clobber an existing file, for all sorts of reasons\n",
7971
" print(f\"Will NOT overwrite {filename}\")\n",
@@ -90,6 +82,30 @@
9082
"metadata": {},
9183
"outputs": [],
9284
"source": []
85+
},
86+
{
87+
"cell_type": "code",
88+
"execution_count": null,
89+
"id": "97e17d85",
90+
"metadata": {},
91+
"outputs": [],
92+
"source": []
93+
},
94+
{
95+
"cell_type": "code",
96+
"execution_count": null,
97+
"id": "fc8f8016",
98+
"metadata": {},
99+
"outputs": [],
100+
"source": []
101+
},
102+
{
103+
"cell_type": "code",
104+
"execution_count": null,
105+
"id": "bbd04446",
106+
"metadata": {},
107+
"outputs": [],
108+
"source": []
93109
}
94110
],
95111
"metadata": {

0 commit comments

Comments
 (0)