bugfix
This commit is contained in:
parent
07c2848da3
commit
c8318a276c
@ -1,6 +1,8 @@
|
|||||||
|
from appPublic.jsonConfig import getConfig
|
||||||
import openpyxl as xlsx
|
import openpyxl as xlsx
|
||||||
import asyncio
|
import asyncio
|
||||||
from sqlor.dbpools import DBPools
|
from sqlor.dbpools import DBPools
|
||||||
|
from typeconv import convrec
|
||||||
|
|
||||||
class CBObject:
|
class CBObject:
|
||||||
def __init__(self,db, name):
|
def __init__(self,db, name):
|
||||||
@ -9,10 +11,14 @@ class CBObject:
|
|||||||
|
|
||||||
async def handle(self,ws):
|
async def handle(self,ws):
|
||||||
db = DBPools()
|
db = DBPools()
|
||||||
meta = sor.I()
|
|
||||||
async with db.sqlorContext(self.db) as sor:
|
async with db.sqlorContext(self.db) as sor:
|
||||||
|
info = await sor.I(self.tbl)
|
||||||
for rec in getRecord(ws):
|
for rec in getRecord(ws):
|
||||||
sor.C(self.tbl, rec)
|
r = [ v for v in rec.values() if v is not None ]
|
||||||
|
if len(r) == 0:
|
||||||
|
continue
|
||||||
|
rec = convrec(info, rec)
|
||||||
|
await sor.C(self.tbl, rec)
|
||||||
|
|
||||||
typesconv = {
|
typesconv = {
|
||||||
"int":int,
|
"int":int,
|
||||||
@ -20,7 +26,7 @@ typesconv = {
|
|||||||
"str":str,
|
"str":str,
|
||||||
}
|
}
|
||||||
|
|
||||||
async def getRecord(ws):
|
def getRecord(ws):
|
||||||
names = []
|
names = []
|
||||||
types = []
|
types = []
|
||||||
for i,r in enumerate(ws.rows):
|
for i,r in enumerate(ws.rows):
|
||||||
@ -35,14 +41,16 @@ async def getRecord(ws):
|
|||||||
else:
|
else:
|
||||||
dic = {}
|
dic = {}
|
||||||
for j,c in enumerate(r):
|
for j,c in enumerate(r):
|
||||||
tf = typesconv.get(types[j],None)
|
# tf = typesconv.get(types[j],None)
|
||||||
v = c.value
|
v = c.value
|
||||||
dic[names[j]] = v
|
dic[names[j]] = v
|
||||||
yield rec
|
yield dic
|
||||||
|
|
||||||
async def excel2db(xlsxfile):
|
async def loaddatainexcel(xlsxfile):
|
||||||
wb = xlsx.load_workbook(xlsxfile)
|
wb = xlsx.load_workbook(xlsxfile)
|
||||||
dbname = [ i[2:-3] for i in wb.sheetnames if i.startswith('__')[0]
|
print(f'{wb.sheetnames=}')
|
||||||
|
dbname = [ i[2:-2] for i in wb.sheetnames if i.startswith('__')][0]
|
||||||
|
print(f'{dbname=}')
|
||||||
for name in wb.sheetnames:
|
for name in wb.sheetnames:
|
||||||
if name.startswith('__'):
|
if name.startswith('__'):
|
||||||
continue
|
continue
|
||||||
@ -52,10 +60,13 @@ async def excel2db(xlsxfile):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import sys
|
import sys
|
||||||
config = getConfig()
|
import os
|
||||||
|
p = os.getcwd()
|
||||||
|
config = getConfig(p)
|
||||||
|
print(f'{config.databases=},cwd={p}')
|
||||||
DBPools(config.databases)
|
DBPools(config.databases)
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
print('%s xlsxfile' % sys.argv[0])
|
print('%s xlsxfile' % sys.argv[0])
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
loop.run_until_complete(excel2db(sys.argv[1]))
|
loop.run_until_complete(loaddatainexcel(sys.argv[1]))
|
||||||
|
4
dataloader/macos/build.sh
Executable file
4
dataloader/macos/build.sh
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
pyinstaller -y --clean dataloader.spec
|
||||||
|
echo "build success, please find the target in dist folder"
|
47
dataloader/macos/dataloader.spec
Normal file
47
dataloader/macos/dataloader.spec
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
# -*- mode: python ; coding: utf-8 -*-
|
||||||
|
|
||||||
|
|
||||||
|
block_cipher = None
|
||||||
|
|
||||||
|
|
||||||
|
a = Analysis(
|
||||||
|
['../dataloader.py'],
|
||||||
|
pathex=[],
|
||||||
|
binaries=[],
|
||||||
|
datas=[],
|
||||||
|
hiddenimports=[
|
||||||
|
"aiopg",
|
||||||
|
"aiomysql"
|
||||||
|
],
|
||||||
|
hookspath=[],
|
||||||
|
hooksconfig={},
|
||||||
|
runtime_hooks=[],
|
||||||
|
excludes=[],
|
||||||
|
win_no_prefer_redirects=False,
|
||||||
|
win_private_assemblies=False,
|
||||||
|
cipher=block_cipher,
|
||||||
|
noarchive=False,
|
||||||
|
)
|
||||||
|
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
|
||||||
|
|
||||||
|
exe = EXE(
|
||||||
|
pyz,
|
||||||
|
a.scripts,
|
||||||
|
a.binaries,
|
||||||
|
a.zipfiles,
|
||||||
|
a.datas,
|
||||||
|
[],
|
||||||
|
name='dataloader',
|
||||||
|
debug=False,
|
||||||
|
bootloader_ignore_signals=False,
|
||||||
|
strip=False,
|
||||||
|
upx=True,
|
||||||
|
upx_exclude=[],
|
||||||
|
runtime_tmpdir=None,
|
||||||
|
console=True,
|
||||||
|
disable_windowed_traceback=False,
|
||||||
|
argv_emulation=False,
|
||||||
|
target_arch=None,
|
||||||
|
codesign_identity=None,
|
||||||
|
entitlements_file=None,
|
||||||
|
)
|
25
dataloader/typeconv.py
Normal file
25
dataloader/typeconv.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
convfuncs = {
|
||||||
|
'int':int,
|
||||||
|
'long':int,
|
||||||
|
'llong':int,
|
||||||
|
'float':float,
|
||||||
|
'double':float,
|
||||||
|
'date':str,
|
||||||
|
'datetime':str,
|
||||||
|
'ddouble':float
|
||||||
|
}
|
||||||
|
|
||||||
|
def conv(info, name, value):
|
||||||
|
fields = info['fields']
|
||||||
|
for f in fields:
|
||||||
|
if f['name'] == name:
|
||||||
|
f = convfuncs.get(f['type'], None)
|
||||||
|
if f is None:
|
||||||
|
return value
|
||||||
|
return f(value)
|
||||||
|
return value
|
||||||
|
|
||||||
|
def convrec(info, ns):
|
||||||
|
ret = {k:conv(info, k, v) for k,v in ns.items()}
|
||||||
|
return ret
|
||||||
|
|
Loading…
Reference in New Issue
Block a user