Skip to content

Commit

Permalink
add: regions database table (#657)
Browse files Browse the repository at this point in the history
  • Loading branch information
Freelenzer authored Sep 2, 2023
1 parent 0a66f3a commit 83d39f2
Show file tree
Hide file tree
Showing 9 changed files with 401 additions and 273 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Country+State+Cities/World | :white_check_mark: | :white_check_mark: | :white_c
https://dr5hn.github.io/countries-states-cities-database/

## Insights
Total Regions : 6 <br>
Total Countries : 250 <br>
Total States/Regions/Municipalities : 5,081 <br>
Total Cities/Towns/Districts : 150,541 <br>
Expand Down
24 changes: 24 additions & 0 deletions scripts/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
$countryStateArray = array();
$countryCityArray = array();
$countryStateCityArray = array();
$regionsArray = array();
$stateNamesArray = array();
$cityNamesArray = array();

Expand Down Expand Up @@ -216,9 +217,25 @@

}

// Fetching All Regions
$sql = "SELECT * FROM regions ORDER BY name";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
// Pushing it into Fresh Array
$regionsArray[$m]['id'] = (int)$row['id'];
$regionsArray[$m]['name'] = $row['name'];
$regionsArray[$m]['translations'] = json_decode($row['translations'], true);

$m++;
}
}


echo 'Total Countries Count : '.count($countriesArray).PHP_EOL;
echo 'Total States Count : '.count($statesArray).PHP_EOL;
echo 'Total Cities Count : '.count($citiesArray).PHP_EOL;
echo 'Total Regions Count : '.count($regionsArray).PHP_EOL;

// print_r($countriesArray);
$exportTo = $rootDir . '/countries.json';
Expand Down Expand Up @@ -269,6 +286,13 @@
echo 'JSON Exported to ' .$exportTo . PHP_EOL;
fclose($fp);

// print_r($regionsArray);
$exportTo = $rootDir . '/regions.json';
$fp = fopen($exportTo, 'w'); // Putting Array to JSON
fwrite($fp, json_encode($regionsArray, 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
4 changes: 4 additions & 0 deletions scripts/export_csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
'from' => '/cities.json',
'to' => '/csv/cities.csv',
),
'regions' => array(
'from' => '/regions.json',
'to' => '/csv/regions.csv',
),
);

foreach ($files as $root => $v) :
Expand Down
1 change: 1 addition & 0 deletions scripts/export_plist.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os

files = [
'./csv/regions.csv',
'./csv/countries.csv',
'./csv/states.csv',
'./csv/cities.csv',
Expand Down
5 changes: 5 additions & 0 deletions scripts/export_xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

$rootDir = dirname(dirname(__FILE__));
$files = array(
'regions' => array(
'from' => '/regions.json',
'to' => '/xml/regions.xml',
'singular' => 'region',
),
'countries' => array(
'from' => '/countries.json',
'to' => '/xml/countries.xml',
Expand Down
5 changes: 5 additions & 0 deletions scripts/export_yaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

$rootDir = dirname(dirname(__FILE__));
$files = array(
'regions' => array(
'from' => '/regions.json',
'to' => '/yml/regions.yml',
'singular' => 'region',
),
'countries' => array(
'from' => '/countries.json',
'to' => '/yml/countries.yml',
Expand Down
2 changes: 1 addition & 1 deletion sql/countries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ INSERT INTO `countries` VALUES (1,'Afghanistan','AFG','004','AF','93','Kabul','A
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2023-08-11 10:26:35
-- Dump completed on 2023-08-11 10:26:35
61 changes: 61 additions & 0 deletions sql/regions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# ************************************************************
# 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 */;


# Dump of table regions
# ------------------------------------------------------------

DROP TABLE IF EXISTS `regions`;

CREATE TABLE `regions` (
`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,
`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`)
) ENGINE=InnoDB AUTO_INCREMENT=251 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

LOCK TABLES `regions` WRITE;
/*!40000 ALTER TABLE `regions` DISABLE KEYS */;

INSERT INTO `regions` (`id`, `name`, `translations`, `created_at`, `updated_at`, `flag`, `wikiDataId`)
VALUES
(1,'Africa','{\"kr\":\"아프리카\",\"pt-BR\":\"África\",\"pt\":\"África\",\"nl\":\"Afrika\",\"hr\":\"Afrika\",\"fa\":\"آفریقا\",\"de\":\"Afrika\",\"es\":\"África\",\"fr\":\"Afrique\",\"ja\":\"アフリカ\",\"it\":\"Africa\",\"cn\":\"非洲\",\"tr\":\"Afrika\"}','2023-08-14 07:11:03','2023-08-14 07:11:03',1,'Q15'),
(2,'Americas','{\"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\"}','2023-08-14 07:11:03','2023-08-14 07:11:03',1,'Q828'),
(3,'Asia','{\"kr\":\"아시아\",\"pt-BR\":\"Ásia\",\"pt\":\"Ásia\",\"nl\":\"Azië\",\"hr\":\"Ázsia\",\"fa\":\"آسیا\",\"de\":\"Asien\",\"es\":\"Asia\",\"fr\":\"Asie\",\"ja\":\"アジア\",\"it\":\"Asia\",\"cn\":\"亚洲\",\"tr\":\"Asya\"}','2023-08-14 07:11:03','2023-08-14 07:11:03',1,'Q48'),
(4,'Europe','{\"kr\":\"유럽\",\"pt-BR\":\"Europa\",\"pt\":\"Europa\",\"nl\":\"Europa\",\"hr\":\"Európa\",\"fa\":\"اروپا\",\"de\":\"Europa\",\"es\":\"Europa\",\"fr\":\"Europe\",\"ja\":\"ヨーロッパ\",\"it\":\"Europa\",\"cn\":\"欧洲\",\"tr\":\"Avrupa\"}','2023-08-14 07:11:03','2023-08-14 07:11:03',1,'Q46'),
(5,'Oceania','{\"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\"}','2023-08-14 07:11:03','2023-08-14 07:11:03',1,'Q55643'),
(6,'Polar','{\"kr\":\"남극\",\"pt-BR\":\"Antártida\",\"pt\":\"Antártida\",\"nl\":\"Antarctica\",\"hr\":\"Antarktika\",\"fa\":\"جنوبگان\",\"de\":\"Antarktika\",\"es\":\"Antártida\",\"fr\":\"Antarctique\",\"ja\":\"南極大陸\",\"it\":\"Antartide\",\"cn\":\"南極洲\",\"tr\":\"Antarktika\"}','2023-08-14 07:11:03','2023-08-14 07:11:03',1,'Q51');

/*!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

0 comments on commit 83d39f2

Please sign in to comment.