file.go 992 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package common
  2. import (
  3. "encoding/json"
  4. "github.com/go-rod/rod/lib/utils"
  5. "os"
  6. )
  7. // GetCollectPDFPath 生成一个采集用的pdf路径
  8. func GetCollectPDFPath(district, taxNo, taxTape string) (string, error) {
  9. var err error
  10. var path string
  11. path = "./data/collection/" + district + "/"
  12. if !PathExists(path) {
  13. err = os.MkdirAll(path, os.ModePerm)
  14. }
  15. path = path + taxNo + "_" + taxTape + ".pdf"
  16. return path, err
  17. }
  18. // PDFtoStrArrayPython pdf转二维数组 python服务
  19. func PDFtoStrArrayPython(path string) ([][]string, error) {
  20. var code [][]string
  21. files := map[string]string{
  22. "file": path,
  23. }
  24. var bys []byte
  25. var err error
  26. pdfServers := []string{
  27. `http://47.104.75.113:6000/pdfToText`,
  28. `http://47.104.75.113:6000/pdfToText`,
  29. }
  30. for _, uri := range pdfServers {
  31. bys, err = PostFile(uri, files, map[string]string{})
  32. if err != nil {
  33. utils.Sleep(10)
  34. continue
  35. }
  36. break
  37. }
  38. if err != nil {
  39. return code, err
  40. }
  41. json.Unmarshal(bys, &code)
  42. return code, nil
  43. }