diff --git a/Gemfile b/Gemfile index a8a4af7..c0bd89b 100644 --- a/Gemfile +++ b/Gemfile @@ -65,6 +65,8 @@ gem "image_processing", "~> 1.13" # gem "ruby-vips", "~> 2.2" gem "mini_magick", "~> 4.13.2" +gem 'devise', '~> 4.9' + group :development, :test do # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem gem "debug", platforms: %i[ mri windows ], require: "debug/prelude" diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc index 01154f0..45f9aeb 100644 --- a/config/credentials.yml.enc +++ b/config/credentials.yml.enc @@ -1 +1 @@ -zSnch4RlzPEpqZOE+TyBVBnHu+wyiNfNZoe1zi+cGNcgN/0BMw3xVQNIdu5ZgZzklukyimLlvkic7/G3PZE5aooqKIPeaGIgVKwdBvIGZYkTbrLTPtiA2Mx2iay4u6XI3eLDZZdy9g446GTngz9beQFR9s7dBbRBewOdIuCjA17seywsv722x97wHCv1xoGBeknK0DrEaYQcnECcy3G3esAsGeoKCQRMNHIf5/IbB6J+ZsoyOpnwtjOXdfEUnmtieLqvyw1xjgOxQTp2GMJk8zq+dGUBR3nIzplzccJbotppWfUbd9nxuT0stxWdFtKRPceynUfJ4awQNOmx+qGXi2/sYZH9lEB0nnyuKUpte6/bf1kcxcXyqTcsjaw0f9DXC3z9jx0pPbf2+O1MLZSFmo7Sr18mXjHVWjSCXnuYmWWkkuKESl4DwW5KScguWdnsf+/Y1eHds2MpE9dRLynlf5ONvFMY495iXuN4bR7UE5utAmU3imAg8vhErDqiro2L0GKMY5boMg+9NIObSlxwI6uAer8HaIKBVioiXGHFoFofR0LpmIKTbHiRF9ZZM3KCunsrQXAvRB4X7jL18JR08cDGGML2m03u9fcn9VuCYgcr+TLnsBozoG+ATP03kXc6lxkxjDvOc2z/AKqPmHUejCvsTLibFuEgw34E/NnVgcrC/Cggh/pp2Vmc6Yg2aQN7NcUmz0enGpzaTcnwiiB/8U8ig5WUovZP/iG3JH8S4KtBhDVz4hzz3FDOFBZC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InXUVx8GBtbE9K0dTAvcIS0mKH8+DY61R9HeJ46L7AX6BADOpug9ScjiE62owl7CR95M97V+B53muKVSXT9tnqsYYJqP3fVk8X264i97T2JxOKwAxPxoPljv9Y6nwH8ZlR7s1sPCviOQxZBssEkmTxiYjX9J0+S0T/q9M6NwYZn1weEjCPFZbwHltcXBTqPuvR0iUN+itUBTnDkS0F3CkF12JmfYWJSOAh3PR+sgEcrJszySxoGMEv3smUx7MgJ+eZWIkbXbx0JWzEf/UJIparRGYVP4GCerZ7EY6Q2HG4WkyR3v2A7Ityzv0jI/u3DDXoEIB/+tW7xaeSzTJjaLjO--wzTRxzkF39xx+3YB--yfEzFDCIT3kpIEDGL5skrQ== \ No newline at end of file diff --git a/config/database.yml b/config/database.yml index 2640cb5..5dd2ac0 100644 --- a/config/database.yml +++ b/config/database.yml @@ -11,7 +11,8 @@ default: &default development: <<: *default - database: storage/development.sqlite3 +# database: storage/development.sqlite3 + url: <%= Rails.application.credentials.db_dev.url %> # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". diff --git a/config/environments/production.rb b/config/environments/production.rb index 1d89d45..6bde9d3 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -59,7 +59,7 @@ Rails.application.configure do # config.action_mailer.raise_delivery_errors = false # Set host to be used by links generated in mailer templates. - config.action_mailer.default_url_options = { host: "example.com" } + config.action_mailer.default_url_options = { host: "todayaiweather.com" } # Specify outgoing SMTP server. Remember to add smtp/* credentials via rails credentials:edit. # config.action_mailer.smtp_settings = { diff --git a/db/schema.rb b/db/schema.rb index ce7a67c..0a3cab8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -18,9 +18,9 @@ ActiveRecord::Schema[8.0].define(version: 2025_02_08_052634) do t.string "namespace" t.text "body" t.string "resource_type" - t.bigint "resource_id" + t.integer "resource_id" t.string "author_type" - t.bigint "author_id" + t.integer "author_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["author_type", "author_id"], name: "index_active_admin_comments_on_author" @@ -69,8 +69,8 @@ ActiveRecord::Schema[8.0].define(version: 2025_02_08_052634) do end create_table "ahoy_events", force: :cascade do |t| - t.bigint "visit_id" - t.bigint "user_id" + t.integer "visit_id" + t.integer "user_id" t.string "name" t.text "properties" t.datetime "time" @@ -82,7 +82,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_02_08_052634) do create_table "ahoy_visits", force: :cascade do |t| t.string "visit_token" t.string "visitor_token" - t.bigint "user_id" + t.integer "user_id" t.string "ip" t.text "user_agent" t.text "referrer" @@ -120,12 +120,12 @@ ActiveRecord::Schema[8.0].define(version: 2025_02_08_052634) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "slug" - t.bigint "country_id", null: false + t.integer "country_id", null: false t.string "state_code" t.string "country_code" t.boolean "flag", default: true t.string "wiki_data_id" - t.bigint "state_id" + t.integer "state_id" t.index ["country_id"], name: "index_cities_on_country_id" t.index ["slug"], name: "index_cities_on_slug", unique: true t.index ["state_id"], name: "index_cities_on_state_id" @@ -135,7 +135,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_02_08_052634) do t.string "name" t.string "code" t.string "slug" - t.bigint "region_id" + t.integer "region_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "iso3" @@ -158,7 +158,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_02_08_052634) do t.string "emoji_u" t.boolean "flag", default: true t.string "wiki_data_id" - t.bigint "subregion_id" + t.integer "subregion_id" t.index ["code"], name: "index_countries_on_code", unique: true t.index ["region_id"], name: "index_countries_on_region_id" t.index ["slug"], name: "index_countries_on_slug", unique: true @@ -192,7 +192,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_02_08_052634) do create_table "states", force: :cascade do |t| t.string "name" t.string "code" - t.bigint "country_id" + t.integer "country_id" t.string "country_code" t.string "fips_code" t.string "iso2" @@ -211,7 +211,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_02_08_052634) do create_table "subregions", force: :cascade do |t| t.string "name", null: false t.text "translations" - t.bigint "region_id", null: false + t.integer "region_id", null: false t.boolean "flag", default: true t.string "wiki_data_id" t.datetime "created_at", null: false @@ -220,7 +220,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_02_08_052634) do end create_table "weather_arts", force: :cascade do |t| - t.bigint "city_id", null: false + t.integer "city_id", null: false t.date "weather_date" t.string "description" t.decimal "temperature" diff --git a/db/seeds.rb b/db/seeds.rb index 6779d9b..6f24725 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -10,64 +10,60 @@ # AdminUser.create!(email: 'admin@example.com', password: 'password', password_confirmation: 'password') if Rails.env.development? AdminUser.create!(email: 'admin@example.com', password: 'password', password_confirmation: 'password') -WeatherArt.delete_all -City.delete_all -Country.delete_all -Region.delete_all +# WeatherArt.delete_all +# City.delete_all +# Country.delete_all +# Region.delete_all # 创建区域 regions = Region.create!([ { name: 'Asia', code: 'AS' - }, - { - name: 'South Asia', - code: 'SA' - }, - { - name: 'Southeast Asia', - code: 'SEA' - }, - { - name: 'East Asia', - code: 'EA' - }, - { - name: 'Middle East', - code: 'ME' - }, - { - name: 'Africa', - code: 'AF' - }, - { - name: 'North Africa', - code: 'NA' - }, - { - name: 'Sub-Saharan Africa', - code: 'SSA' - }, - { - name: 'Europe', - code: 'EU' - }, - { - name: 'North America', - code: 'NAM' - }, - { - name: 'South America', - code: 'SAM' - }, - { - name: 'Central America', - code: 'CAM' - }, - { - name: 'Oceania', - code: 'OC' + # }, + # { + # name: 'Southeast Asia', + # code: 'SEA' + # }, + # { + # name: 'East Asia', + # code: 'EA' + # }, + # { + # name: 'Middle East', + # code: 'ME' + # }, + # { + # name: 'Africa', + # code: 'AF' + # }, + # { + # name: 'North Africa', + # code: 'NA' + # }, + # { + # name: 'Sub-Saharan Africa', + # code: 'SSA' + # }, + # { + # name: 'Europe', + # code: 'EU' + # }, + # { + # name: 'North America', + # code: 'NAM' + # }, + # { + # name: 'South America', + # code: 'SAM' + # }, + # { + # name: 'Central America', + # code: 'CAM' + # }, + # { + # name: 'Oceania', + # code: 'OC' } ]) asia = Region.find_by(code: 'AS') @@ -80,66 +76,106 @@ oceania = Region.find_by(code: 'OC') # 创建所有国家 Country.create!([ # East Asia - { name: 'China', code: 'CN', region: asia }, - { name: 'Japan', code: 'JP', region: asia }, - { name: 'South Korea', code: 'KR', region: asia }, - { name: 'Taiwan', code: 'TW', region: asia }, - { name: 'Hong Kong', code: 'HK', region: asia }, + { name: 'China', code: 'CN', region: asia } + # { name: 'Japan', code: 'JP', region: asia }, + # { name: 'South Korea', code: 'KR', region: asia }, + # { name: 'Taiwan', code: 'TW', region: asia }, + # { name: 'Hong Kong', code: 'HK', region: asia }, # South Asia - { name: 'India', code: 'IN', region: asia }, - { name: 'Pakistan', code: 'PK', region: asia }, - { name: 'Bangladesh', code: 'BD', region: asia }, + # { name: 'India', code: 'IN', region: asia }, + # { name: 'Pakistan', code: 'PK', region: asia }, + # { name: 'Bangladesh', code: 'BD', region: asia }, # Southeast Asia - { name: 'Indonesia', code: 'ID', region: asia }, - { name: 'Vietnam', code: 'VN', region: asia }, - { name: 'Thailand', code: 'TH', region: asia }, - { name: 'Myanmar', code: 'MM', region: asia }, - { name: 'Singapore', code: 'SG', region: asia }, + # { name: 'Indonesia', code: 'ID', region: asia }, + # { name: 'Vietnam', code: 'VN', region: asia }, + # { name: 'Thailand', code: 'TH', region: asia }, + # { name: 'Myanmar', code: 'MM', region: asia }, + # { name: 'Singapore', code: 'SG', region: asia }, # Middle East - { name: 'Turkey', code: 'TR', region: asia }, - { name: 'Iran', code: 'IR', region: asia }, - { name: 'Saudi Arabia', code: 'SA', region: asia }, - { name: 'Iraq', code: 'IQ', region: asia }, + # { name: 'Turkey', code: 'TR', region: asia }, + # { name: 'Iran', code: 'IR', region: asia }, + # { name: 'Saudi Arabia', code: 'SA', region: asia }, + # { name: 'Iraq', code: 'IQ', region: asia }, # Africa - { name: 'Nigeria', code: 'NG', region: africa }, - { name: 'Egypt', code: 'EG', region: africa }, - { name: 'Democratic Republic of the Congo', code: 'CD', region: africa }, - { name: 'Tanzania', code: 'TZ', region: africa }, - { name: 'South Africa', code: 'ZA', region: africa }, - { name: 'Kenya', code: 'KE', region: africa }, - { name: 'Angola', code: 'AO', region: africa }, - { name: 'Mali', code: 'ML', region: africa }, - { name: 'Ivory Coast', code: 'CI', region: africa }, + # { name: 'Nigeria', code: 'NG', region: africa }, + # { name: 'Egypt', code: 'EG', region: africa }, + # { name: 'Democratic Republic of the Congo', code: 'CD', region: africa }, + # { name: 'Tanzania', code: 'TZ', region: africa }, + # { name: 'South Africa', code: 'ZA', region: africa }, + # { name: 'Kenya', code: 'KE', region: africa }, + # { name: 'Angola', code: 'AO', region: africa }, + # { name: 'Mali', code: 'ML', region: africa }, + # { name: 'Ivory Coast', code: 'CI', region: africa }, # Europe - { name: 'Russia', code: 'RU', region: europe }, - { name: 'United Kingdom', code: 'GB', region: europe }, - { name: 'Germany', code: 'DE', region: europe }, - { name: 'France', code: 'FRA', region: europe }, + # { name: 'Russia', code: 'RU', region: europe }, + # { name: 'United Kingdom', code: 'GB', region: europe }, + # { name: 'Germany', code: 'DE', region: europe }, + # { name: 'France', code: 'FRA', region: europe }, # North America - { name: 'United States', code: 'US', region: north_america }, - { name: 'Mexico', code: 'MX', region: north_america }, - { name: 'Canada', code: 'CA', region: north_america }, + # { name: 'United States', code: 'US', region: north_america }, + # { name: 'Mexico', code: 'MX', region: north_america }, + # { name: 'Canada', code: 'CA', region: north_america }, # South America - { name: 'Brazil', code: 'BR', region: south_america }, - { name: 'Peru', code: 'PE', region: south_america }, - { name: 'Colombia', code: 'CO', region: south_america }, - { name: 'Chile', code: 'CL', region: south_america }, + # { name: 'Brazil', code: 'BR', region: south_america }, + # { name: 'Peru', code: 'PE', region: south_america }, + # { name: 'Colombia', code: 'CO', region: south_america }, + # { name: 'Chile', code: 'CL', region: south_america }, # Oceania - { name: 'Australia', code: 'AU', region: oceania } + # { name: 'Australia', code: 'AU', region: oceania } ]) # 创建城市 -Dir[Rails.root.join('db/seeds/cities/*.rb')].sort.each do |file| - require file -end +# Dir[Rails.root.join('db/seeds/cities/*.rb')].sort.each do |file| +# require file +# end +china = Country.find_by code: 'CN' +City.create!([ + { + name: 'Shanghai', + latitude: 31.2304, + longitude: 121.4737, + country: china, + timezone: 'Asia/Shanghai', + active: true, + priority: 100 + }, + { + name: 'Beijing', + latitude: 39.9042, + longitude: 116.4074, + country: china, + timezone: 'Asia/Shanghai', + active: true, + priority: 100 + }, + { + name: 'Shenzhen', + latitude: 22.5431, + longitude: 114.0579, + country: china, + timezone: 'Asia/Shanghai', + active: true, + priority: 100 + }, + { + name: 'Guangzhou', + latitude: 23.1291, + longitude: 113.2644, + country: china, + timezone: 'Asia/Shanghai', + active: true, + priority: 100 + } +]) + guangzhou = City.find_by name: 'Guangzhou' guangzhou_weather_art = WeatherArt.create!( diff --git a/lib/tasks/sync_geo_data.rake b/lib/tasks/sync_geo_data.rake index 5750bed..7df77df 100644 --- a/lib/tasks/sync_geo_data.rake +++ b/lib/tasks/sync_geo_data.rake @@ -22,11 +22,15 @@ namespace :geo do count = 1 regions.each do |data| - region = Region.find_or_create_by!(name: data["name"]) + region = Region.find_or_create_by!(id: data["id"]) do |r| + r.name = data["name"] + r.code = data["name"] + end puts "Sync Regions[#{count}/#{sum}]: [#{region.name}]" count += 1 region.update!( + name: data["name"], code: data["name"], translations: data["translations"], flag: data["flag"] || true, @@ -42,10 +46,12 @@ namespace :geo do count = 1 subregions.each do |data| - subregion = Subregion.find_or_create_by!(name: data["name"]) do |s| - s.region_id = data["region_id"] + region = Region.find_by!(id: data["region_id"]) + subregion = Subregion.find_or_create_by!(id: data["id"]) do |s| + s.name = data["name"] + s.region_id = region.id end - puts "Sync Subregions[#{count}/#{sum}]: [#{subregion.name}]" + puts "Sync Subregions[#{count}/#{sum}]: [#{subregion.name}] region:[#{region.name}]" count += 1 subregion.update!( @@ -131,6 +137,7 @@ namespace :geo do state = State.find_or_create_by!(name: data["name"]) do |s| s.country_id = country.id + s.country_code = country.code end state.update!(