|
@@ -40,6 +40,8 @@ from pathlib import Path
|
|
|
from tempfile import NamedTemporaryFile
|
|
|
from typing import Callable
|
|
|
import shutil
|
|
|
+import aiofiles
|
|
|
+from io import StringIO
|
|
|
|
|
|
|
|
|
driver = None
|
|
@@ -263,25 +265,31 @@ def save_upload_file_tmp(file: UploadFile) -> Path:
|
|
|
|
|
|
@app.post("/kwtree")
|
|
|
async def kwtree(file: UploadFile = File(...)):
|
|
|
- destination_file_path = "/root/src/kw_tools/web" + file.filename
|
|
|
- with codecs.open(destination_file_path,'r','utf-16') as out_file:
|
|
|
+ destination_file_path = "/Users/zooeytsai/" + file.filename
|
|
|
+ base_dir = os.path.dirname(__file__)
|
|
|
+ file_path = f'{base_dir}/{file.filename}'
|
|
|
+ # async with open(file.filename,'r',encoding='utf-16') as out_file:
|
|
|
# with codecs.open(file.file) as csvfile:
|
|
|
- # csv_reader = csv.reader(codecs.iterdecode(file.file, 'utf-8'))
|
|
|
- csvfile = csv.reader(out_file, delimiter='\t', quotechar='|')
|
|
|
- # spamreader = csv.reader(csvfile, delimiter='\t', quotechar='|')
|
|
|
- kwdict = {}
|
|
|
- addict = {}
|
|
|
- head = True
|
|
|
- rowlst = []
|
|
|
- for row in csvfile:
|
|
|
- if head:
|
|
|
- head = False
|
|
|
- continue
|
|
|
- ll = len(row)
|
|
|
- proc_row(row[0])
|
|
|
- if row not in rowlst:
|
|
|
- rowlst.append(row[0])
|
|
|
- head = True
|
|
|
+ # csvfile = csv.DictReader(codecs.iterdecode(out_file, 'utf-16'),dialect=csv.excel_tab)
|
|
|
+ # csvfile = csv.reader(file.file, delimiter='\t', quotechar='|')
|
|
|
+ # spamreader = csv.reader(csvfile, delimiter='\t', quotechar='|')
|
|
|
+ # csvfile = await file.read()
|
|
|
+ csvfile = csv.DictReader(codecs.iterdecode(file.file, 'utf-16'), dialect=csv.excel)
|
|
|
+
|
|
|
+ kwdict = {}
|
|
|
+ addict = {}
|
|
|
+ head = True
|
|
|
+ rowlst = []
|
|
|
+ for row in csvfile:
|
|
|
+ print(row)
|
|
|
+ if head:
|
|
|
+ head = False
|
|
|
+ continue
|
|
|
+ ll = len(row)
|
|
|
+ proc_row(row[0])
|
|
|
+ if row not in rowlst:
|
|
|
+ rowlst.append(row[0])
|
|
|
+ head = True
|
|
|
|
|
|
clusters = gcm0(rowlst)
|
|
|
keys = []
|
|
@@ -334,4 +342,4 @@ async def kwtree(file: UploadFile = File(...)):
|
|
|
|
|
|
# sys.exit()
|
|
|
|
|
|
- return FileResponse(f'/root/kw_tools/web/news{news_file}.html',media_type='text/html')
|
|
|
+ return FileResponse(f'/Users/zooeytsai/kw_tools/choozmo/news{news_file}.html',media_type='text/html')
|