92 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			92 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| {
 | |
|  "cells": [
 | |
|   {
 | |
|    "cell_type": "code",
 | |
|    "execution_count": 68,
 | |
|    "metadata": {},
 | |
|    "outputs": [
 | |
|     {
 | |
|      "data": {
 | |
|       "text/plain": [
 | |
|        "<module 'server' from '/media/ict/hky3535/data/chinatelecom/pypi/b64-viewer/server.py'>"
 | |
|       ]
 | |
|      },
 | |
|      "execution_count": 68,
 | |
|      "metadata": {},
 | |
|      "output_type": "execute_result"
 | |
|     }
 | |
|    ],
 | |
|    "source": [
 | |
|     "import numpy\n",
 | |
|     "import base64\n",
 | |
|     "import io\n",
 | |
|     "import time\n",
 | |
|     "import requests\n",
 | |
|     "from PIL import Image, ImageDraw, ImageFont\n",
 | |
|     "\n",
 | |
|     "import server\n",
 | |
|     "import importlib\n",
 | |
|     "importlib.reload(server)"
 | |
|    ]
 | |
|   },
 | |
|   {
 | |
|    "cell_type": "code",
 | |
|    "execution_count": 103,
 | |
|    "metadata": {},
 | |
|    "outputs": [
 | |
|     {
 | |
|      "name": "stdout",
 | |
|      "output_type": "stream",
 | |
|      "text": [
 | |
|       "<Response [200]> {}\n"
 | |
|      ]
 | |
|     }
 | |
|    ],
 | |
|    "source": [
 | |
|     "font = ImageFont.load_default()\n",
 | |
|     "\n",
 | |
|     "def random_image_b64(width=640, height=480):\n",
 | |
|     "    image = Image.fromarray(\n",
 | |
|     "        numpy.random.randint(0, 1, (height, width, 3), dtype=numpy.uint8), 'RGB')\n",
 | |
|     "\n",
 | |
|     "    buffer = io.BytesIO()\n",
 | |
|     "    image.save(buffer, format=\"JPEG\")\n",
 | |
|     "    image_b64 = base64.b64encode(buffer.getvalue()).decode('utf-8')\n",
 | |
|     "    return image_b64\n",
 | |
|     "\n",
 | |
|     "while True:\n",
 | |
|     "    image_b64 = random_image_b64()\n",
 | |
|     "\n",
 | |
|     "    response = requests.post(\n",
 | |
|     "        url=\"http://localhost:60000/update\", \n",
 | |
|     "        json={\"image\": image_b64, \"image_extra\": image_b64})\n",
 | |
|     "    \n",
 | |
|     "    print(response, response.json())\n",
 | |
|     "\n",
 | |
|     "    break"
 | |
|    ]
 | |
|   }
 | |
|  ],
 | |
|  "metadata": {
 | |
|   "kernelspec": {
 | |
|    "display_name": "Python 3",
 | |
|    "language": "python",
 | |
|    "name": "python3"
 | |
|   },
 | |
|   "language_info": {
 | |
|    "codemirror_mode": {
 | |
|     "name": "ipython",
 | |
|     "version": 3
 | |
|    },
 | |
|    "file_extension": ".py",
 | |
|    "mimetype": "text/x-python",
 | |
|    "name": "python",
 | |
|    "nbconvert_exporter": "python",
 | |
|    "pygments_lexer": "ipython3",
 | |
|    "version": "3.10.12"
 | |
|   }
 | |
|  },
 | |
|  "nbformat": 4,
 | |
|  "nbformat_minor": 2
 | |
| }
 | 
