master
兔子 5 days ago
parent 32c6e7b534
commit 98ed1980ff

@ -0,0 +1,74 @@
package astro
import (
_ "embed"
"encoding/json"
"errors"
"fmt"
"os"
"strings"
"time"
)
//go:embed city.json
var cityByte []byte
type City struct {
Code int `json:"code"`
CityName string `json:"city_name"`
Lat float64 `json:"lat"`
Lon float64 `json:"lon"`
}
var lon, lat, height, loc float64
var city string
func SetLonLatHeight(lo, la, he float64) error {
lon, lat, height = lo, la, he
return os.WriteFile(".ast.env", []byte(fmt.Sprintf("%f,%f,%f,%f", lon, lat, height, loc)), 0644)
}
func LoadLonLatHeight() error {
if _, err := os.Stat(".ast.env"); errors.Is(err, os.ErrNotExist) {
return nil
}
b, err := os.ReadFile(".ast.env")
if err != nil {
return err
}
_, err = fmt.Sscanf(string(b), "%f,%f,%f,%f", &lon, &lat, &height, &loc)
return err
}
func GetLonLatHeight() (float64, float64, float64) {
return lon, lat, height
}
func Lon() float64 {
return lon
}
func Lat() float64 {
return lat
}
func Height() float64 {
return height
}
func GetFromCity(name string) bool {
var c []City
err := json.Unmarshal(cityByte, &c)
if err != nil {
return false
}
for _, v := range c {
if strings.Contains(v.CityName, name) {
lon, lat = v.Lon, v.Lat
loc = 8
time.Local = time.FixedZone("Local", int(loc*3600))
return true
}
}
return false
}

@ -0,0 +1,431 @@
package astro
import (
"b612.me/astro/calendar"
"b612.me/staros"
"fmt"
"github.com/spf13/cobra"
"golang.org/x/term"
"os"
"strconv"
"strings"
"time"
)
var year int
var nowDay string
var isTimestamp bool
var isLunar, isLive, isLeap bool
func init() {
CmdDateInfo.Flags().StringVarP(&nowDay, "now", "n", "", "指定现在的时间")
CmdDateInfo.Flags().BoolVarP(&isTimestamp, "timestamp", "t", false, "是否为时间戳")
CmdDateInfo.Flags().BoolVarP(&isLunar, "lunar", "l", false, "是否为农历")
CmdDateInfo.Flags().BoolVarP(&isLive, "live", "v", false, "是否为实时")
CmdDateInfo.Flags().BoolVarP(&isLeap, "leap", "L", false, "是否为农历闰月")
CmdHoliday.Flags().IntVarP(&year, "year", "y", 0, "年份")
CmdCal.AddCommand(CmdHoliday, CmdDateInfo)
}
var CmdCal = &cobra.Command{
Use: "cal",
Args: cobra.MaximumNArgs(100),
Short: "简洁日历与日期相关方法",
Long: "简洁日历,支持多个月份,多个年份,支持年份月份混合输入,日期方法请查看子命令",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
now := time.Now()
fmt.Println(now.Format("2006年01月"))
fmt.Println("------------------------")
ShowCalendar(now.Year(), int(now.Month()))
return
}
for _, v := range args {
if len(v) < 4 {
fmt.Println("输入错误年份至少4位")
return
}
year, err := strconv.Atoi(v[:4])
if err != nil {
fmt.Println("输入错误:", err)
return
}
if len(v) == 4 {
for i := 1; i <= 12; i++ {
fmt.Printf("%d年%d月\n", year, i)
fmt.Println("------------------------")
ShowCalendar(year, i)
fmt.Println()
fmt.Println()
}
continue
}
month, err := strconv.Atoi(v[4:])
if err != nil {
fmt.Println("输入错误:", err)
return
}
fmt.Printf("%d年%d月\n", year, month)
fmt.Println("------------------------")
ShowCalendar(year, month)
fmt.Println()
}
},
}
var CmdHoliday = &cobra.Command{
Use: "hol",
Short: "中国法定节日放假安排",
Long: "中国法定节日放假安排",
Run: func(cmd *cobra.Command, args []string) {
if year == 0 {
year = time.Now().Year()
}
fmt.Printf("%d年放假安排\n", year)
for _, v := range args {
fmt.Println("------------------------")
var d Holiday
switch v {
case "1", "元旦":
d = YuanDan(year)
case "2", "春节":
d = ChunJie(year)
case "3", "清明", "清明节":
d = QingMing(year)
case "4", "劳动", "劳动节":
d = LaoDongJie(year)
case "5", "端午", "端午节":
d = DuanWu(year)
case "6", "中秋", "中秋节":
d = ZhongQiu(year)
case "7", "国庆", "国庆节":
d = GuoQing(year)
}
d.BasicInfo()
d.Detail()
}
if len(args) == 0 {
for _, v := range ChineseHoliday(year) {
fmt.Println("------------------------")
v.BasicInfo()
v.Detail()
fmt.Println(" ")
}
}
},
}
var CmdDateInfo = &cobra.Command{
Use: "info",
Short: "指定时刻的详情",
Long: "指定时刻的详情格式info [时间] [选项]",
Run: func(cmd *cobra.Command, args []string) {
var now = time.Now()
var target = now
var err error
if nowDay != "" {
now, err = parseDate(time.Time{}, nowDay, isTimestamp)
if err != nil {
fmt.Println(err)
return
}
}
if len(args) > 0 {
target, err = parseDate(now, args[0], isTimestamp)
if err != nil {
fmt.Println(err)
return
}
}
for {
if isLunar {
LDateInfo(now, target, isLeap)
} else {
DateInfo(now, target)
}
if !isLive {
break
}
time.Sleep(time.Nanosecond*
time.Duration(1000000000-time.Now().Nanosecond()) + 1)
if nowDay == "" {
now = time.Now()
now = now.Add(time.Duration(now.Nanosecond()*-1) * time.Nanosecond)
} else {
now = now.Add(time.Second)
}
ClearScreen()
}
},
}
func ClearScreen() {
fmt.Print("\033[H\033[2J")
}
func GenerateCalendar(year int, month int) []string {
var days []string
date := time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.Local)
firstWeekday := int(date.Weekday()) - 1
if firstWeekday < 0 {
firstWeekday += 7
}
count := 0
for i := 0; i < firstWeekday; i++ {
days = append(days, " ")
count++
}
for i := 1; i <= 32; i++ {
insertLunar := func(start int) {
if start < 0 {
start += 7
}
for j := start; j >= 0; j-- {
if i-j < 1 {
days = append(days, "\u3000\u3000")
continue
}
date = time.Date(year, time.Month(month), i-j, 0, 0, 0, 0, time.Local)
_, d, _, str := calendar.RapidSolarToLunar(date)
if d != 1 {
str = str[strings.Index(str, "月")+3:]
} else {
str = str[:strings.Index(str, "月")+3]
}
days = append(days, str)
}
}
date = time.Date(year, time.Month(month), i, 0, 0, 0, 0, time.Local)
if date.Month() != time.Month(month) {
if (count)%7 != 0 {
i--
insertLunar(count%7 - 1)
}
break
}
days = append(days, fmt.Sprintf("%d", i))
count++
if count%7 == 0 {
insertLunar(6)
}
}
return days
}
func ShowCalendar(year int, month int) {
days := GenerateCalendar(year, month)
fd := int(os.Stdout.Fd())
width, _, err := term.GetSize(fd)
if err != nil {
fmt.Println("Error getting terminal size:", err)
return
}
spark := 4
if width > 45 {
spark = 5
}
if width < 30 {
fmt.Println("Terminal too small")
return
}
for _, v := range []string{"\u3000一", "\u3000二", "\u3000三", "\u3000四", "\u3000五", "\u3000六", "\u3000日"} {
fmt.Printf("%*s", spark-1, v)
}
fmt.Println()
ct := 0
doBreak := false
for i, v := range days {
if len(days)-i < 7 && i%7 == len(days)-i && !doBreak {
doBreak = true
ct++
if ct%2 == 1 {
spark -= 2
} else {
spark += 2
}
fmt.Println()
fmt.Print(" ")
}
if i%7 == 0 && i != 0 && !doBreak {
fmt.Println()
ct++
if ct%2 == 1 {
fmt.Print(" ")
spark -= 2
} else {
spark += 2
}
}
fmt.Printf("%*s ", spark, v)
}
}
func LDateInfo(now, date time.Time, isLeap bool) {
sdate := calendar.RapidLunarToSolar(date.Year(), int(date.Month()), date.Day(), isLeap)
DateInfo(now, sdate)
}
func DateInfo(now, date time.Time) {
if now.IsZero() {
now = time.Now()
}
_, m, _, str := calendar.RapidSolarToLunar(date)
gz := calendar.GanZhi(date.Year())
if m > 10 && int(date.Month()) < 3 {
gz = calendar.GanZhi(date.Year() - 1)
}
fmt.Println("现在:", now.Format("2006年01月02日 15:04:05"))
fmt.Println("-------------------------")
xq := []string{"日", "一", "二", "三", "四", "五", "六"}
fmt.Printf("公历:%s 星期%s\n", date.Format("2006年01月02日 15:04:05"), xq[date.Weekday()])
fmt.Println("农历:", gz+str)
fmt.Printf("时间戳:%v\n", date.Unix())
fmt.Println("-------------------------")
diff := date.Sub(now)
fmt.Printf("距今: %.5f秒\n", diff.Seconds())
fmt.Printf("距今: %.5f分钟\n", diff.Minutes())
fmt.Printf("距今: %.5f小时\n", diff.Hours())
fmt.Printf("距今: %.5f天\n", diff.Hours()/24)
fmt.Printf("距今: %.5f年\n", diff.Hours()/24/365.2425)
fmt.Println("距今:", dayDiff(now, date))
}
func dayDiff(date1, date2 time.Time) string {
// 提取年、月、日
pr := ""
if date1.After(date2) {
pr = "-"
date1, date2 = date2, date1
}
years, months, days := date2.Date()
yearDiff := years - date1.Year()
monthDiff := int(months) - int(date1.Month())
dayDiff := days - date1.Day()
// 处理负的月份和日期差
if dayDiff < 0 {
monthDiff--
// 计算上个月的天数
prevMonth := date2.AddDate(0, -1, 0)
dayDiff += time.Date(prevMonth.Year(), prevMonth.Month(), 0, 0, 0, 0, 0, time.UTC).Day()
}
if monthDiff < 0 {
yearDiff--
monthDiff += 12
}
// 提取小时、分钟和秒
hours := date2.Hour() - date1.Hour()
minutes := date2.Minute() - date1.Minute()
seconds := date2.Second() - date1.Second()
// 处理负的小时、分钟和秒差
if seconds < 0 {
minutes--
seconds += 60
}
if minutes < 0 {
hours--
minutes += 60
}
if hours < 0 {
days--
hours += 24
}
return fmt.Sprintf("%s%d年%d月%d日%d时%d分%d秒", pr, yearDiff, monthDiff, dayDiff, hours, minutes, seconds)
}
func parseDate(base time.Time, date string, isTimestamp bool) (time.Time, error) {
if isTimestamp {
i, err := strconv.Atoi(date)
if err != nil {
return time.Time{}, err
}
return time.Unix(int64(i), 0), nil
}
if base.IsZero() {
base = time.Now()
}
if strings.HasPrefix(date, "+") || strings.HasPrefix(date, "p") {
val, err := staros.Calc(date[1:])
if err != nil {
return time.Time{}, err
}
for val > 9.22e09 {
val = val - 9.22e09
base = base.Add(9.22e09 * time.Second)
}
return base.Add(time.Second * time.Duration(int(val))), nil
}
if strings.HasPrefix(date, "-") || strings.HasPrefix(date, "—") ||
strings.HasPrefix(date, "~") || strings.HasPrefix(date, "!") ||
strings.HasPrefix(date, "m") {
val, err := staros.Calc(date[1:])
if err != nil {
return time.Time{}, err
}
for val > 9.22e09 {
val = val - 9.22e09
base = base.Add(-9.22e09 * time.Second)
}
return base.Add(-1 * time.Second * time.Duration(int(val))), nil
}
if strings.Contains(date, "-") {
d, err := time.ParseInLocation("2006-01-02 15:04:05", date, time.Local)
if err == nil {
return d, nil
}
d, err = time.ParseInLocation("2006-01-02", date, time.Local)
if err == nil {
return d, nil
}
d, err = time.ParseInLocation("2006-01-02T15:04:05-0700", date, time.Local)
if err == nil {
return d, nil
}
d, err = time.ParseInLocation("2006-01-02T15:04:05Z", date, time.Local)
if err == nil {
return d, nil
}
return time.Time{}, err
}
if strings.Contains(date, "/") {
d, err := time.ParseInLocation("2006/01/02 15:04:05", date, time.Local)
if err == nil {
return d, nil
}
d, err = time.ParseInLocation("2006/01/02", date, time.Local)
if err == nil {
return d, nil
}
d, err = time.ParseInLocation("02/01/2006 15:04:05", date, time.Local)
if err == nil {
return d, nil
}
d, err = time.ParseInLocation("02/01/2006", date, time.Local)
if err == nil {
return d, nil
}
d, err = time.ParseInLocation("01/02/2006 15:04:05", date, time.Local)
if err == nil {
return d, nil
}
d, err = time.ParseInLocation("01/02/2006", date, time.Local)
if err == nil {
return d, nil
}
return time.Time{}, err
}
d, err := time.ParseInLocation("20060102150405", date, time.Local)
if err == nil {
return d, nil
}
d, err = time.ParseInLocation("20060102", date, time.Local)
if err == nil {
return d, nil
}
return time.Time{}, fmt.Errorf("无法解析日期")
}

@ -0,0 +1,37 @@
package astro
import (
"fmt"
"testing"
"time"
)
func TestCal(t *testing.T) {
//LDateInfo(time.Time{}, time.Date(2021, 1, 1, 0, 0, 0, 0, time.Local), false)
//DateInfo(time.Time{}, time.Now().Add(time.Second*-5))
for y := 2008; y < 2028; y++ {
zq := GuoQing(y)
zq.BasicInfo()
zq.Detail()
fmt.Println("--------")
}
}
func TestChineseHoliday(t *testing.T) {
legalData := [][]Holiday{
//year 2000
{
{
Start: time.Date(1999, 12, 31, 0, 0, 0, 0, time.Local),
End: time.Date(2000, 1, 2, 0, 0, 0, 0, time.Local),
Core: time.Date(2000, 1, 1, 0, 0, 0, 0, time.Local),
Total: 3,
Instead: nil,
Name: "元旦",
LegalDays: 1,
},
},
}
_ = legalData
}

@ -0,0 +1,691 @@
package astro
import (
"b612.me/astro/calendar"
"fmt"
"time"
)
type Holiday struct {
//假日开始时间
Start time.Time
//假日结束时间
End time.Time
//节日所在日期
Core time.Time
//假日总天数
Total int
//调休日期
Instead []time.Time
//假日名称
Name string
//法定假日天数
LegalDays int
Comment string
}
func (h Holiday) BasicInfo() {
xq := []string{"日", "一", "二", "三", "四", "五", "六"}
_, m, _, str := calendar.RapidSolarToLunar(h.Core)
gz := calendar.GanZhi(h.Core.Year())
if m > 10 && int(h.Core.Month()) < 3 {
gz = calendar.GanZhi(h.Core.Year() - 1)
}
if h.Start.IsZero() {
fmt.Println(h.Name + "无假期")
return
}
fmt.Printf("节日: %s 法定假期: %d天 放假天数: %d天\n", h.Name, h.LegalDays, h.Total)
fmt.Println("公历:", h.Core.Format("2006年01月02日"), "星期"+xq[h.Core.Weekday()])
fmt.Println("农历:", gz+str)
if h.Comment != "" {
fmt.Println(h.Comment)
}
}
func (h Holiday) Detail() {
if h.Start.IsZero() {
return
}
xq := []string{"日", "一", "二", "三", "四", "五", "六"}
if h.Start.Equal(h.End) || h.End.IsZero() {
fmt.Printf("假期: %s(星期%s) 共%d天\n",
h.Start.Format("2006年01月02日"), xq[h.Start.Weekday()], h.Total)
} else {
fmt.Printf("假期: %s(星期%s) - %s(星期%s) 共%d天\n",
h.Start.Format("2006年01月02日"), xq[h.Start.Weekday()],
h.End.Format("2006年01月02日"), xq[h.End.Weekday()], h.Total)
}
if len(h.Instead) > 0 {
fmt.Print("调休: ")
for idx, v := range h.Instead {
fmt.Printf("%s(星期%s)", v.Format("01月02日"), xq[v.Weekday()])
if idx != len(h.Instead)-1 {
fmt.Print("、")
}
}
fmt.Println(" 上班")
return
}
fmt.Println("不调休")
}
func target3Day1(date time.Time) Holiday {
switch date.Weekday() {
case 0:
return Holiday{
Core: date,
Start: date.Add(-24 * time.Hour),
End: date.Add(24 * time.Hour),
Total: 3,
LegalDays: 1,
}
case 1:
return Holiday{
Core: date,
Start: date.Add(-48 * time.Hour),
End: date,
Total: 3,
LegalDays: 1,
}
case 5, 6:
return Holiday{
Core: date,
Start: date,
End: date.Add(48 * time.Hour),
Total: 3,
LegalDays: 1,
}
case 3:
return Holiday{
Core: date,
Start: date,
End: date,
Total: 1,
LegalDays: 1,
}
case 2:
return Holiday{
Core: date,
Start: date.Add(-48 * time.Hour),
End: date,
Total: 3,
Instead: []time.Time{date.Add(-72 * time.Hour)},
LegalDays: 1,
}
case 4:
return Holiday{
Core: date,
Start: date,
End: date.Add(48 * time.Hour),
Total: 3,
Instead: []time.Time{date.Add(72 * time.Hour)},
LegalDays: 1,
}
}
return Holiday{}
}
func target5Day1(date time.Time) Holiday {
switch date.Weekday() {
case 1:
return Holiday{
Start: date.Add(time.Hour * -48),
End: date.Add(time.Hour * 48),
Core: date,
Total: 5,
Instead: []time.Time{date.Add(time.Hour * -24 * 8), date.Add(time.Hour * 24 * 5)},
Name: "",
LegalDays: 1,
}
case 2:
return Holiday{
Start: date,
End: date.Add(time.Hour * -24 * 4),
Core: date,
Total: 5,
Instead: []time.Time{date.Add(time.Hour * -24 * 2), date.Add(time.Hour * 24 * 5)},
Name: "",
LegalDays: 1,
}
case 3:
return Holiday{
Start: date,
End: date.Add(time.Hour * 24 * 4),
Core: date,
Total: 5,
Instead: []time.Time{date.Add(time.Hour * -24 * 3), date.Add(time.Hour * 24 * 10)},
Name: "",
LegalDays: 1,
}
case 4:
return Holiday{
Start: date,
End: date.Add(time.Hour * 24 * 4),
Core: date,
Total: 5,
Instead: []time.Time{date.Add(time.Hour * -24 * 4), date.Add(time.Hour * 24 * 9)},
Name: "",
LegalDays: 1,
}
case 5:
return Holiday{
Start: date,
End: date.Add(time.Hour * 24 * 4),
Core: date,
Total: 5,
Instead: []time.Time{date.Add(time.Hour * -24 * 5), date.Add(time.Hour * 24 * 8)},
Name: "",
LegalDays: 1,
}
case 6:
return Holiday{
Start: date,
End: date.Add(time.Hour * 24 * 4),
Core: date,
Total: 5,
Instead: []time.Time{date.Add(time.Hour * -24 * 6), date.Add(time.Hour * 24 * 7)},
Name: "",
LegalDays: 1,
}
case 0:
return Holiday{
Start: date.Add(time.Hour * -24),
End: date.Add(time.Hour * 24 * 3),
Core: date,
Total: 5,
Instead: []time.Time{date.Add(time.Hour * -24 * 7), date.Add(time.Hour * 24 * 6)},
Name: "",
LegalDays: 1,
}
}
return Holiday{}
}
func target5Day2(date time.Time) Holiday {
switch date.Weekday() {
case 1:
return Holiday{
Start: date.Add(time.Hour * -48),
End: date.Add(time.Hour * 48),
Core: date,
Total: 5,
Instead: []time.Time{date.Add(time.Hour * 24 * 5)},
Name: "",
LegalDays: 2,
}
case 2:
return Holiday{
Start: date,
End: date.Add(time.Hour * -24 * 4),
Core: date,
Total: 5,
Instead: []time.Time{date.Add(time.Hour * -24 * 2)},
Name: "",
LegalDays: 2,
}
case 3:
return Holiday{
Start: date,
End: date.Add(time.Hour * 24 * 4),
Core: date,
Total: 5,
Instead: []time.Time{date.Add(time.Hour * -24 * 3)},
Name: "",
LegalDays: 2,
}
case 4:
return Holiday{
Start: date,
End: date.Add(time.Hour * 24 * 4),
Core: date,
Total: 5,
Instead: []time.Time{date.Add(time.Hour * -24 * 4)},
Name: "",
LegalDays: 2,
}
case 5:
return Holiday{
Start: date,
End: date.Add(time.Hour * 24 * 4),
Core: date,
Total: 5,
Instead: []time.Time{date.Add(time.Hour * 24 * 8)},
Name: "",
LegalDays: 2,
}
case 6:
return Holiday{
Start: date,
End: date.Add(time.Hour * 24 * 4),
Core: date,
Total: 5,
Instead: []time.Time{date.Add(time.Hour * 24 * 7)},
Name: "",
LegalDays: 2,
}
case 0:
return Holiday{
Start: date.Add(time.Hour * -24),
End: date.Add(time.Hour * 24 * 3),
Core: date,
Total: 5,
Instead: []time.Time{date.Add(time.Hour * 24 * 6)},
Name: "",
LegalDays: 2,
}
}
return Holiday{}
}
func target7Day3(date time.Time) Holiday {
switch date.Weekday() {
case 1:
return Holiday{
Start: date,
End: date.Add(time.Hour * 6 * 24),
Core: date,
Total: 7,
Instead: []time.Time{date.Add(time.Hour * 24 * -2), date.Add(time.Hour * 24 * -1)},
Name: "",
LegalDays: 3,
}
case 2:
return Holiday{
Start: date,
End: date.Add(time.Hour * 6 * 24),
Core: date,
Total: 7,
Instead: []time.Time{date.Add(time.Hour * 24 * -2), date.Add(time.Hour * 24 * 11)},
Name: "",
LegalDays: 3,
}
case 3:
return Holiday{
Start: date,
End: date.Add(time.Hour * 6 * 24),
Core: date,
Total: 7,
Instead: []time.Time{date.Add(time.Hour * 24 * -3), date.Add(time.Hour * 24 * 10)},
Name: "",
LegalDays: 3,
}
case 4:
return Holiday{
Start: date,
End: date.Add(time.Hour * 6 * 24),
Core: date,
Total: 7,
Instead: []time.Time{date.Add(time.Hour * 24 * -4), date.Add(time.Hour * 24 * 9)},
Name: "",
LegalDays: 3,
}
case 5:
return Holiday{
Start: date,
End: date.Add(time.Hour * 6 * 24),
Core: date,
Total: 7,
Instead: []time.Time{date.Add(time.Hour * 24 * -5), date.Add(time.Hour * 24 * 8)},
Name: "",
LegalDays: 3,
}
case 6:
return Holiday{
Start: date,
End: date.Add(time.Hour * 6 * 24),
Core: date,
Total: 7,
Instead: []time.Time{date.Add(time.Hour * 24 * 7), date.Add(time.Hour * 24 * 8)},
Name: "",
LegalDays: 3,
}
case 0:
return Holiday{
Start: date,
End: date.Add(time.Hour * 6 * 24),
Core: date,
Total: 7,
Instead: []time.Time{date.Add(time.Hour * 24 * -1), date.Add(time.Hour * 24 * 7)},
Name: "",
LegalDays: 3,
}
}
return Holiday{}
}
func target8Day4(date time.Time) Holiday {
switch date.Weekday() {
case 1:
return Holiday{
Start: date,
End: date.Add(time.Hour * 7 * 24),
Core: date,
Total: 8,
Instead: []time.Time{date.Add(time.Hour * 24 * -2), date.Add(time.Hour * 24 * -1)},
Name: "",
LegalDays: 4,
}
case 2:
return Holiday{
Start: date,
End: date.Add(time.Hour * 7 * 24),
Core: date,
Total: 8,
Instead: []time.Time{date.Add(time.Hour * 24 * -2), date.Add(time.Hour * 24 * 11)},
Name: "",
LegalDays: 4,
}
case 3:
return Holiday{
Start: date,
End: date.Add(time.Hour * 7 * 24),
Core: date,
Total: 8,
Instead: []time.Time{date.Add(time.Hour * 24 * -3), date.Add(time.Hour * 24 * 10)},
Name: "",
LegalDays: 4,
}
case 4:
return Holiday{
Start: date,
End: date.Add(time.Hour * 7 * 24),
Core: date,
Total: 8,
Instead: []time.Time{date.Add(time.Hour * 24 * -4), date.Add(time.Hour * 24 * 9)},
Name: "",
LegalDays: 4,
}
case 5:
if date.Year() >= 2025 {
return Holiday{
Start: date,
End: date.Add(time.Hour * 8 * 24),
Core: date,
Total: 9,
Instead: []time.Time{date.Add(time.Hour * 24 * -5), date.Add(time.Hour * 24 * 9)},
Name: "",
LegalDays: 4,
}
}
return Holiday{
Start: date,
End: date.Add(time.Hour * 7 * 24),
Core: date,
Total: 8,
Instead: []time.Time{date.Add(time.Hour * 24 * 8), date.Add(time.Hour * 24 * 9)},
Name: "",
LegalDays: 4,
}
case 6:
return Holiday{
Start: date,
End: date.Add(time.Hour * 7 * 24),
Core: date,
Total: 8,
Instead: []time.Time{date.Add(time.Hour * 24 * -6), date.Add(time.Hour * 24 * 8)},
Name: "",
LegalDays: 2,
}
case 0:
return Holiday{
Start: date,
End: date.Add(time.Hour * 7 * 24),
Core: date,
Total: 8,
Instead: []time.Time{date.Add(time.Hour * 24 * -1)},
Name: "",
LegalDays: 2,
}
}
return Holiday{}
}
// 元旦
func YuanDan(year int) Holiday {
name := "元旦"
date := time.Date(year, 1, 1, 0, 0, 0, 0, time.Local)
if year > 2007 || year == 2005 {
d := target3Day1(date)
d.Name = name
return d
}
switch year {
case 2007:
return Holiday{
Start: date,
End: date.Add(3 * 24 * time.Hour),
Core: date,
Total: 3,
Instead: []time.Time{date.Add(-24 * time.Hour), date.Add(-2 * 24 * time.Hour)},
Name: name,
LegalDays: 1,
}
case 2006:
return Holiday{
Start: date,
End: date.Add(3 * 24 * time.Hour),
Core: date,
Total: 3,
Instead: []time.Time{date.Add(-24 * time.Hour)},
Name: name,
LegalDays: 1,
}
case 2004, 2003:
return Holiday{
Start: date,
End: date,
Core: date,
Total: 1,
Instead: nil,
Name: name,
LegalDays: 1,
}
case 2002:
return Holiday{
Start: date,
End: date.Add(3 * 24 * time.Hour),
Core: date,
Total: 3,
Instead: []time.Time{date.Add(-3 * 24 * time.Hour), date.Add(-2 * 24 * time.Hour)},
Name: name,
LegalDays: 1,
}
}
return Holiday{Name: name}
}
// 春节
func ChunJie(year int) Holiday {
name := "春节"
chineseNewYear := calendar.RapidLunarToSolar(year, 1, 1, false)
chuxi := chineseNewYear.AddDate(0, 0, -1)
if year <= 2007 || year == 2014 {
d := target7Day3(chineseNewYear)
d.Name = name
return d
}
if year >= 2008 && year < 2024 {
d := target7Day3(chuxi)
d.Name = name
if year == 2020 {
d.Comment = "因新冠疫情防控2020年春节延长至2月2日"
}
return d
}
if year == 2024 {
d := target8Day4(chineseNewYear)
d.LegalDays = 3
d.Name = name
return d
}
d := target8Day4(chuxi)
d.Name = name
return d
}
func QingMing(year int) Holiday {
name := "清明节"
if year < 2008 {
return Holiday{Name: name}
}
qingming := calendar.JieQi(year, calendar.JQ_)
d := target3Day1(qingming)
d.Name = name
return d
}
func LaoDongJie(year int) Holiday {
name := "劳动节"
date := time.Date(year, 5, 1, 0, 0, 0, 0, time.Local)
if year < 2008 {
d := target7Day3(date)
d.Name = name
return d
}
if year == 2019 {
return Holiday{
Start: date,
End: date.Add(4 * 24 * time.Hour),
Core: date,
Total: 4,
Instead: []time.Time{date.Add(-24 * 3 * time.Hour), date.Add(24 * time.Hour * 5)},
Name: name,
LegalDays: 1,
Comment: "",
}
}
if year >= 2008 && year < 2020 {
d := target3Day1(date)
d.Name = name
return d
}
if year >= 2020 && year < 2025 {
d := target5Day1(date)
d.Name = name
return d
}
d := target5Day2(date)
d.Name = name
return d
}
func DuanWu(year int) Holiday {
name := "端午节"
if year < 2008 {
return Holiday{Name: name}
}
date := calendar.RapidLunarToSolar(year, 5, 5, false)
d := target3Day1(date)
d.Name = name
return d
}
func ZhongQiu(year int) Holiday {
name := "中秋节"
if year < 2008 {
return Holiday{Name: name}
}
date := calendar.RapidLunarToSolar(year, 8, 15, false)
if date.Month() == 9 && date.Day() >= 28 {
d := target8Day4(date)
d.Name = "国庆中秋连假"
return d
} else if date.Month() == 10 {
d := target8Day4(time.Date(year, 10, 1, 0, 0, 0, 0, time.Local))
d.Name = "国庆中秋连假"
return d
}
d := target3Day1(date)
d.Name = name
if date.Month() == 9 && date.Day() <= 20 {
return d
}
if date.Weekday() == 3 {
d.Instead = []time.Time{date.Add(-24 * 3 * time.Hour), date.Add(24 * 3 * time.Hour)}
d.End = date.Add(2 * 24 * time.Hour)
d.Total = 3
}
gq := target7Day3(time.Date(year, 10, 1, 0, 0, 0, 0, time.Local))
for _, v := range gq.Instead {
if v.Before(d.End) || v.Equal(d.End) {
if v.Equal(date) {
d.Total = d.Total - 1
d.End = d.End.Add(-24 * time.Hour)
} else {
if v.Equal(d.Start) {
d.Total = d.Total - 1
d.Start = d.Start.Add(24 * time.Hour)
} else if v.Equal(d.End) {
d.Total = d.Total - 1
d.End = d.End.Add(-24 * time.Hour)
}
}
}
}
return d
}
func GuoQing(year int) Holiday {
name := "国庆节"
date := time.Date(year, 10, 1, 0, 0, 0, 0, time.Local)
zq := calendar.RapidLunarToSolar(year, 8, 15, false)
if year == 2008 {
return Holiday{
Start: date.Add(-24 * 2 * time.Hour),
End: date.Add(4 * 24 * time.Hour),
Core: date,
Total: 7,
Instead: []time.Time{date.Add(-24 * 4 * time.Hour), date.Add(24 * -3 * time.Hour)},
Name: name,
LegalDays: 3,
}
}
if year < 2008 || (zq.Month() == 9 && zq.Day() <= 20) {
d := target7Day3(date)
d.Name = name
return d
}
if zq.Month() == 9 && zq.Day() >= 28 {
d := target8Day4(zq)
d.Name = "国庆中秋连假"
return d
} else if zq.Month() == 10 {
d := target8Day4(date)
d.Name = "国庆中秋连假"
return d
}
zqd := target3Day1(zq)
if date.Weekday() == 3 {
zqd.Instead = []time.Time{date.Add(-24 * 3 * time.Hour), date.Add(24 * 3 * time.Hour)}
zqd.End = date.Add(2 * 24 * time.Hour)
zqd.Total = 3
}
d := target7Day3(date)
d.Name = name
for k, v := range d.Instead {
if v.Before(zqd.End) || v.Equal(zqd.End) {
if v.Equal(zq) {
d.Instead = append(d.Instead[:k], d.Instead[k+1:]...)
}
}
}
return d
}
func ChineseHoliday(year int) []Holiday {
d := []Holiday{
YuanDan(year),
ChunJie(year),
QingMing(year),
LaoDongJie(year),
DuanWu(year),
ZhongQiu(year),
GuoQing(year),
}
if d[len(d)-1].Name == "国庆中秋连假" {
return d[:len(d)-1]
}
return d
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,197 @@
package astro
import (
"fmt"
"github.com/spf13/cobra"
"time"
)
var isFormat bool
func init() {
Cmd.PersistentFlags().Float64Var(&lon, "lon", -273, "经度,WGS84坐标系")
Cmd.PersistentFlags().Float64Var(&lat, "lat", -273, "纬度,WGS84坐标系")
Cmd.PersistentFlags().Float64Var(&height, "height", 0, "海拔高度")
CmdSun.Flags().StringVarP(&nowDay, "now", "n", "", "指定现在的时间")
CmdSun.Flags().BoolVarP(&isTimestamp, "timestamp", "t", false, "是否为时间戳")
CmdSun.Flags().BoolVarP(&isLive, "live", "v", false, "是否为实时")
CmdSun.Flags().BoolVarP(&isFormat, "format", "f", false, "格式化输出")
CmdSun.Flags().StringVarP(&city, "city", "c", "", "城市名")
CmdMoon.Flags().StringVarP(&nowDay, "now", "n", "", "指定现在的时间")
CmdMoon.Flags().BoolVarP(&isTimestamp, "timestamp", "t", false, "是否为时间戳")
CmdMoon.Flags().BoolVarP(&isLive, "live", "v", false, "是否为实时")
CmdMoon.Flags().BoolVarP(&isFormat, "format", "f", false, "格式化输出")
CmdMoon.Flags().StringVarP(&city, "city", "c", "", "城市名")
CmdStar.Flags().StringVarP(&nowDay, "now", "n", "", "指定现在的时间")
CmdStar.Flags().BoolVarP(&isTimestamp, "timestamp", "t", false, "是否为时间戳")
CmdStar.Flags().BoolVarP(&isLive, "live", "v", false, "是否为实时")
CmdStar.Flags().BoolVarP(&isFormat, "format", "f", false, "格式化输出")
CmdStar.Flags().StringVarP(&city, "city", "c", "", "城市名")
Cmd.AddCommand(CmdCal, CmdSun, CmdMoon, CmdStar)
}
var Cmd = &cobra.Command{
Use: "astro",
Short: "天文计算",
}
var CmdSun = &cobra.Command{
Use: "sun",
Short: "太阳计算",
Run: func(cmd *cobra.Command, args []string) {
format := 0
if isFormat {
format = 1
}
isSet := CliLoadLonLatHeight()
var now = time.Now()
var err error
if nowDay != "" {
now, err = parseDate(now, nowDay, isTimestamp)
if err != nil {
fmt.Println(err)
return
}
}
for {
if isSet {
fmt.Printf("经度: %f 纬度: %f 海拔: %f\n", lon, lat, height)
}
BasicSun(now, uint8(format))
if isSet {
SunDetail(now, lon, lat, height, uint8(format))
}
if !isLive {
break
}
time.Sleep(time.Nanosecond*
time.Duration(1000000000-time.Now().Nanosecond()) + 1)
if nowDay == "" {
now = time.Now()
now = now.Add(time.Duration(now.Nanosecond()*-1) * time.Nanosecond)
} else {
now = now.Add(time.Second)
}
ClearScreen()
}
},
}
var CmdMoon = &cobra.Command{
Use: "moon",
Short: "月亮计算",
Run: func(cmd *cobra.Command, args []string) {
format := 0
if isFormat {
format = 1
}
isSet := CliLoadLonLatHeight()
var now = time.Now()
var err error
if nowDay != "" {
now, err = parseDate(now, nowDay, isTimestamp)
if err != nil {
fmt.Println(err)
return
}
}
for {
if isSet {
fmt.Printf("经度: %f 纬度: %f 海拔: %f\n", lon, lat, height)
}
BasicMoon(now, uint8(format))
if isSet {
MoonDetail(now, lon, lat, height, uint8(format))
}
if !isLive {
break
}
time.Sleep(time.Nanosecond*
time.Duration(1000000000-time.Now().Nanosecond()) + 1)
if nowDay == "" {
now = time.Now()
now = now.Add(time.Duration(now.Nanosecond()*-1) * time.Nanosecond)
} else {
now = now.Add(time.Second)
}
ClearScreen()
}
},
}
var CmdStar = &cobra.Command{
Use: "star",
Short: "星星计算",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
fmt.Println("请输入星星名字")
return
}
format := 0
if isFormat {
format = 1
}
isSet := CliLoadLonLatHeight()
var now = time.Now()
var err error
if nowDay != "" {
now, err = parseDate(now, nowDay, isTimestamp)
if err != nil {
fmt.Println(err)
return
}
}
for {
if isSet {
fmt.Printf("经度: %f 纬度: %f 海拔: %f\n", lon, lat, height)
}
BasicStar(now, args[0], uint8(format))
if isSet {
StarDetail(now, args[0], lon, lat, height, uint8(format))
}
if !isLive {
break
}
time.Sleep(time.Nanosecond*
time.Duration(1000000000-time.Now().Nanosecond()) + 1)
if nowDay == "" {
now = time.Now()
now = now.Add(time.Duration(now.Nanosecond()*-1) * time.Nanosecond)
} else {
now = now.Add(time.Second)
}
ClearScreen()
}
},
}
func CliLoadLonLatHeight() bool {
if city != "" {
if !GetFromCity(city) {
fmt.Println("城市名错误")
return false
}
fmt.Println("城市名: ", city)
SetLonLatHeight(lon, lat, height)
return true
}
tlon, tlat, theight := lon, lat, height
LoadLonLatHeight()
if lon == -273 && lon != tlon {
lon = tlon
}
if lat == -273 && lat != tlat {
lat = tlat
}
if height == 0 && height != theight {
height = theight
}
SetLonLatHeight(lon, lat, height)
if lon == -273 || lat == -273 {
return false
}
return true
}

@ -0,0 +1,130 @@
package astro
import (
"b612.me/astro/moon"
"b612.me/astro/star"
"b612.me/astro/sun"
"b612.me/astro/tools"
"fmt"
"time"
)
func BasicMoon(date time.Time, format uint8) {
fmt.Printf("时间: %s\n", date.Format("2006-01-02 15:04:05"))
lo := moon.ApparentLo(date)
eo := moon.Phase(date)
bo := moon.TrueBo(date)
fmt.Println("月亮")
fmt.Println("------------------------")
switch format {
case 0:
fmt.Printf("黄经: %f\n", lo)
fmt.Printf("黄纬: %f\n", bo)
case 1:
flo := tools.Format(lo, 0)
fbo := tools.Format(bo, 0)
fmt.Printf("黄经: %s\n", flo)
fmt.Printf("黄纬: %s\n", fbo)
}
phaseStr := ""
mslo := tools.Limit360(lo - sun.ApparentLo(date))
if mslo >= 0 && mslo <= 30 {
phaseStr = "新月"
} else if mslo > 30 && mslo <= 75 {
phaseStr = "上峨眉月"
} else if mslo > 75 && mslo <= 135 {
phaseStr = "上弦月"
} else if mslo > 135 && mslo < 170 {
phaseStr = "盈凸月"
} else if mslo >= 170 && mslo <= 190 {
phaseStr = "满月"
} else if mslo > 190 && mslo < 225 {
phaseStr = "亏凸月"
} else if mslo >= 225 && mslo < 285 {
phaseStr = "下弦月"
} else if mslo >= 285 && mslo < 330 {
phaseStr = "下峨眉月"
} else {
phaseStr = "残月"
}
fmt.Printf("月相: %.2f%% %s\n", eo*100, phaseStr)
sx := moon.NextShangXianYue(date)
xx := moon.NextXiaXianYue(date)
wang := moon.NextWangYue(date)
shuo := moon.NextShuoYue(date)
fmt.Printf("朔月: %s\n", shuo.Format("2006-01-02 15:04:05"))
fmt.Printf("上弦: %s\n", sx.Format("2006-01-02 15:04:05"))
fmt.Printf("望月: %s\n", wang.Format("2006-01-02 15:04:05"))
fmt.Printf("下弦: %s\n", xx.Format("2006-01-02 15:04:05"))
}
func MoonDetail(date time.Time, lon, lat, height float64, format uint8) {
var err error
ra, dec := moon.ApparentRaDec(date, lon, lat)
tmp := new(time.Time)
*tmp, err = moon.RiseTime(date, lon, lat, height, true)
if err != nil {
if err == moon.ERR_NOT_TODAY {
*tmp, err = moon.RiseTime(date.AddDate(0, 0, -1), lon, lat, 0, true)
if err != nil {
*tmp = time.Time{}
}
}
}
rise := *tmp
tmp = new(time.Time)
*tmp, err = moon.DownTime(date, lon, lat, 0, true)
if err != nil {
if err == moon.ERR_NOT_TODAY {
*tmp, err = moon.DownTime(date.AddDate(0, 0, 1), lon, lat, 0, true)
if err != nil {
*tmp = time.Time{}
}
}
}
if tmp.Before(rise) {
tmp = new(time.Time)
*tmp, err = moon.DownTime(date.AddDate(0, 0, 1), lon, lat, 0, true)
if err != nil {
if err == moon.ERR_NOT_TODAY {
*tmp, err = moon.DownTime(date.AddDate(0, 0, 2), lon, lat, 0, true)
if err != nil {
*tmp = time.Time{}
}
}
}
}
set := tmp
cst := star.Constellation(ra, dec, date)
switch format {
case 0:
fmt.Printf("视赤经: %s\n", ra)
fmt.Printf("视赤纬: %s\n", dec)
case 1:
fra := tools.Format(ra/15, 1)
fdec := tools.Format(dec, 0)
fmt.Printf("视赤经: %s\n", fra)
fmt.Printf("视赤纬: %s\n", fdec)
}
fmt.Printf("星座: %s\n", cst)
fmt.Printf("升起: %s\n", rise.Format("2006-01-02 15:04:05"))
fmt.Printf("落下: %s\n", set.Format("2006-01-02 15:04:05"))
az := moon.Azimuth(date, lon, lat)
alt := moon.Zenith(date, lon, lat)
ta := moon.HourAngle(date, lon, lat)
switch format {
case 0:
fmt.Printf("方位角: %f\n", az)
fmt.Printf("高度角: %f\n", alt)
fmt.Printf("时角: %f\n", ta)
case 1:
faz := tools.Format(az, 0)
falt := tools.Format(alt, 0)
fta := tools.Format(ta/15, 1)
fmt.Printf("方位角: %s\n", faz)
fmt.Printf("高度角: %s\n", falt)
fmt.Printf("时角: %s\n", fta)
}
}

@ -0,0 +1,101 @@
package astro
import (
"b612.me/astro/star"
"b612.me/astro/tools"
"fmt"
"time"
)
func BasicStar(date time.Time, name string, format uint8) {
fmt.Printf("时间: %s\n", date.Format("2006-01-02 15:04:05"))
s, err := star.StarDataByName(name)
if err != nil {
fmt.Println(err)
return
}
ra, dec := s.RaDecByDate(date)
fmt.Printf("%s %s 星等:%.2f\n", s.ChineseName, s.Name, s.Mag)
fmt.Println("------------------------")
switch format {
case 0:
fmt.Printf("视赤经: %f\n", ra)
fmt.Printf("视赤纬: %f\n", dec)
case 1:
fra := tools.Format(ra/15, 1)
fdec := tools.Format(dec, 0)
fmt.Printf("视赤经: %s\n", fra)
fmt.Printf("视赤纬: %s\n", fdec)
}
cst := star.Constellation(ra, dec, date)
fmt.Printf("星座: %s\n", cst)
}
func StarDetail(date time.Time, name string, lon, lat, height float64, format uint8) {
s, err := star.StarDataByName(name)
if err != nil {
fmt.Println(err)
return
}
ra, dec := s.RaDecByDate(date)
alt := star.Zenith(date, ra, dec, lon, lat)
ta := star.HourAngle(date, ra, lon)
zt := star.CulminationTime(date, ra, lon)
az := star.Azimuth(date, ra, dec, lon, lat)
var rise, set time.Time
var duration time.Duration
for {
nk := date.Add(duration)
rise, err = star.RiseTime(nk, ra, dec, lon, lat, height, true)
if err != nil {
fmt.Println(err)
}
if alt > 0 && rise.After(nk) {
rise, err = star.RiseTime(nk.Add(time.Hour*-24), ra, dec, lon, lat, height, true)
if err != nil {
fmt.Println(err)
}
} else if alt < 0 && rise.Before(nk) {
rise, err = star.RiseTime(nk.Add(time.Hour*24), ra, dec, lon, lat, height, true)
if err != nil {
fmt.Println(err)
}
}
set, err = star.DownTime(nk, ra, dec, lon, lat, height, true)
if err != nil {
fmt.Println(err)
}
if set.Before(rise) {
set, err = star.DownTime(nk.Add(time.Hour*24), ra, dec, lon, lat, height, true)
if err != nil {
fmt.Println(err)
}
}
if set.Before(date) {
duration += time.Hour * 24
continue
}
if zt.Before(rise) {
zt = star.CulminationTime(nk.Add(time.Hour*24), ra, lon)
}
break
}
fmt.Printf("升起: %s\n", rise.Format("2006-01-02 15:04:05"))
fmt.Printf("中天: %s\n", zt.Format("2006-01-02 15:04:05"))
fmt.Printf("落下: %s\n", set.Format("2006-01-02 15:04:05"))
switch format {
case 0:
fmt.Printf("方位角: %f\n", az)
fmt.Printf("高度角: %f\n", alt)
fmt.Printf("时角: %f\n", ta)
case 1:
faz := tools.Format(az, 0)
falt := tools.Format(alt, 0)
fta := tools.Format(ta/15, 1)
fmt.Printf("方位角: %s\n", faz)
fmt.Printf("高度角: %s\n", falt)
fmt.Printf("时角: %s\n", fta)
}
}

@ -0,0 +1,76 @@
package astro
import (
"b612.me/astro/star"
"b612.me/astro/sun"
"b612.me/astro/tools"
"fmt"
"time"
)
func BasicSun(date time.Time, format uint8) {
fmt.Printf("时间: %s\n", date.Format("2006-01-02 15:04:05"))
ra, dec := sun.ApparentRaDec(date)
lo := sun.ApparentLo(date)
eo := sun.EclipticObliquity(date, true)
fmt.Println("太阳")
fmt.Println("------------------------")
switch format {
case 0:
fmt.Printf("视赤经: %f\n", ra)
fmt.Printf("视赤纬: %f\n", dec)
fmt.Printf("视黄经: %f\n", lo)
fmt.Printf("黄赤交角: %f\n", eo)
case 1:
fra := tools.Format(ra/15, 1)
fdec := tools.Format(dec, 0)
flo := tools.Format(lo, 0)
feo := tools.Format(eo, 0)
fmt.Printf("视赤经: %s\n", fra)
fmt.Printf("视赤纬: %s\n", fdec)
fmt.Printf("视黄经: %s\n", flo)
fmt.Printf("黄赤交角: %s\n", feo)
}
cst := star.Constellation(ra, dec, date)
fmt.Printf("星座: %s\n", cst)
}
func SunDetail(date time.Time, lon, lat, height float64, format uint8) {
rise, err := sun.RiseTime(date, lon, lat, height, true)
if err != nil {
fmt.Println(err)
}
set, err := sun.DownTime(date, lon, lat, height, true)
if err != nil {
fmt.Println(err)
}
morning, err := sun.MorningTwilight(date, lon, lat, -6)
if err != nil {
fmt.Println(err)
}
evening, err := sun.EveningTwilight(date, lon, lat, -6)
if err != nil {
fmt.Println(err)
}
fmt.Printf("晨朦影: %s\n", morning.Format("2006-01-02 15:04:05"))
fmt.Printf("升起: %s\n", rise.Format("2006-01-02 15:04:05"))
fmt.Printf("落下: %s\n", set.Format("2006-01-02 15:04:05"))
fmt.Printf("昏朦影: %s\n", evening.Format("2006-01-02 15:04:05"))
az := sun.Azimuth(date, lon, lat)
alt := sun.Zenith(date, lon, lat)
ta := sun.HourAngle(date, lon, lat)
switch format {
case 0:
fmt.Printf("方位角: %f\n", az)
fmt.Printf("高度角: %f\n", alt)
fmt.Printf("时角: %f\n", ta)
case 1:
faz := tools.Format(az, 0)
falt := tools.Format(alt, 0)
fta := tools.Format(ta/15, 1)
fmt.Printf("方位角: %s\n", faz)
fmt.Printf("高度角: %s\n", falt)
fmt.Printf("时角: %s\n", fta)
}
}

@ -1,6 +1,6 @@
module b612.me/apps/b612
go 1.20
go 1.21.2
require (
b612.me/bcap v0.0.4
@ -32,6 +32,7 @@ require (
github.com/spf13/cobra v1.8.0
github.com/things-go/go-socks5 v0.0.5
github.com/vbauerster/mpb/v8 v8.8.3
github.com/wayneashleyberry/terminal-dimensions v1.1.0
golang.org/x/crypto v0.26.0
golang.org/x/net v0.28.0
golang.org/x/sys v0.26.0
@ -39,6 +40,7 @@ require (
)
require (
b612.me/astro v0.0.4 // indirect
b612.me/win32api v0.0.2 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0 // indirect

@ -1,3 +1,7 @@
b612.me/astro v0.0.3 h1:MjZ6iAG28qEtZxzg1WFlTligu56b1O64hw1hl5wh/HI=
b612.me/astro v0.0.3/go.mod h1:yC1arIa79Q5ztQgWphj5mX5UvM/gddwTP+jGneojPt4=
b612.me/astro v0.0.4 h1:i60vJ3Dq+9U16ryMqmnjE0uXB28poRBx8boIMbP8VH8=
b612.me/astro v0.0.4/go.mod h1:yC1arIa79Q5ztQgWphj5mX5UvM/gddwTP+jGneojPt4=
b612.me/bcap v0.0.4 h1:iY2Oz+uyG/mue6a/dJiU82ci5Xwkj4xHhre/q0O8G60=
b612.me/bcap v0.0.4/go.mod h1:tpus+4iMpsnxb98Pck70s87Zt4sIWuRZjK23MmmzmoY=
b612.me/notify v0.0.0-20240818092352-85803f75dfa0 h1:PaLuNLMM0HBM7qPdk4igtNvqT2CDgdm52sL+KA9I3so=
@ -35,9 +39,11 @@ github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0/go.mod h1:okt5dMMTOFjX/aov
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/dns/armdns v1.1.0 h1:8iR6OLffWWorFdzL2JFCab5xpD8VKEE2DUBBl+HNTDY=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/dns/armdns v1.1.0/go.mod h1:copqlcjMWc/wgQ1N2fzsJFQxDdqKGg1EQt8T5wJMOGE=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2 h1:mLY+pNLjCUeKhgnAJWAKhEUQM+RJQo2H1fuGSw1Ky1E=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2/go.mod h1:FbdwsQ2EzwvXxOPcMFYO8ogEc9uMMIj3YkmCdXdAFmk=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/privatedns/armprivatedns v1.1.0 h1:rR8ZW79lE/ppfXTfiYSnMFv5EzmVuY4pfZWIkscIJ64=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/privatedns/armprivatedns v1.1.0/go.mod h1:y2zXtLSMM/X5Mfawq0lOftpWn3f4V6OCsRdINsvWBPI=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0 h1:ECsQtyERDVz3NP3kvDOTLvbQhqWp/x9EsGKtb4ogUr8=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0/go.mod h1:s1tW/At+xHqjNFvWU4G0c0Qv33KOhvbGNj0RCTQDV8s=
github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0 h1:OBhqkivkhkMqLPymWEppkm7vgPQY2XsHoEkaMQ0AdZY=
github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0/go.mod h1:kgDmCTgBzIEPFElEF+FK0SdjAor06dRq2Go927dnQ6o=
github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow=
@ -57,6 +63,7 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI=
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
github.com/ebitengine/purego v0.8.1 h1:sdRKd6plj7KYW33EH5As6YKfe8m9zbN9JMrOjNVF/BE=
github.com/ebitengine/purego v0.8.1/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
github.com/elazarl/goproxy v0.0.0-20231117061959-7cc037d33fb5 h1:m62nsMU279qRD9PQSWD1l66kmkXzuYcnVJqL4XLeV2M=
@ -68,6 +75,7 @@ github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21/go.mod h1:iL2twTe
github.com/emersion/go-smtp v0.20.2 h1:peX42Qnh5Q0q3vrAnRy43R/JwTnnv75AebxbkTL7Ia4=
github.com/emersion/go-smtp v0.20.2/go.mod h1:qm27SGYgoIPRot6ubfQ/GpiPy/g3PaZAVRxiO/sDUgQ=
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/florianl/go-nfqueue/v2 v2.0.0 h1:NTCxS9b0GSbHkWv1a7oOvZn679fsyDkaSkRvOYpQ9Oo=
github.com/florianl/go-nfqueue/v2 v2.0.0/go.mod h1:M2tBLIj62QpwqjwV0qfcjqGOqP3qiTuXr2uSRBXH9Qk=
github.com/go-acme/lego/v4 v4.16.1 h1:JxZ93s4KG0jL27rZ30UsIgxap6VGzKuREsSkkyzeoCQ=
@ -98,11 +106,14 @@ github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-hclog v1.2.0 h1:La19f8d7WIlm4ogzNHB0JGqs5AUDAZ2UfCY4sJXcJdM=
github.com/hashicorp/go-hclog v1.2.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/go-retryablehttp v0.7.5 h1:bJj+Pj19UZMIweq/iie+1u5YCdGrnxCT9yvm0e+Nd5M=
github.com/hashicorp/go-retryablehttp v0.7.5/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc=
@ -129,7 +140,9 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mdlayher/netlink v1.7.2 h1:/UtM3ofJap7Vl4QWCPDGXY8d3GIY2UGSDbK+QWmY8/g=
@ -170,6 +183,7 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.490 h1:mmz27tVi2r70JYnm5y0Zk8w0Qzsx+vfUw3oqSyrEfP8=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.490/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod v1.0.490 h1:g9SWTaTy/rEuhMErC2jWq9Qt5ci+jBYSvXnJsLq4adg=
@ -178,6 +192,8 @@ github.com/things-go/go-socks5 v0.0.5 h1:qvKaGcBkfDrUL33SchHN93srAmYGzb4CxSM2DPY
github.com/things-go/go-socks5 v0.0.5/go.mod h1:mtzInf8v5xmsBpHZVbIw2YQYhc4K0jRwzfsH64Uh0IQ=
github.com/vbauerster/mpb/v8 v8.8.3 h1:dTOByGoqwaTJYPubhVz3lO5O6MK553XVgUo33LdnNsQ=
github.com/vbauerster/mpb/v8 v8.8.3/go.mod h1:JfCCrtcMsJwP6ZwMn9e5LMnNyp3TVNpUWWkN+nd4EWk=
github.com/wayneashleyberry/terminal-dimensions v1.1.0 h1:EB7cIzBdsOzAgmhTUtTTQXBByuPheP/Zv1zL2BRPY6g=
github.com/wayneashleyberry/terminal-dimensions v1.1.0/go.mod h1:2lc/0eWCObmhRczn2SdGSQtgBooLUzIotkkEGXqghyg=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
@ -287,6 +303,7 @@ gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

@ -2,6 +2,7 @@ package main
import (
"b612.me/apps/b612/aes"
"b612.me/apps/b612/astro"
"b612.me/apps/b612/attach"
"b612.me/apps/b612/base64"
"b612.me/apps/b612/base85"
@ -54,7 +55,7 @@ func init() {
base64.Cmd, base85.Cmd, base91.Cmd, attach.Cmd, detach.Cmd, df.Cmd, dfinder.Cmd,
ftp.Cmd, generate.Cmd, hash.Cmd, image.Cmd, merge.Cmd, search.Cmd, split.Cmd, vic.Cmd,
calc.Cmd, net.Cmd, rmt.Cmds, rmt.Cmdc, keygen.Cmd, dns.Cmd, whois.Cmd, socks5.Cmd, httproxy.Cmd, smtpserver.Cmd, smtpclient.Cmd,
cert.Cmd, aes.Cmd, tls.Cmd, mget.Cmd, tcpkill.Cmd, tcm.Cmd)
cert.Cmd, aes.Cmd, tls.Cmd, mget.Cmd, tcpkill.Cmd, tcm.Cmd, astro.CmdCal, astro.Cmd)
}
func main() {

@ -0,0 +1,28 @@
package nmon
import (
"fmt"
"github.com/shirou/gopsutil/v4/cpu"
"time"
)
func Cpu() {
go func() {
flat, err := cpu.Percent(time.Second, false)
if err != nil {
return
}
fmt.Println(flat)
}()
flat, err := cpu.Percent(time.Second, true)
if err != nil {
return
}
c := 0.0000
for _, v := range flat {
c += v
}
fmt.Println(flat)
fmt.Println(c / float64(len(flat)))
time.Sleep(time.Millisecond * 200)
}

@ -0,0 +1,7 @@
package nmon
import "testing"
func TestCpu(t *testing.T) {
Cpu()
}
Loading…
Cancel
Save