Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ref: parsers
  • Loading branch information
sshaplygin committed Jan 6, 2024
commit ed7cb5265f6bb4bd417647378828922c2ac290bb
7 changes: 3 additions & 4 deletions parser/bik/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/xml"
"fmt"
"io"
"log"
"os"
)

Expand Down Expand Up @@ -57,14 +58,12 @@ type Bik struct {

func checkErr(e error) {
if e != nil {
panic(e)
log.Panic(e)
}
}

func init() {
var err error
devNull, err = os.OpenFile(os.DevNull, os.O_WRONLY, 0600)
if err != nil {
panic(err)
}
checkErr(err)
}
73 changes: 67 additions & 6 deletions parser/fns/main.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,83 @@
package main

import "os"
import (
"bufio"
"fmt"
"log"
"os"
"strconv"
)

// Example output:
// var SupportedTaxDepartment = map[ConstitutionSubjectCode]TaxDepart{
// 0: {
// Name: "ФНС России",
// },
// 1: {
// Name: "УФНС России по Республике Адыгея",
// Branches: map[RegionTaxServiceNumber]string{
// 1: "Межрайонная инспекция Федеральной налоговой службы №2 по Республике Адыгея",
// 5: "Межрайонная инспекция Федеральной налоговой службы №1 по Республике Адыгея",
// 7: "Межрайонная инспекция Федеральной налоговой службы №3 по Республике Адыгея",
// },
// },
// }

func main() {
file, err := os.Open("input.txts")
file, err := os.Open("input.txt")
checkErr(err)
if err != nil {
panic(err)
}

defer func() {
err = file.Close()
checkErr(err)
}()

fmt.Println("package main", "\n")
fmt.Println("var SupportedTaxDepartment = map[ConstitutionSubjectCode]TaxDepart{")

scanner := bufio.NewScanner(file)
var code int

var nextRegion bool
for scanner.Scan() {
row := scanner.Text()
code, err = strconv.Atoi(row)
if err != nil {
var output string
if nextRegion {
//fmt.Println("},")
output += "Name: "
}
fmt.Println(output + "`" + row + "`,")
if nextRegion {
fmt.Println("Branches: map[RegionTaxServiceNumber]string{")
}

nextRegion = false
continue
}

if code%100 == 0 {
fmt.Println("},")
fmt.Println("},")
fmt.Println(code/100, ": {")
nextRegion = true
} else {
fmt.Print(code%100, ":")
}
}

fmt.Println("},") // close branch map
fmt.Println("},") // close global map
fmt.Println("}")

err = scanner.Err()
checkErr(err)

}

func checkErr(e error) {
if e != nil {
panic(e)
log.Panic(e)
}
}
3 changes: 2 additions & 1 deletion parser/okato-states/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"log"
"os"
"strings"
"unicode"
Expand Down Expand Up @@ -53,6 +54,6 @@ func excludeDigits(input string) string {

func checkErr(e error) {
if e != nil {
panic(e)
log.Panic(e)
}
}
3 changes: 2 additions & 1 deletion parser/subjects/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"log"
"os"
"strings"

Expand Down Expand Up @@ -39,6 +40,6 @@ func main() {

func checkErr(e error) {
if e != nil {
panic(e)
log.Panic(e)
}
}