Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] split events closes #90 #168

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
17 changes: 10 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,26 @@ test:
$(ROOT)/cmd/thetool/thetool: test
cd $(ROOT)/cmd/thetool && go build .

split: $(ROOT)/cmd/thetool/thetool
$(ROOT)/cmd/thetool/thetool -dir $(ROOT)/gregorian,$(ROOT)/hijri,$(ROOT)/jalali split -base event -dist $(ROOT)/events

generate: $(ROOT)/cmd/thetool/thetool
mkdir -p $(ROOT)/dist
$(ROOT)/cmd/thetool/thetool -dir $(ROOT)/gregorian,$(ROOT)/hijri,$(ROOT)/jalali generate -dist $(ROOT)/dist
$(ROOT)/cmd/thetool/thetool -dir $(ROOT)/events/gregorian,$(ROOT)/events/hijri,$(ROOT)/events/jalali generate -dist $(ROOT)/dist
# Make sure update something in dist, since travis looks for changes, and if the build only contains new file
# skips the deploy
date > $(ROOT)/dist/.build_at

validate: $(ROOT)/cmd/thetool/thetool
$(ROOT)/cmd/thetool/thetool -dir $(ROOT)/gregorian,$(ROOT)/hijri,$(ROOT)/jalali unique
$(ROOT)/cmd/thetool/thetool -dir $(ROOT)/gregorian,$(ROOT)/hijri,$(ROOT)/jalali validate
$(ROOT)/cmd/thetool/thetool -dir $(ROOT)/gregorian,$(ROOT)/hijri,$(ROOT)/jalali validate-links
$(ROOT)/cmd/thetool/thetool -dir $(ROOT)/events/gregorian,$(ROOT)/events/hijri,$(ROOT)/events/jalali unique
$(ROOT)/cmd/thetool/thetool -dir $(ROOT)/events/gregorian,$(ROOT)/events/hijri,$(ROOT)/events/jalali validate
$(ROOT)/cmd/thetool/thetool -dir $(ROOT)/events/gregorian,$(ROOT)/events/hijri,$(ROOT)/events/jalali validate-links

reorder-jalali: $(ROOT)/cmd/thetool/thetool
$(ROOT)/cmd/thetool/thetool -dir $(ROOT)/jalali reorder -output - > $(ROOT)/jalali.yaml
$(ROOT)/cmd/thetool/thetool -dir $(ROOT)/events/jalali reorder -output - > $(ROOT)/jalali.yaml

reorder-hijri: $(ROOT)/cmd/thetool/thetool
$(ROOT)/cmd/thetool/thetool -dir $(ROOT)/hijri reorder -output - > $(ROOT)/hijri.yaml
$(ROOT)/cmd/thetool/thetool -dir $(ROOT)/events/hijri reorder -output - > $(ROOT)/hijri.yaml

reorder-gregorian: $(ROOT)/cmd/thetool/thetool
$(ROOT)/cmd/thetool/thetool -dir $(ROOT)/gregorian reorder -output - > $(ROOT)/gregorian.yaml
$(ROOT)/cmd/thetool/thetool -dir $(ROOT)/events/gregorian reorder -output - > $(ROOT)/gregorian.yaml
33 changes: 15 additions & 18 deletions cmd/thetool/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,26 +91,23 @@ func (f *File) Merge(new *File) {
}

func openFolder(folder string) ([]string, error) {
fl, err := ioutil.ReadDir(folder)
if err != nil {
return nil, err
}

var ret = make([]string, 0, len(fl))
for i := range fl {
if fl[i].IsDir() {
continue
}
var ret = make([]string, 0)

full := filepath.Join(folder, fl[i].Name())
if ext := filepath.Ext(full); ext != ".yml" {
continue
}

ret = append(ret, full)
}

return ret, nil
return ret, filepath.Walk(folder,
func(path string, fi os.FileInfo, err error) error {
if fi.IsDir() {
return nil
}

//full := filepath.Join(folder, fi.Name())
if ext := filepath.Ext(path); ext != ".yml" {
return nil
}

ret = append(ret, path)
return nil
})
}

func loadFolder(folder string) (*File, error) {
Expand Down
71 changes: 69 additions & 2 deletions cmd/thetool/split.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@ import (
"io/ioutil"
"os"
"path/filepath"
"sort"
"strings"

"gopkg.in/yaml.v2"
)

var target *string
var (
target *string
base *string
)

func split(cmd *command, fls []*File) error {
func monthBase(fls []*File) error {
for _, fl := range fls {
ev := make([][]Event, len(fl.Months.Normal))
for i := range fl.Events {
fl.Events[i].Key = 0
ev[fl.Events[i].Month-1] = append(ev[fl.Events[i].Month-1], fl.Events[i])
}

Expand Down Expand Up @@ -47,9 +52,71 @@ func split(cmd *command, fls []*File) error {
return nil
}

func eventBase(fls []*File) error {
for _, fl := range fls {
sort.Sort(fl)
evs := make(map[string][]Event)
for i := range fl.Events {
fl.Events[i].Key = 0
k := fmt.Sprintf("%02d%02d", fl.Events[i].Month, fl.Events[i].Day)
if _, ok := evs[k]; ok {
evs[k] = append(evs[k], fl.Events[i])
} else {
evs[k] = []Event{fl.Events[i]}
}
}



for k, v := range evs {
name := strings.ToLower(filepath.Join(*target,
fl.Name,
fmt.Sprintf("%02d-%s", v[0].Month, fl.Months.Name[v[0].Month-1]["en_US"]),
fmt.Sprintf("%s.yml", k[2:])))
b, err := yaml.Marshal(File{
Events: v,
})
if err != nil {
return err
}
os.MkdirAll(strings.ToLower(filepath.Join(*target,
fl.Name,
fmt.Sprintf("%02d-%s", v[0].Month, fl.Months.Name[v[0].Month-1]["en_US"]))), os.ModePerm)

if err := ioutil.WriteFile(name, b, 0600); err != nil {
return err
}
}

fl.Events = nil
name := strings.ToLower(filepath.Join(*target,fl.Name, "preset.yml"))
b, err := yaml.Marshal(fl)
if err != nil {
return err
}
if err := ioutil.WriteFile(name, b, 0600); err != nil {
return err
}
}

return nil
}

func split(cmd *command, fls []*File) error {
switch *base {
case "month":
return monthBase(fls)
case "event":
return eventBase(fls)
default:
return fmt.Errorf("the %q is not valid value for -base", *base)
}
}

func init() {
cur, _ := os.Getwd()
cmd := newCommand("split", "split one year based on the months", split)
target = cmd.Flags.String("dist", cur, "The dist folder")
base = cmd.Flags.String("base", cur, `The base of split. valid values are "month" and "event" `)
registerCommand(cmd)
}
17 changes: 17 additions & 0 deletions events/gregorian/02-feburary/04.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
events:
- partial_key: world_cancer_day
title:
en_US: world cancer day
fa_IR: روز جهانی سرطان
description:
en_US: World Cancer Day is an international day marked on February 4 to raise
awareness of cancer and to encourage its prevention, detection, and treatment.
fa_IR: روز جهانی سرطان روز جهانی است که در تاریخ 4 فوریه برای افزایش آگاهی از
سرطان و ترغیب به پیشگیری ، تشخیص و درمان آن مشخص شده است.
year: 2000
month: 2
day: 4
calendar:
- International
sources:
- https://en.wikipedia.org/wiki/World_Cancer_Day
21 changes: 21 additions & 0 deletions events/gregorian/02-feburary/06.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
events:
- partial_key: international_day_of_zero_tolerance_to_female_genital_mutilation
title:
en_US: International Day of Zero Tolerance for Female Genital Mutilation
fa_IR: روز جهانی عدم هرگونه مدارا با مثله‌کردن جنسی زنان
description:
en_US: International Day of Zero Tolerance for Female Genital Mutilation is a
United Nations-sponsored annual awareness day that takes place on February 6
as part of the UN's efforts to eradicate female genital mutilation. It was first
introduced in 2003.
fa_IR: روز بین‌المللی عدم هرگونه مدارا با مثله‌کردن جنسی زنان یکی از روزهای آگاهی
دهنده بین‌المللی مورد حمایت سازمان ملل است که برای ۶ فوریه هر سال انتخاب شده
و به مبارزه با بریدن آلت تناسلی زنان (ختنه زنان) اختصاص دارد.
year: 2003
month: 2
day: 6
calendar:
- International
sources:
- https://fa.wikipedia.org/wiki/روز_جهانی_عدم_هرگونه_مدارا_با_مثله‌کردن_جنسی_زنان
- https://en.wikipedia.org/wiki/International_Day_of_Zero_Tolerance_for_Female_Genital_Mutilation
19 changes: 19 additions & 0 deletions events/gregorian/02-feburary/10.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
events:
- partial_key: world_pulses_day
title:
en_US: World Pulses Day
fa_IR: روز جهانی حبوبات
description:
en_US: World Pulses Day is a day established by the Food and Agriculture Organization
(FAO) of the United Nations to recognize the importance of pulses (dry beans,
lentils, dry peas, chickpeas, lupins) as a global food.
fa_IR: روز جهانی پالس روزی است که توسط سازمان غذا و کشاورزی (FAO) سازمان ملل متحد
برای شناخت اهمیت حبوبات (لوبیا خشک ، عدس ، نخود خشک ، نخود ، لپین) به عنوان
یک ماده غذایی جهانی تأسیس شده است.
year: 2018
month: 2
day: 10
calendar:
- International
sources:
- https://en.wikipedia.org/wiki/World_Pulses_Day
21 changes: 21 additions & 0 deletions events/gregorian/02-feburary/11.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
events:
- partial_key: international_day_of_women_and_girls_in_science
title:
en_US: International Day of Women and Girls in Science
fa_IR: روز جهانی زنان و دختران در علم
description:
en_US: In order to achieve full and equal access to and participation in science
for women and girls, and further achieve gender equality and the empowerment
of women and girls, the United Nations General Assembly adopted resolution A/RES/70/212
declaring 11 February as the International Day of Women and Girls in Science.
fa_IR: به منظور دستیابی کامل و مساوی به مشارکت و مشارکت در علم زنان و دختران و
دستیابی بیشتر به برابری جنسیتی و توانمندسازی زنان و دختران ، مجمع عمومی سازمان
ملل متحد قطعنامه A / RES / 70/212 را تصویب کرد که 11 فوریه را به عنوان روز جهانی
زن و دختر در علم اعلام کرد.
year: 2015
month: 2
day: 11
calendar:
- International
sources:
- https://undocs.org/A/RES/70/212
21 changes: 21 additions & 0 deletions events/gregorian/02-feburary/13.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
events:
- partial_key: world_radio_day
title:
en_US: World Radio Day
fa_IR: روز جهانی رادیو
description:
en_US: Following a request from the Spanish Radio Academy on 20 September 2010,
Spain proposed that the UNESCO Executive Board include an agenda item on the
proclamation of a World Radio Day. UNESCO's Executive Board approved the agenda
item in its provisional agenda for the proclamation of a "World Radio Day" on
29 September 2011.
fa_IR: روز جهانی رادیو یک رویداد سالانه است که در ۱۳ فوریه، برگزار می‌شود. این
روز توسط یونسکو نامگذاری شده است.
year: 2012
month: 2
day: 13
calendar:
- International
sources:
- https://fa.wikipedia.org/wiki/روز_جهانی_رادیو
- https://en.wikipedia.org/wiki/World_Radio_Day
21 changes: 21 additions & 0 deletions events/gregorian/02-feburary/20.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
events:
- partial_key: world_day_of_social_justice
title:
en_US: World Day of Social Justice
fa_IR: روز جهانی عدالت اجتماعی
description:
en_US: Social Equality Justice day is a day recognizing the need to promote efforts
to tackle issues such as poverty, exclusion and unemployment. Many organizations,
including the UN, American Library Association (ALA), and the International
Labour Office, make statements on the importance of social justice for people.
fa_IR: روز عدالت اجتماعی روزی است که نیاز به ترویج تلاش برای مقابله با موضوعاتی
از جمله فقر ، محرومیت و بیکاری است. بسیاری از سازمانها از جمله سازمان ملل متحد
، انجمن كتابخانه های آمریكا (ALA) و دفتر بین المللی كار در مورد اهمیت عدالت
اجتماعی برای مردم بیانیه می دهند.
year: 2007
month: 2
day: 20
calendar:
- International
sources:
- https://en.wikipedia.org/wiki/World_Day_of_Social_Justice
22 changes: 22 additions & 0 deletions events/gregorian/02-feburary/21.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
events:
- partial_key: international_mother_language_day
title:
en_US: International Mother Language Day
fa_IR: روز جهانی زبان مادری
description:
en_US: International Mother Language Day (IMLD) is a worldwide annual observance
held on 21 February to promote awareness of linguistic and cultural diversity
and promote multilingualism. First announced by UNESCO on 17 November 1999,
it was formally recognized by the United Nations General Assembly in a resolution
establishing 2008 as the International Year of Languages
fa_IR: نامگذاری این روز در کنفرانس عمومی یونسکو در سال ۱۹۹۹ به منظور کمک به تنوع
زبانی و فرهنگی انجام شده‌است. مجمع عمومی سازمان ملل متحد نیز به دلیل اهمیت زیاد
آن، سال ۲۰۰۸ را سال جهانی زبان‌ها اعلام کرد.
year: 2002
month: 2
day: 21
calendar:
- International
sources:
- https://fa.wikipedia.org/wiki/روز_جهانی_زبان_مادری
- https://en.wikipedia.org/wiki/International_Mother_Language_Day
22 changes: 22 additions & 0 deletions events/gregorian/04-april/02.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
events:
- partial_key: world_autism_awareness_day
title:
en_US: World Autism Awareness Day
fa_IR: روز آگاهی جهانی اوتیسم
description:
en_US: World Autism Awareness Day is an internationally recognized day on 2 April
every year, encouraging Member States of the United Nations to take measures
to raise awareness about people with Autism Spectrum Disorder (ASD) throughout
the world.
fa_IR: .روز آگاهی جهانی اوتیسم روز دوم آوریل هر سال است که به عنوان یک روز جهانی
به رسمیت شناخته شده است و هدف آن یادآوری و ترغیب کنش های کشورهای عضو در سازمان
ملل متحد در جهت افزایش آگاهی در مورد افراد مبتلا به اختلال اسپکتروم اوتیسم در
سراسر جهان است
year: 2007
month: 4
day: 2
calendar:
- International
sources:
- https://fa.wikipedia.org/wiki/روز_آگاهی_جهانی_اوتیسم
- https://en.wikipedia.org/wiki/World_Autism_Awareness_Day
21 changes: 21 additions & 0 deletions events/gregorian/04-april/06.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
events:
- partial_key: international_day_of_sport_for_development_and_peace
title:
en_US: International Day of Sport for Development and Peace
fa_IR: روز جهانی ورزش برای صلح و توسعه
description:
en_US: The International Day of Sport for Development and Peace (IDSDP) is an
annual celebration of the power of sport to drive social change, community development
and to foster peace and understanding.
fa_IR: .روز جهانی ورزش برای صلح و توسعه در روز 6 آوریل توسط سازمان ملل متحد نامگزاری
شد.روز ششم آوریل در واقع آغازگر نخستین دوره بازی های المپیک تابستانی مدرن در
سال 1896 به میزبانی یونان بوده و همین علت این روز به عنوان روز ورزش در خدمت
صلح و توسعه نام گذاری شده است
year: 2014
month: 4
day: 6
calendar:
- International
sources:
- https://fa.wikipedia.org/wiki/روز_جهانی_ورزش_برای_صلح_و_توسعه
- https://en.wikipedia.org/wiki/International_Day_of_Sport_for_Development_and_Peace
20 changes: 20 additions & 0 deletions events/gregorian/04-april/07.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
events:
- partial_key: world_health_day
title:
en_US: World Health Day
fa_IR: روز جهانی بهداشت
description:
en_US: The World Health Day is a global health awareness day celebrated every
year on 7 April, under the sponsorship of the World Health Organization (WHO),
as well as other related organizations.
fa_IR: .روز جهانی بهداشت سالروز مقارن هفتم آوریل است که تحت حمایت سازمان بهداشت
جهانی قرار دارد و همه ساله در این روز تحت نظارت مجمع بهداشت جهانی و دیگر سازمان
های مرتبط جشن گرفته می شود
year: 1950
month: 4
day: 7
calendar:
- International
sources:
- https://fa.wikipedia.org/wiki/روز_جهانی_بهداشت
- https://en.wikipedia.org/wiki/World_Health_Day
Loading