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

Feature/subregions #668

Merged
merged 2 commits into from
Sep 3, 2023
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions scripts/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require_once 'vendor/base.php';

$r = 0; // regions
$s = 0; // suberegions
$i = 0; // states && states-cities
$j = 0; // cities
$k = 0; // countries-states-cities && countries-states
Expand All @@ -16,6 +17,7 @@
$countryCityArray = array();
$countryStateCityArray = array();
$regionsArray = array();
$subregionsArray = array();
$stateNamesArray = array();
$cityNamesArray = array();

Expand Down Expand Up @@ -185,7 +187,9 @@
$countryStateArray[$k]['tld'] = $country['tld'];
$countryStateArray[$k]['native'] = $country['native'];
$countryStateArray[$k]['region'] = $country['region'];
$countryStateArray[$k]['region_id'] = $country['region_id'];
$countryStateArray[$k]['subregion'] = $country['subregion'];
$countryStateArray[$k]['subregion_id'] = $country['subregion_id'];
$countryStateArray[$k]['nationality'] = $country['nationality'];
$countryStateArray[$k]['timezones'] = $country['timezones'];
$countryStateArray[$k]['translations'] = $country['translations'];
Expand Down Expand Up @@ -227,13 +231,31 @@
$regionsArray[$r]['id'] = (int)$row['id'];
$regionsArray[$r]['name'] = $row['name'];
$regionsArray[$r]['translations'] = json_decode($row['translations'], true);
$regionsArray[$r]['wikiDataId'] = $row['wikiDataId'];

$r++;
}
}

// Fetching All Subregions
$sql = "SELECT * FROM subregions ORDER BY name";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
// Pushing it into Fresh Array
$subregionsArray[$s]['id'] = (int)$row['id'];
$subregionsArray[$s]['name'] = $row['name'];
$subregionsArray[$s]['region_id'] = $row['region_id'];
$subregionsArray[$s]['translations'] = json_decode($row['translations'], true);
$subregionsArray[$s]['wikiDataId'] = $row['wikiDataId'];
$s++;
}
}



echo 'Total Regions Count : '.count($regionsArray).PHP_EOL;
echo 'Total Subregions Count : '.count($subregionsArray).PHP_EOL;
echo 'Total Countries Count : '.count($countriesArray).PHP_EOL;
echo 'Total States Count : '.count($statesArray).PHP_EOL;
echo 'Total Cities Count : '.count($citiesArray).PHP_EOL;
Expand Down Expand Up @@ -294,6 +316,13 @@
echo 'JSON Exported to ' .$exportTo . PHP_EOL;
fclose($fp);

// print_r($subregionsArray);
$exportTo = $rootDir . '/subregions.json';
$fp = fopen($exportTo, 'w'); // Putting Array to JSON
fwrite($fp, json_encode($subregionsArray, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT).PHP_EOL);
echo 'JSON Exported to ' .$exportTo . PHP_EOL;
fclose($fp);

// | JSON_ERROR_UTF8|JSON_ERROR_UTF16|JSON_THROW_ON_ERROR|JSON_ERROR_DEPTH

$conn->close();
Expand Down
81 changes: 81 additions & 0 deletions sql/subregions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# ************************************************************
# Sequel Ace SQL dump
# Version 20050
#
# https://sequel-ace.com/
# https://github.com/Sequel-Ace/Sequel-Ace
#
# Host: localhost (MySQL 8.0.30)
# Database: bucketlist
# Generation Time: 2023-08-11 17:25:54 +0000
# ************************************************************


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
SET NAMES utf8mb4;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE='NO_AUTO_VALUE_ON_ZERO', SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;


DROP TABLE IF EXISTS `subregions`;

CREATE TABLE `subregions` (
`id` mediumint unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`translations` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
`region_id` mediumint unsigned NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`flag` tinyint(1) NOT NULL DEFAULT '1',
`wikiDataId` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Rapid API GeoDB Cities',
PRIMARY KEY (`id`),
KEY `subregion_continent` (`region_id`),
CONSTRAINT `subregion_continent_final` FOREIGN KEY (`region_id`) REFERENCES `regions` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=251 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


/*!40000 ALTER TABLE `regions` DISABLE KEYS */;

INSERT INTO `subregions` (`id`, `name`, `translations`, `region_id`, `created_at`, `updated_at`, `flag`, `wikiDataId`)
VALUES
(1,'Northern Africa','{\"kr\":\"북아프리카\",\"pt-BR\":\"Norte de África\",\"pt\":\"Norte de África\",\"nl\":\"Noord-Afrika\",\"hr\":\"Észak-Afrika\",\"fa\":\"شمال آفریقا\",\"de\":\"Nordafrika\",\"es\":\"Norte de África\",\"fr\":\"Afrique du Nord\",\"ja\":\"北アフリカ\",\"it\":\"Nordafrica\",\"cn\":\"北非\",\"tr\":\"Kuzey Afrika\"}',1 ,'2023-08-14 07:11:03','2023-08-14 07:11:03',1,'Q27381'),
(2,'Middle Africa','{\"kr\":\"아프리카\",\"pt-BR\":\"África\",\"pt\":\"África\",\"nl\":\"Afrika\",\"hr\":\"Afrika\",\"fa\":\"آفریقا\",\"de\":\"Afrika\",\"es\":\"África\",\"fr\":\"Afrique\",\"ja\":\"アフリカ\",\"it\":\"Africa\",\"cn\":\"非洲\",\"tr\":\"Afrika\"}',1 ,'2023-08-14 07:11:03','2023-08-14 07:11:03',1,'Q15'),
(3,'Western Africa','{\"kr\":\"아프리카\",\"pt-BR\":\"África\",\"pt\":\"África\",\"nl\":\"Afrika\",\"hr\":\"Afrika\",\"fa\":\"آفریقا\",\"de\":\"Afrika\",\"es\":\"África\",\"fr\":\"Afrique\",\"ja\":\"アフリカ\",\"it\":\"Africa\",\"cn\":\"非洲\",\"tr\":\"Afrika\"}',1 ,'2023-08-14 07:11:03','2023-08-14 07:11:03',1,'Q15'),
(4,'Eastern Africa','{\"kr\":\"아프리카\",\"pt-BR\":\"África\",\"pt\":\"África\",\"nl\":\"Afrika\",\"hr\":\"Afrika\",\"fa\":\"آفریقا\",\"de\":\"Afrika\",\"es\":\"África\",\"fr\":\"Afrique\",\"ja\":\"アフリカ\",\"it\":\"Africa\",\"cn\":\"非洲\",\"tr\":\"Afrika\"}',1 ,'2023-08-14 07:11:03','2023-08-14 07:11:03',1,'Q15'),
(5,'Southern Africa','{\"kr\":\"아프리카\",\"pt-BR\":\"África\",\"pt\":\"África\",\"nl\":\"Afrika\",\"hr\":\"Afrika\",\"fa\":\"آفریقا\",\"de\":\"Afrika\",\"es\":\"África\",\"fr\":\"Afrique\",\"ja\":\"アフリカ\",\"it\":\"Africa\",\"cn\":\"非洲\",\"tr\":\"Afrika\"}',1 ,'2023-08-14 07:11:03','2023-08-14 07:11:03',1,'Q15'),

(6,'Northern America','{\"kr\":\"아메리카\",\"pt-BR\":\"América\",\"pt\":\"América\",\"nl\":\"Amerika\",\"hr\":\"Amerika\",\"fa\":\"قاره آمریکا\",\"de\":\"Amerika\",\"es\":\"América\",\"fr\":\"Amérique\",\"ja\":\"アメリカ州\",\"it\":\"America\",\"cn\":\"美洲\",\"tr\":\"Amerika\"}',2 ,'2023-08-14 07:11:03','2023-08-14 07:11:03',1,'Q828'),
(7,'Caribbean','{\"kr\":\"아메리카\",\"pt-BR\":\"América\",\"pt\":\"América\",\"nl\":\"Amerika\",\"hr\":\"Amerika\",\"fa\":\"قاره آمریکا\",\"de\":\"Amerika\",\"es\":\"América\",\"fr\":\"Amérique\",\"ja\":\"アメリカ州\",\"it\":\"America\",\"cn\":\"美洲\",\"tr\":\"Amerika\"}',2 ,'2023-08-14 07:11:03','2023-08-14 07:11:03',1,'Q828'),
(8,'South America','{\"kr\":\"아메리카\",\"pt-BR\":\"América\",\"pt\":\"América\",\"nl\":\"Amerika\",\"hr\":\"Amerika\",\"fa\":\"قاره آمریکا\",\"de\":\"Amerika\",\"es\":\"América\",\"fr\":\"Amérique\",\"ja\":\"アメリカ州\",\"it\":\"America\",\"cn\":\"美洲\",\"tr\":\"Amerika\"}',2 ,'2023-08-14 07:11:03','2023-08-14 07:11:03',1,'Q828'),
(9,'Central America','{\"kr\":\"아메리카\",\"pt-BR\":\"América\",\"pt\":\"América\",\"nl\":\"Amerika\",\"hr\":\"Amerika\",\"fa\":\"قاره آمریکا\",\"de\":\"Amerika\",\"es\":\"América\",\"fr\":\"Amérique\",\"ja\":\"アメリカ州\",\"it\":\"America\",\"cn\":\"美洲\",\"tr\":\"Amerika\"}',2 ,'2023-08-14 07:11:03','2023-08-14 07:11:03',1,'Q828'),

(10,'Central Asia','{\"kr\":\"아메리카\",\"pt-BR\":\"América\",\"pt\":\"América\",\"nl\":\"Amerika\",\"hr\":\"Amerika\",\"fa\":\"قاره آمریکا\",\"de\":\"Amerika\",\"es\":\"América\",\"fr\":\"Amérique\",\"ja\":\"アメリカ州\",\"it\":\"America\",\"cn\":\"美洲\",\"tr\":\"Amerika\"}',3 ,'2023-08-14 07:11:03','2023-08-14 07:11:03',1,'Q828'),
(11,'Western Asia','{\"kr\":\"아메리카\",\"pt-BR\":\"América\",\"pt\":\"América\",\"nl\":\"Amerika\",\"hr\":\"Amerika\",\"fa\":\"قاره آمریکا\",\"de\":\"Amerika\",\"es\":\"América\",\"fr\":\"Amérique\",\"ja\":\"アメリカ州\",\"it\":\"America\",\"cn\":\"美洲\",\"tr\":\"Amerika\"}',3 ,'2023-08-14 07:11:03','2023-08-14 07:11:03',1,'Q828'),
(12,'Eastern Asia','{\"kr\":\"아메리카\",\"pt-BR\":\"América\",\"pt\":\"América\",\"nl\":\"Amerika\",\"hr\":\"Amerika\",\"fa\":\"قاره آمریکا\",\"de\":\"Amerika\",\"es\":\"América\",\"fr\":\"Amérique\",\"ja\":\"アメリカ州\",\"it\":\"America\",\"cn\":\"美洲\",\"tr\":\"Amerika\"}',3 ,'2023-08-14 07:11:03','2023-08-14 07:11:03',1,'Q828'),
(13,'South-Eastern Asia','{\"kr\":\"아메리카\",\"pt-BR\":\"América\",\"pt\":\"América\",\"nl\":\"Amerika\",\"hr\":\"Amerika\",\"fa\":\"قاره آمریکا\",\"de\":\"Amerika\",\"es\":\"América\",\"fr\":\"Amérique\",\"ja\":\"アメリカ州\",\"it\":\"America\",\"cn\":\"美洲\",\"tr\":\"Amerika\"}',3 ,'2023-08-14 07:11:03','2023-08-14 07:11:03',1,'Q828'),
(14,'Southern Asia','{\"kr\":\"아메리카\",\"pt-BR\":\"América\",\"pt\":\"América\",\"nl\":\"Amerika\",\"hr\":\"Amerika\",\"fa\":\"قاره آمریکا\",\"de\":\"Amerika\",\"es\":\"América\",\"fr\":\"Amérique\",\"ja\":\"アメリカ州\",\"it\":\"America\",\"cn\":\"美洲\",\"tr\":\"Amerika\"}',3 ,'2023-08-14 07:11:03','2023-08-14 07:11:03',1,'Q828'),

(15,'Eastern Europe','{\"kr\":\"아시아\",\"pt-BR\":\"Ásia\",\"pt\":\"Ásia\",\"nl\":\"Azië\",\"hr\":\"Ázsia\",\"fa\":\"آسیا\",\"de\":\"Asien\",\"es\":\"Asia\",\"fr\":\"Asie\",\"ja\":\"アジア\",\"it\":\"Asia\",\"cn\":\"亚洲\",\"tr\":\"Asya\"}',4 ,'2023-08-14 07:11:03','2023-08-14 07:11:03',1,'Q48'),
(16,'Southern Europe','{\"kr\":\"아시아\",\"pt-BR\":\"Ásia\",\"pt\":\"Ásia\",\"nl\":\"Azië\",\"hr\":\"Ázsia\",\"fa\":\"آسیا\",\"de\":\"Asien\",\"es\":\"Asia\",\"fr\":\"Asie\",\"ja\":\"アジア\",\"it\":\"Asia\",\"cn\":\"亚洲\",\"tr\":\"Asya\"}',4 ,'2023-08-14 07:11:03','2023-08-14 07:11:03',1,'Q48'),
(17,'Western Europe','{\"kr\":\"아시아\",\"pt-BR\":\"Ásia\",\"pt\":\"Ásia\",\"nl\":\"Azië\",\"hr\":\"Ázsia\",\"fa\":\"آسیا\",\"de\":\"Asien\",\"es\":\"Asia\",\"fr\":\"Asie\",\"ja\":\"アジア\",\"it\":\"Asia\",\"cn\":\"亚洲\",\"tr\":\"Asya\"}',4 ,'2023-08-14 07:11:03','2023-08-14 07:11:03',1,'Q48'),
(18,'Northern Europe','{\"kr\":\"아시아\",\"pt-BR\":\"Ásia\",\"pt\":\"Ásia\",\"nl\":\"Azië\",\"hr\":\"Ázsia\",\"fa\":\"آسیا\",\"de\":\"Asien\",\"es\":\"Asia\",\"fr\":\"Asie\",\"ja\":\"アジア\",\"it\":\"Asia\",\"cn\":\"亚洲\",\"tr\":\"Asya\"}',4 ,'2023-08-14 07:11:03','2023-08-14 07:11:03',1,'Q48'),

(19,'Australia and New Zealand','{\"kr\":\"유럽\",\"pt-BR\":\"Europa\",\"pt\":\"Europa\",\"nl\":\"Europa\",\"hr\":\"Európa\",\"fa\":\"اروپا\",\"de\":\"Europa\",\"es\":\"Europa\",\"fr\":\"Europe\",\"ja\":\"ヨーロッパ\",\"it\":\"Europa\",\"cn\":\"欧洲\",\"tr\":\"Avrupa\"}',5,'2023-08-14 07:11:03','2023-08-14 07:11:03',1,'Q46'),
(20,'Melanesia','{\"kr\":\"유럽\",\"pt-BR\":\"Europa\",\"pt\":\"Europa\",\"nl\":\"Europa\",\"hr\":\"Európa\",\"fa\":\"اروپا\",\"de\":\"Europa\",\"es\":\"Europa\",\"fr\":\"Europe\",\"ja\":\"ヨーロッパ\",\"it\":\"Europa\",\"cn\":\"欧洲\",\"tr\":\"Avrupa\"}',5,'2023-08-14 07:11:03','2023-08-14 07:11:03',1,'Q46'),
(21,'Micronesia','{\"kr\":\"오세아니아\",\"pt-BR\":\"Oceania\",\"pt\":\"Oceania\",\"nl\":\"Oceanië en Australië\",\"hr\":\"Óceánia és Ausztrália\",\"fa\":\"اقیانوسیه\",\"de\":\"Ozeanien und Australien\",\"es\":\"Oceanía\",\"fr\":\"Océanie\",\"ja\":\"オセアニア\",\"it\":\"Oceania\",\"cn\":\"大洋洲\",\"tr\":\"Okyanusya\"}',5,'2023-08-14 07:11:03','2023-08-14 07:11:03',1,'Q55643'),
(22,'Polynesia','{\"kr\":\"유럽\",\"pt-BR\":\"Europa\",\"pt\":\"Europa\",\"nl\":\"Europa\",\"hr\":\"Európa\",\"fa\":\"اروپا\",\"de\":\"Europa\",\"es\":\"Europa\",\"fr\":\"Europe\",\"ja\":\"ヨーロッパ\",\"it\":\"Europa\",\"cn\":\"欧洲\",\"tr\":\"Avrupa\"}',5,'2023-08-14 07:11:03','2023-08-14 07:11:03',1,'Q46');



/*!40000 ALTER TABLE `regions` ENABLE KEYS */;
UNLOCK TABLES;

/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Loading