Skip to content

Commit aa3fd89

Browse files
committed
PostaDB 2.0
1 parent 8755b1e commit aa3fd89

File tree

12 files changed

+3455
-6716
lines changed

12 files changed

+3455
-6716
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
/.idea
1+
/.idea
2+
composer\.lock
3+
/vendor

.htaccess

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<FilesMatch "^\.">
2+
Order allow,deny
3+
Deny from all
4+
</FilesMatch>

README.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,33 @@
1-
# PostaDB
2-
Magyarorszagi iranyitoszamok es telepulesek adatbazisa
1+
# PostaDB 2.0
2+
Magyarországi irányítószámok és települések adatbázisa
33

4-
Adatbazis .sql .csv es .xls formatumban, a Magyar Posta adatbazisa alapjan
4+
Adatbázis .csv formátumban, auto-importerrel, a Magyar Posta hivatalos adatbázis alapján
55
http://posta.hu/ugyfelszolgalat/iranyitoszam_kereso
66

7-
Frissitve: 2018.02.06
7+
> **v.2.0.0:**
8+
>
9+
> - Publikus stabil verzió
10+
11+
> **Függőségek:**
12+
> - Composer
13+
14+
Telepítés:
15+
```
16+
composer install
17+
```
18+
19+
- Hozzuk létre a táblát a table.sql alapján
20+
- Az env/.env.sample file-ban állítsuk be a konfigurációs értékeket, majd:
21+
22+
```
23+
cd env
24+
cp .env.sample .env
25+
```
26+
27+
Használat:
28+
```
29+
cd /var/www/host/
30+
php importer.php
31+
```
32+
33+
Frissitve: 2019.04.03

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"require": {
3+
"vlucas/phpdotenv": "^3.1"
4+
}
5+
}

env/.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
DB_HOST=172.16.238.12
2+
DB_DATABASE=ocrm
3+
DB_USERNAME=root
4+
DB_PASSWORD=

env/.env.sample

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
DB_HOST=
2+
DB_DATABASE=
3+
DB_USERNAME=
4+
DB_PASSWORD=

importer.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
if(PHP_SAPI !== 'cli' || isset($_SERVER['HTTP_USER_AGENT'])):
3+
die('Please run only from cli');
4+
endif;
5+
6+
/**
7+
* Include Dotenv library to pull config options from .env file.
8+
*/
9+
if(file_exists(__DIR__ . '/vendor/autoload.php')) {
10+
require_once __DIR__ . '/vendor/autoload.php';
11+
12+
$dotenv = Dotenv\Dotenv::create(__DIR__, '/env/.env');
13+
$dotenv->load();
14+
15+
} else {
16+
die('Please install via composer and setup a new .env file!');
17+
}
18+
19+
try {
20+
$conn = new mysqli(getenv('DB_HOST'), getenv('DB_USERNAME'), getenv('DB_PASSWORD'), getenv('DB_DATABASE'));
21+
mysqli_set_charset($conn,"utf8");
22+
23+
if ($conn->connect_error) {
24+
die("Connection failed: " . $conn->connect_error);
25+
}
26+
27+
$db = getenv('DB_DATABASE');
28+
echo "Connected DB: $db\n\n";
29+
30+
$csv = 'zip.csv';
31+
32+
function csvToArray($filename='', $delimiter=',')
33+
{
34+
if(!file_exists($filename) || !is_readable($filename))
35+
return FALSE;
36+
$header = NULL;
37+
$data = array();
38+
if (($handle = fopen($filename, 'r')) !== FALSE)
39+
{
40+
while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE)
41+
{
42+
if(!$header)
43+
$header = $row;
44+
else
45+
$data[] = array_combine($header, $row);
46+
}
47+
fclose($handle);
48+
}
49+
return $data;
50+
}
51+
52+
$data = csvToArray($csv);
53+
foreach($data as $d) {
54+
$zip = $d['zip'];
55+
$city = $d['city'];
56+
$district = $d['district'];
57+
58+
$sql = "INSERT INTO zip(zip, city, district)
59+
VALUES ('$zip', '$city', '$district')";
60+
61+
if($conn->query($sql) === TRUE) {
62+
echo "Zip inserted: $zip --------–>\n";
63+
} else {
64+
echo "Unable to save, try again --------–>\n";
65+
}
66+
}
67+
68+
$conn->close();
69+
70+
} catch (Exception $e) {
71+
echo 'Script error: ' . $e->getMessage();
72+
exit(1);
73+
}

0 commit comments

Comments
 (0)