|
10 | 10 | }, |
11 | 11 | { |
12 | 12 | "cell_type": "code", |
13 | | - "execution_count": 1, |
| 13 | + "execution_count": null, |
14 | 14 | "id": "79210915", |
15 | 15 | "metadata": {}, |
16 | 16 | "outputs": [], |
|
21 | 21 | }, |
22 | 22 | { |
23 | 23 | "cell_type": "code", |
24 | | - "execution_count": 2, |
| 24 | + "execution_count": null, |
25 | 25 | "id": "225f3422-2872-4deb-9783-e249957aca30", |
26 | 26 | "metadata": {}, |
27 | 27 | "outputs": [], |
|
35 | 35 | }, |
36 | 36 | { |
37 | 37 | "cell_type": "code", |
38 | | - "execution_count": 3, |
| 38 | + "execution_count": null, |
39 | 39 | "id": "af8c7fe0", |
40 | 40 | "metadata": {}, |
41 | 41 | "outputs": [], |
|
44 | 44 | "import os\n", |
45 | 45 | "from pathlib import Path\n", |
46 | 46 | "\n", |
47 | | - "from dsd_pythonanywhere.client import APIClient\n", |
| 47 | + "from dsd_pythonanywhere.client import PythonAnywhereClient\n", |
48 | 48 | "\n", |
49 | 49 | "logging.basicConfig(\n", |
50 | 50 | " level=logging.DEBUG, force=True, format=\"%(asctime)s - %(levelname)s - %(message)s\"\n", |
|
53 | 53 | }, |
54 | 54 | { |
55 | 55 | "cell_type": "code", |
56 | | - "execution_count": 6, |
| 56 | + "execution_count": null, |
57 | 57 | "id": "1f0cff23", |
58 | 58 | "metadata": {}, |
59 | | - "outputs": [ |
60 | | - { |
61 | | - "name": "stdout", |
62 | | - "output_type": "stream", |
63 | | - "text": [ |
64 | | - "Set API_TOKEN\n", |
65 | | - "Set API_USER\n" |
66 | | - ] |
67 | | - } |
68 | | - ], |
| 59 | + "outputs": [], |
69 | 60 | "source": [ |
70 | 61 | "# VS Code's Jupyter extension doesn't support loading .envrc, so do it manually here\n", |
71 | 62 | "\n", |
|
82 | 73 | }, |
83 | 74 | { |
84 | 75 | "cell_type": "code", |
85 | | - "execution_count": 7, |
| 76 | + "execution_count": null, |
86 | 77 | "id": "7adbd24d", |
87 | 78 | "metadata": {}, |
88 | | - "outputs": [ |
89 | | - { |
90 | | - "name": "stderr", |
91 | | - "output_type": "stream", |
92 | | - "text": [ |
93 | | - "2025-12-29 12:32:51,046 - DEBUG - Converted retries value: 3 -> Retry(total=3, connect=None, read=None, redirect=None, status=None)\n" |
94 | | - ] |
95 | | - } |
96 | | - ], |
| 79 | + "outputs": [], |
97 | 80 | "source": [ |
98 | 81 | "username = os.getenv(\"API_USER\")\n", |
99 | | - "client = APIClient(username)" |
| 82 | + "client = PythonAnywhereClient(username)" |
100 | 83 | ] |
101 | 84 | }, |
102 | 85 | { |
103 | 86 | "cell_type": "code", |
104 | 87 | "execution_count": null, |
105 | 88 | "id": "c8fbf886", |
106 | 89 | "metadata": {}, |
107 | | - "outputs": [ |
108 | | - { |
109 | | - "name": "stderr", |
110 | | - "output_type": "stream", |
111 | | - "text": [ |
112 | | - "2025-09-12 13:46:48,086 - DEBUG - Starting new HTTPS connection (1): www.pythonanywhere.com:443\n", |
113 | | - "2025-09-12 13:46:48,242 - DEBUG - https://www.pythonanywhere.com:443 \"GET /api/v0/user/copelco/consoles/ HTTP/1.1\" 200 2\n", |
114 | | - "2025-09-12 13:46:48,243 - DEBUG - API response: 200 []\n", |
115 | | - "2025-09-12 13:46:48,243 - DEBUG - No active bash console found, starting a new one...\n", |
116 | | - "2025-09-12 13:46:48,311 - DEBUG - https://www.pythonanywhere.com:443 \"POST /api/v0/user/copelco/consoles/ HTTP/1.1\" 201 233\n", |
117 | | - "2025-09-12 13:46:48,311 - DEBUG - API response: 201 {\"id\":42095523,\"user\":\"copelco\",\"executable\":\"bash\",\"arguments\":\"\",\"working_directory\":null,\"name\":\"Bash console 42095523\",\"console_url\":\"/user/copelco/consoles/42095523/\",\"console_frame_url\":\"/user/copelco/consoles/42095523/frame/\"}\n", |
118 | | - "2025-09-12 13:46:48,312 - DEBUG - Found bash console: {'id': 42095523, 'user': 'copelco', 'executable': 'bash', 'arguments': '', 'working_directory': None, 'name': 'Bash console 42095523', 'console_url': '/user/copelco/consoles/42095523/', 'console_frame_url': '/user/copelco/consoles/42095523/frame/'}\n", |
119 | | - "2025-09-12 13:46:48,312 - DEBUG - Attempt 0: checking if console is active\n", |
120 | | - "2025-09-12 13:46:48,380 - DEBUG - https://www.pythonanywhere.com:443 \"POST /api/v0/user/copelco/consoles/42095523/send_input/ HTTP/1.1\" 412 87\n", |
121 | | - "2025-09-12 13:46:48,381 - DEBUG - API error status_code=412 error_data={'error': 'Console not yet started. Please load it (or its iframe) in a browser first'}\n", |
122 | | - "2025-09-12 13:46:48,381 - DEBUG - API response: 412 {\"error\":\"Console not yet started. Please load it (or its iframe) in a browser first\"}\n", |
123 | | - "2025-09-12 13:46:48,382 - DEBUG - Console not yet started, opening browser...\n", |
124 | | - "2025-09-12 13:46:48,523 - DEBUG - Console not yet started, waiting...\n", |
125 | | - "2025-09-12 13:46:49,530 - DEBUG - Attempt 1: checking if console is active\n", |
126 | | - "2025-09-12 13:46:49,625 - DEBUG - https://www.pythonanywhere.com:443 \"POST /api/v0/user/copelco/consoles/42095523/send_input/ HTTP/1.1\" 200 15\n", |
127 | | - "2025-09-12 13:46:49,627 - DEBUG - API response: 200 {\"status\":\"OK\"}\n", |
128 | | - "2025-09-12 13:46:49,627 - DEBUG - Console is active.\n", |
129 | | - "2025-09-12 13:46:49,707 - DEBUG - https://www.pythonanywhere.com:443 \"POST /api/v0/user/copelco/consoles/42095523/send_input/ HTTP/1.1\" 200 15\n", |
130 | | - "2025-09-12 13:46:49,708 - DEBUG - API response: 200 {\"status\":\"OK\"}\n", |
131 | | - "2025-09-12 13:46:49,777 - DEBUG - https://www.pythonanywhere.com:443 \"GET /api/v0/user/copelco/consoles/42095523/get_latest_output/ HTTP/1.1\" 200 51\n" |
132 | | - ] |
133 | | - }, |
134 | | - { |
135 | | - "name": "stdout", |
136 | | - "output_type": "stream", |
137 | | - "text": [ |
138 | | - "\n", |
139 | | - "Preparing execution environment...\n" |
140 | | - ] |
141 | | - } |
142 | | - ], |
| 90 | + "outputs": [], |
143 | 91 | "source": [ |
144 | | - "print(client.run_command(\"ls -la\"))" |
| 92 | + "client.request(method=\"GET\", url=client._base_url(\"cpu\"))" |
145 | 93 | ] |
146 | 94 | }, |
147 | 95 | { |
148 | 96 | "cell_type": "code", |
149 | | - "execution_count": 8, |
| 97 | + "execution_count": null, |
| 98 | + "id": "83e6f6f1", |
| 99 | + "metadata": {}, |
| 100 | + "outputs": [], |
| 101 | + "source": [ |
| 102 | + "client.webapp_exists()" |
| 103 | + ] |
| 104 | + }, |
| 105 | + { |
| 106 | + "cell_type": "code", |
| 107 | + "execution_count": null, |
150 | 108 | "id": "5e5f7022", |
151 | 109 | "metadata": {}, |
152 | 110 | "outputs": [], |
|
156 | 114 | }, |
157 | 115 | { |
158 | 116 | "cell_type": "code", |
159 | | - "execution_count": 16, |
| 117 | + "execution_count": null, |
160 | 118 | "id": "180bcefc", |
161 | 119 | "metadata": {}, |
162 | 120 | "outputs": [], |
163 | 121 | "source": [ |
164 | | - "webapp = Webapp(\"copelco.pythonanywhere.com\")" |
| 122 | + "webapp = Webapp.list_webapps()" |
165 | 123 | ] |
166 | 124 | }, |
167 | 125 | { |
168 | 126 | "cell_type": "code", |
169 | | - "execution_count": 17, |
| 127 | + "execution_count": null, |
170 | 128 | "id": "1fe24344", |
171 | 129 | "metadata": {}, |
172 | | - "outputs": [ |
173 | | - { |
174 | | - "name": "stderr", |
175 | | - "output_type": "stream", |
176 | | - "text": [ |
177 | | - "2025-12-29 13:12:08,848 - DEBUG - Starting new HTTPS connection (1): www.pythonanywhere.com:443\n" |
178 | | - ] |
179 | | - }, |
180 | | - { |
181 | | - "name": "stderr", |
182 | | - "output_type": "stream", |
183 | | - "text": [ |
184 | | - "2025-12-29 13:12:09,476 - DEBUG - https://www.pythonanywhere.com:443 \"GET /api/v0/user/copelco/webapps/copelco.pythonanywhere.com/ HTTP/1.1\" 403 63\n" |
185 | | - ] |
186 | | - } |
187 | | - ], |
| 130 | + "outputs": [], |
188 | 131 | "source": [ |
189 | 132 | "webapp.sanity_checks(nuke=False)" |
190 | 133 | ] |
191 | 134 | }, |
192 | 135 | { |
193 | 136 | "cell_type": "code", |
194 | | - "execution_count": 18, |
| 137 | + "execution_count": null, |
195 | 138 | "id": "a27334f9", |
196 | 139 | "metadata": {}, |
197 | | - "outputs": [ |
198 | | - { |
199 | | - "name": "stderr", |
200 | | - "output_type": "stream", |
201 | | - "text": [ |
202 | | - "2025-12-29 13:12:11,430 - DEBUG - Starting new HTTPS connection (1): www.pythonanywhere.com:443\n", |
203 | | - "2025-12-29 13:12:20,857 - DEBUG - https://www.pythonanywhere.com:443 \"POST /api/v0/user/copelco/webapps/ HTTP/1.1\" 200 94\n", |
204 | | - "2025-12-29 13:12:20,863 - DEBUG - Starting new HTTPS connection (1): www.pythonanywhere.com:443\n", |
205 | | - "2025-12-29 13:12:21,097 - DEBUG - https://www.pythonanywhere.com:443 \"PATCH /api/v0/user/copelco/webapps/copelco.pythonanywhere.com/ HTTP/1.1\" 200 None\n" |
206 | | - ] |
207 | | - } |
208 | | - ], |
| 140 | + "outputs": [], |
209 | 141 | "source": [ |
210 | | - "webapp.create(python_version=\"3.13\", virtualenv_path=\"/home/copelco/venv\", project_path=\"/home/copelco/dsd-testproj\", nuke=False)" |
| 142 | + "webapp.create(\n", |
| 143 | + " python_version=\"3.13\",\n", |
| 144 | + " virtualenv_path=\"/home/copelco/venv\",\n", |
| 145 | + " project_path=\"/home/copelco/dsd-testproj\",\n", |
| 146 | + " nuke=False,\n", |
| 147 | + ")" |
211 | 148 | ] |
212 | 149 | }, |
213 | 150 | { |
214 | 151 | "cell_type": "code", |
215 | | - "execution_count": 25, |
| 152 | + "execution_count": null, |
216 | 153 | "id": "64c54a59", |
217 | 154 | "metadata": {}, |
218 | | - "outputs": [ |
219 | | - { |
220 | | - "name": "stderr", |
221 | | - "output_type": "stream", |
222 | | - "text": [ |
223 | | - "2025-12-29 13:38:21,458 - DEBUG - Starting new HTTPS connection (1): www.pythonanywhere.com:443\n" |
224 | | - ] |
225 | | - }, |
226 | | - { |
227 | | - "name": "stderr", |
228 | | - "output_type": "stream", |
229 | | - "text": [ |
230 | | - "2025-12-29 13:38:32,034 - DEBUG - https://www.pythonanywhere.com:443 \"POST /api/v0/user/copelco/webapps/copelco.pythonanywhere.com/reload/ HTTP/1.1\" 200 15\n" |
231 | | - ] |
232 | | - } |
233 | | - ], |
| 155 | + "outputs": [], |
234 | 156 | "source": [ |
235 | 157 | "webapp.reload()" |
236 | 158 | ] |
|
0 commit comments