Skip to content

Commit

Permalink
ADD conf IMAGE_HEIGHT,COL_WIDTH
Browse files Browse the repository at this point in the history
  • Loading branch information
iotames committed Apr 25, 2024
1 parent b95bc37 commit ed0637a
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 19 deletions.
94 changes: 94 additions & 0 deletions .github/workflows/release_tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: CreateRelease

on:
release:
types:
- prereleased
# - released
push:
tags:
- "v*"

jobs:
create_release:
if: github.event_name == 'push'
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Create Release
id: create_release
uses: actions/create-release@v1
if: github.event_name == 'push'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref_name }}
body: 修复了一些已知问题。
draft: false
prerelease: true

build:
# if: github.event_name == 'release'
# needs: create_release
strategy:
matrix:
goos: [linux, darwin, windows]

permissions: # 需要设置写权限才能自动发布
contents: write

runs-on: ubuntu-latest
env:
GOOS: ${{ matrix.goos }}
CGO_ENABLED: 0
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22.x'

- name: Install dependencies
run: |
go env -w GO111MODULE=on
sudo apt-get update -y
sudo apt-get install -y gcc libgl1-mesa-dev xorg-dev
go mod tidy
go install fyne.io/fyne/v2/cmd/fyne@latest
- name: Get File Name
id: get_filename
run: |
export _NAME=DownUtils-${{ matrix.goos }}.tar.gz
echo "GOOS: $GOOS, GOARCH: $GOARCH, RELEASE_NAME: $_NAME"
echo "ASSET_NAME=$_NAME" >> $GITHUB_OUTPUT
echo "ASSET_NAME=$_NAME" >> $GITHUB_ENV
- name: Build
run: |
fyne package -os ${{ matrix.goos }} -icon resource/images/logo.png
ls *.exe *.tar*
- name: Package
run: tar zcvf ${{ steps.get_filename.outputs.ASSET_NAME }} *.exe *.tar*

# 上传附件
- name: Upload file to Artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ steps.get_filename.outputs.ASSET_NAME }}
path: ${{ steps.get_filename.outputs.ASSET_NAME }}

- name: Upload files to GitHub release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file_glob: true
file: ./${{ steps.get_filename.outputs.ASSET_NAME }}
tag: ${{ github.ref }}
overwrite: true
6 changes: 5 additions & 1 deletion conf/conf_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const DEFAULT_RETRY_TIMES = 3
const DEFAULT_DELAY = 1
const DEFAULT_RANDOM_DELAY = 1
const DEFAULT_PARALLELISM = 12
const DEFAULT_IMAGE_HEIGHT = 76
const DEFAULT_COL_WIDTH = 76
const DEFAULT_IMAGES_PATH = "runtime/images"
const DEFAULT_DOWNLOADS_PATH = "runtime/downloads"
const DEFAULT_RUNTIME_DIR = "runtime"
Expand All @@ -46,6 +48,8 @@ RETRY_TIMES = %d
DELAY = %d
RANDOM_DELAY = %d
PARALLELISM = %d
IMAGE_HEIGHT = %d
COL_WIDTH = %d
# 该目录存放程序运行时产生的文件
RUNTIME_DIR = "%s"
Expand All @@ -59,6 +63,6 @@ func getAllConfEnvStrDefault() string {
return fmt.Sprintf(ENV_FILE_CONTENT, DEFAULT_DB_DRIVER, DEFAULT_DB_HOST, DEFAULT_DB_PORT,
DEFAULT_DB_NAME, DEFAULT_DB_USERNAME, DEFAULT_DB_PASSWORD, DEFAULT_DB_NODE_ID,
DEFAULT_USER_AGENT, "", "", DEFAULT_TIMEOUT, DEFAULT_RETRY_TIMES, DEFAULT_DELAY,
DEFAULT_RANDOM_DELAY, DEFAULT_PARALLELISM, DEFAULT_RUNTIME_DIR, DEFAULT_IMAGES_PATH,
DEFAULT_RANDOM_DELAY, DEFAULT_PARALLELISM, DEFAULT_IMAGE_HEIGHT, DEFAULT_COL_WIDTH, DEFAULT_RUNTIME_DIR, DEFAULT_IMAGES_PATH,
DEFAULT_DOWNLOADS_PATH, DEFAULT_FYNE_FONT, DEFAULT_FYNE_TITLE)
}
21 changes: 7 additions & 14 deletions conf/conf_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,24 @@ func setEnvFile() {
func initEnvFile() []string {
var err error
var files []string
var createNewEnvfile bool
if !miniutils.IsPathExists(WorkEnvFile) {
err = createEnvFile(WorkEnvFile)
if err != nil {
panic(err)
}
files = append(files, WorkEnvFile)
fmt.Printf("Create file %s SUCCESS\n", WorkEnvFile)
createNewEnvfile = true
}
files = append(files, WorkEnvFile)

if miniutils.IsPathExists(DEFAULT_ENV_FILE) {
files = append(files, DEFAULT_ENV_FILE)
} else {
if createNewEnvfile {
err = createEnvFile(DEFAULT_ENV_FILE)
if err != nil {
fmt.Printf("--------initEnvFile(%s)err(%v)\n", DEFAULT_ENV_FILE, err)
return files
}
files = append(files, DEFAULT_ENV_FILE)
fmt.Printf("Create file %s SUCCESS\n", DEFAULT_ENV_FILE)
if !miniutils.IsPathExists(DEFAULT_ENV_FILE) {
err = createEnvFile(DEFAULT_ENV_FILE)
if err != nil {
fmt.Printf("--------initEnvFile(%s)err(%v)\n", DEFAULT_ENV_FILE, err)
return files
}
fmt.Printf("Create file %s SUCCESS\n", DEFAULT_ENV_FILE)
}
files = append(files, DEFAULT_ENV_FILE)
return files
}

Expand Down
3 changes: 3 additions & 0 deletions conf/conf_val.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var userAgent, imgsPath, cookie, httpProxy, runtimeDir, downloadsPath, FyneFont,
var timeout, retry, delay, randomDelay, parallelism int
var dbDriver, dbName, dbUsername, dbPassword, dbHost string
var dbPort, dbNodeId int
var ImageHeight, ColWidth int

func getConfByEnv() {
FyneTitle = getEnvDefaultStr("FYNE_TITLE", DEFAULT_FYNE_TITLE)
Expand All @@ -27,6 +28,8 @@ func getConfByEnv() {
delay = getEnvDefaultInt("DELAY", DEFAULT_DELAY)
randomDelay = getEnvDefaultInt("RANDOM_DELAY", DEFAULT_RANDOM_DELAY)
parallelism = getEnvDefaultInt("PARALLELISM", DEFAULT_PARALLELISM)
ImageHeight = getEnvDefaultInt("IMAGE_HEIGHT", DEFAULT_IMAGE_HEIGHT)
ColWidth = getEnvDefaultInt("COL_WIDTH", DEFAULT_COL_WIDTH)

dbDriver = getEnvDefaultStr("DB_DRIVER", DEFAULT_DB_DRIVER)
dbName = getEnvDefaultStr("DB_NAME", DEFAULT_DB_NAME)
Expand Down
5 changes: 2 additions & 3 deletions fyne/form_downimg.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func RenderFormDownImg(w fyne.Window) fyne.CanvasObject {
imgdirItem.HintText = "文件夹名。留空则从Referer值生成。"

refererInput := widget.NewEntry()
refererInput.Text = ""
refererInput.Text = "https://image.baidu.com/"
refererInput.PlaceHolder = "填网站主页。例: https://www.amazon.com/"
excelWithPicInput := widget.NewCheck("启用", nil) // NewFyRadio(map[bool]string{false: "否", true: "是"}, false, nil)
withPicItem := widget.NewFormItem("另存为含图片的xlsx文件", excelWithPicInput)
Expand All @@ -67,8 +67,7 @@ func RenderFormDownImg(w fyne.Window) fyne.CanvasObject {
}
refererUrl := refererInput.Text
if refererUrl == "" {
CheckError(fmt.Errorf("Referer不能为空"), w)
return
refererUrl = "https://image.baidu.com/"
}
if strings.Index(refererUrl, "http") != 0 {
CheckError(fmt.Errorf("Referer必须以http开头"), w)
Expand Down
9 changes: 8 additions & 1 deletion service/excel.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ func (e *ExcelService) setLocalImages(sheetName, imgTitle, baseUrl, dirname stri
}
sconf := conf.GetSpiderConf()
miniutils.Mkdir(sconf.ImagesPath + "/" + dirname)
colHeiht := conf.ImageHeight
colWidth := conf.ColWidth

// 遍历数据列
imgTitleExist := false
Expand All @@ -300,8 +302,10 @@ func (e *ExcelService) setLocalImages(sheetName, imgTitle, baseUrl, dirname stri
imgTitleExist = true

rowI := 1
f.SetColWidth(sheetName, fmt.Sprintf("%c", colI), fmt.Sprintf("%c", colI), float64(colWidth))
for i, cell := range col {
f.SetRowHeight(sheetName, rowI, 76)
f.SetRowHeight(sheetName, rowI, float64(colHeiht))

if i == 0 {
rowI++
continue
Expand Down Expand Up @@ -384,6 +388,9 @@ func DownloadImagesByExcel(filepath, sheetName, imgTitle, referer, dirname strin
return err
}
updateExcel := NewExcelService(f)
if referer == "" {
referer = "https://image.baidu.com/"
}
err = updateExcel.DownloadImagesByColly(sheetName, imgTitle, referer, dirname, onResp, withImgFile)
// err = updateExcel.DownloadImages(sheetName, imgTitle, referer, dirname)
if err != nil {
Expand Down

0 comments on commit ed0637a

Please sign in to comment.