Skip to content
This repository has been archived by the owner on Sep 22, 2023. It is now read-only.

Commit

Permalink
Add links handler and parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlad Prud committed Nov 28, 2020
1 parent e4ace4e commit da2bec8
Show file tree
Hide file tree
Showing 13 changed files with 659 additions and 18 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ dmypy.json
*.jpg
*.tiff

# Text files
*.txt
*.csv
*.dsv
*.tsv

# Excel-files
*.xlsx
*.xlsm
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
run:
python -m aiohttp.web -H localhost -P 8080 api.main:init
python3 -m api --host localhost --port 8080
22 changes: 22 additions & 0 deletions api/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import asyncio
import argparse
import logging

from aiohttp import web
from api.routes import setup_routes

parser = argparse.ArgumentParser(description="aiohttp server example")
parser.add_argument('--host')
parser.add_argument('--port')

def main():
logging.basicConfig(level=logging.DEBUG)
args = parser.parse_args()
app = web.Application()

setup_routes(app)

web.run_app(app, host=args.host, port=args.port)

if __name__ == '__main__':
main()
16 changes: 16 additions & 0 deletions api/handlers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os

import asyncio
import requests

from aiohttp import web

Expand Down Expand Up @@ -53,3 +54,18 @@ async def post_jpg(self, request):

#web.Response(text='Excel-report sized of {0} successfully stored'.format(size))
return web.FileResponse(path='./api/tmp/data/loaded.jpg', status=200)

async def post_links(self, request):
reader = await request.json()

#print(reader)
link1 = reader['file1']
#link2 = reader['file2']

r1 = requests.get(link1)

with open("./api/tmp/data/loaded_1.xlsx", "wb") as file:
file.write(r1.content)

#return web.Response(text=link1)
return web.FileResponse(path='./api/tmp/data/loaded_1.xlsx', status=200)
13 changes: 0 additions & 13 deletions api/main.py

This file was deleted.

3 changes: 2 additions & 1 deletion api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ def setup_routes(app):
web.get("/hello/{name}", handler.hello),
web.get("/get/json", handler.get_json),
web.post("/post/excel", handler.post_excel),
web.post("/post/jpg", handler.post_jpg)
web.post("/post/jpg", handler.post_jpg),
web.post("/post/links", handler.post_links)
])
7 changes: 7 additions & 0 deletions api/utilies/fileworker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Worker:

def __init__(self):
pass

def print(self):
print('KK')
Empty file added data/.gitkeep
Empty file.
Empty file added data/prep/raw/.gitkeep
Empty file.
Empty file added data/raw/.gitkeep
Empty file.
Loading

0 comments on commit da2bec8

Please sign in to comment.