Skip to content

Commit

Permalink
fix: Multiple issues (#539)
Browse files Browse the repository at this point in the history
  • Loading branch information
dr5hn authored Nov 13, 2022
1 parent 0ca62f6 commit d47346b
Show file tree
Hide file tree
Showing 8 changed files with 1,044 additions and 1,286 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/export.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.0'
extensions: intl #optional
ini-values: "post_max_size=256M" #optional

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ https://dr5hn.github.io/countries-states-cities-database/

## Insights
Total Countries : 250 <br>
Total States/Regions/Municipalities : 5,001 <br>
Total Cities/Towns/Districts : 150,890 <br>
Total States/Regions/Municipalities : 4,989 <br>
Total Cities/Towns/Districts : 150,710 <br>

Last Updated On : 6th Oct 2022
Last Updated On : 13th Nov 2022

## When's the next API Database Update day?
I usually update API's database once a quarter.
Expand Down
4 changes: 2 additions & 2 deletions scripts/vendor/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "v0.2",
"require": {
"mashape/unirest-php": "^3.0",
"spatie/array-to-xml": "^2.10",
"symfony/yaml": "^5.0"
"spatie/array-to-xml": "^3.0",
"symfony/yaml": "^6.0"
}
}
121 changes: 26 additions & 95 deletions scripts/vendor/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions scripts/vendor/fix_cities.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
if (!empty($citiesArray)) :
foreach($citiesArray as $city) :
$city_name = mysqli_real_escape_string($conn, $city['name']);
$sql = "UPDATE cities SET name='".$city_name."' WHERE id=".$city['id'];
if ($conn->query($sql) === TRUE) {
echo "Record updated successfully".PHP_EOL;
} else {
echo "Error updating record: ".$sql." ".$conn->error.PHP_EOL;
}
// $sql = "UPDATE cities SET name='".$city_name."' WHERE id=".$city['id'];
// if ($conn->query($sql) === TRUE) {
// echo "Record updated successfully".PHP_EOL;
// } else {
// echo "Error updating record: ".$sql." ".$conn->error.PHP_EOL;
// }
endforeach;
endif;
40 changes: 22 additions & 18 deletions scripts/vendor/fix_duplicates.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
<?php
require_once 'base.php';

$countryId = 101; // India
$countryCode = 'SA'; // India
$stateCode = '04';

// Step 1: Find Duplicates
$sql = "SELECT name, country_id, state_id FROM cities WHERE country_id=$countryId ORDER BY country_id, state_id, name";
$sql = "SELECT id, name, country_id, state_id FROM cities WHERE country_code='$countryCode' AND state_code='$stateCode' ORDER BY country_id, state_id, name";
$cities = $conn->query($sql);

// Grab the JSON File
$file_name = "data/cities/" . $countryCode . '_' . $stateCode . '.json';

$citiesJson = file_get_contents($file_name);
$citiesArray = json_decode($citiesJson, true);
$citynames = array_column($citiesArray, 'name');
print_r($citynames);

$ids = [];

if ($cities->num_rows > 0) {
while ($city = $cities->fetch_assoc()) {
$countryId = (int)$city['country_id'];
$stateId = (int)$city['state_id'];
// $name = $city['name'];
$name = implode('%', str_split($city['name']));
$sqld = "SELECT id, name FROM cities WHERE country_id=$countryId AND state_id=$stateId AND name LIKE '".$name."' ORDER BY id";
$cityResult = $conn->query($sqld);
if ($cityResult->num_rows > 1) {
echo 'Checking for: '.$city['name'].PHP_EOL;
echo '-----------'.PHP_EOL;
echo 'SQL: '.$sqld.PHP_EOL;
echo 'Found Duplicate....'.PHP_EOL;
while ($cr = $cityResult->fetch_assoc()) {
// Write what to do with duplicate
echo 'Duplicate Name & ID: '.$cr["name"].' ['.$cr["id"].']'.PHP_EOL;
}
echo ''.PHP_EOL.PHP_EOL;
$name = $city['name'];
$key = array_search($name, $citynames);
if ($key || $key === 0) {
// echo $name . ' ' . $key . PHP_EOL;
} else {
echo $city['id'] . ' ' . $name . ' not found' . PHP_EOL;
array_push($ids, $city['id']);
}
}

echo implode(',', $ids);
}

$conn->close();
10 changes: 5 additions & 5 deletions scripts/vendor/get_cities_by_state_country.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
// RO-MM - 244
// RO-MS - 599

$countryWiki = 'TN';
$stateFips = '21';
$countryWiki = 'SA';
$stateFips = '04';

$file_name = "data/".$countryWiki.'_'.$stateFips.'.json';
$fetchCitiesOnly = true;
$file_name = "data/cities/".$countryWiki.'_'.$stateFips.'.json';
$fetchCitiesOnly = false;
$city = $fetchCitiesOnly ? '&types=CITY' : '';

for ($i=0; $i<3; $i++): // 379 / 10
for ($i=0; $i<5; $i++): // 379 / 10
$url = "https://wft-geo-db.p.rapidapi.com/v1/geo/countries/".$countryWiki."/regions/".$stateFips."/cities?offset=".$offset."&limit=10".$city."&sort=name";
echo $url.PHP_EOL;
$response = Unirest\Request::get($url,
Expand Down
Loading

0 comments on commit d47346b

Please sign in to comment.