Skip to content

Instantly share code, notes, and snippets.

@bubnenkoff
Last active April 28, 2020 10:51
Show Gist options
  • Select an option

  • Save bubnenkoff/80fdbf30ab91ace455d467fe4cba5c42 to your computer and use it in GitHub Desktop.

Select an option

Save bubnenkoff/80fdbf30ab91ace455d467fe4cba5c42 to your computer and use it in GitHub Desktop.
processing-controls:[
panel [
start-processing-button: button "Start" 60x60 [prepare-for-parsing]
count-of-files-for-parsing: text
]
]
generate-sql-for-processing: func[] [
sql-query-for-processing: {SELECT id, section_name FROM "xml_files"}
sql-query-for-processing
]
get-files-for-processing: func[] [
db-result: sqlite/query generate-sql-for-processing
foreach [_i id section_name full_path] db-result; _i by driver
[
process-single-file id section_name full_path
]
]
list-of-rules: Recursive-Read to-red-file rejoin ["./rules/"] ".red"
process-single-file: func[id section_name full_path][
full_fs_path: rejoin [to-red-file "/D/zak_data/" full_path]
either exists? full_fs_path
[
file-content: read full_fs_path
foreach rule list-of-rules [
do load rule
result: do-parsing file-content
; 1 - status
; 2 - data
; 3 - type
either result/1 [
; parsing success
sql-query: rejoin [{UPDATE "xml_files" SET "processed_date" = '2020-04-28', "status" = 'success' WHERE "id" = '} id {'}]
SQLite/query sql-query ; the problem is here!!!
]
[
; parsing fail
print ["[FAIL]" rule full_fs_path]
]
]
]
[
; xml do not exists
]
]
insert-to-db: func[data]
[
; print data/2/purchaseNumber
; {
sql_notice_fz44: rejoin [{INSERT INTO "notice_fz44" (
"purchaseNumber",
"responsibleOrg_factAddress",
"responsibleOrg_fullName",
"responsibleOrg_inn",
"responsibleOrg_kpp",
"responsibleOrg_postAddress",
"responsibleRole",
"xml_name")
VALUES ('}
data/2/purchaseNumber {', '}
data/2/responsibleOrg_factAddress {', '}
data/2/responsibleOrg_fullName{', '}
data/2/responsibleOrg_inn{', '}
data/2/responsibleOrg_kpp {', '}
data/2/responsibleOrg_postAddress {', '}
data/2/responsibleRole {', '}
data/3 {');}]
print sql_notice_fz44
; sqlite/query sql_notice_fz44
; SQLite/do [use db1]
; }
]
prepare-for-parsing: func[]
[
get-files-for-processing ;
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment