You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
1.0 KiB
Python
32 lines
1.0 KiB
Python
from http.server import HTTPServer, BaseHTTPRequestHandler
|
|
import requests
|
|
|
|
def read_book(resp):
|
|
i=1
|
|
for item in resp.decode().split(','):
|
|
print(str(i) + ": " + item)
|
|
open("{:04d}.jpg".format(i), 'wb').write(requests.get(item).content)
|
|
i+=1
|
|
|
|
|
|
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
|
|
def do_POST(self):
|
|
content_length = int(self.headers['Content-Length'])
|
|
body = self.rfile.read(content_length)
|
|
self.send_response(204)
|
|
self.send_header('Access-Control-Allow-Origin', '*')
|
|
self.end_headers()
|
|
#print(body)
|
|
read_book(body)
|
|
|
|
def do_OPTIONS(self):
|
|
print(self.headers)
|
|
self.send_response(204)
|
|
self.send_header('Access-Control-Allow-Origin', '*')
|
|
self.send_header('Access-Control-Allow-Method', 'POST, GET, OPTIONS')
|
|
self.send_header('Access-Control-Allow-Headers', 'content-type')
|
|
self.end_headers()
|
|
|
|
httpd = HTTPServer(('localhost', 8000), SimpleHTTPRequestHandler)
|
|
httpd.serve_forever()
|