1.6.0 parsing timezones
This commit is contained in:
@@ -22,8 +22,11 @@ def test_code(request):
|
|||||||
|
|
||||||
res = None
|
res = None
|
||||||
|
|
||||||
from SubscribesApp.reports import send_mail_for_user_subscribes_that_is_going_to_finish
|
from ReferenceDataApp.funcs import parse_data
|
||||||
send_mail_for_user_subscribes_that_is_going_to_finish()
|
parse_data()
|
||||||
|
|
||||||
|
# from SubscribesApp.reports import send_mail_for_user_subscribes_that_is_going_to_finish
|
||||||
|
# send_mail_for_user_subscribes_that_is_going_to_finish()
|
||||||
|
|
||||||
if res:
|
if res:
|
||||||
if type(res) == str:
|
if type(res) == str:
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ from django.contrib import admin
|
|||||||
from sets.admin import Admin_Trans_BaseModel
|
from sets.admin import Admin_Trans_BaseModel
|
||||||
from .models import *
|
from .models import *
|
||||||
from modeltranslation.admin import TranslationAdmin
|
from modeltranslation.admin import TranslationAdmin
|
||||||
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
class Admin_Country(Admin_Trans_BaseModel):
|
class Admin_Country(Admin_Trans_BaseModel):
|
||||||
fieldsets = [
|
fieldsets = [
|
||||||
@@ -10,11 +11,20 @@ class Admin_Country(Admin_Trans_BaseModel):
|
|||||||
'fields': [
|
'fields': [
|
||||||
'name', 'enable', 'short_code', 'code',
|
'name', 'enable', 'short_code', 'code',
|
||||||
]
|
]
|
||||||
}]
|
}],
|
||||||
|
[_('Дополнительно'), {
|
||||||
|
'classes': ['wide', 'collapse'],
|
||||||
|
'fields': (
|
||||||
|
'timezone',
|
||||||
|
'geo_lat', 'geo_lon',
|
||||||
|
'json_data',
|
||||||
|
)
|
||||||
|
}],
|
||||||
]
|
]
|
||||||
|
|
||||||
list_display = [
|
list_display = [
|
||||||
'id', 'name', 'name_en', 'name_ru',
|
'id', 'name', 'name_en', 'name_ru',
|
||||||
|
'timezone',
|
||||||
'short_code', 'code',
|
'short_code', 'code',
|
||||||
'enable', 'area_id', 'parsing_finished_DT',
|
'enable', 'area_id', 'parsing_finished_DT',
|
||||||
'order', 'modifiedDT', 'createDT']
|
'order', 'modifiedDT', 'createDT']
|
||||||
@@ -28,12 +38,21 @@ class Admin_City(Admin_Trans_BaseModel):
|
|||||||
'fields': [
|
'fields': [
|
||||||
'name', 'enable', 'country',
|
'name', 'enable', 'country',
|
||||||
]
|
]
|
||||||
}]
|
}],
|
||||||
|
[_('Дополнительно'), {
|
||||||
|
'classes': ['wide', 'collapse'],
|
||||||
|
'fields': (
|
||||||
|
'timezone',
|
||||||
|
'geo_lat', 'geo_lon',
|
||||||
|
'json_data',
|
||||||
|
)
|
||||||
|
}],
|
||||||
]
|
]
|
||||||
|
|
||||||
list_display = [
|
list_display = [
|
||||||
'id', 'name', 'name_en', 'name_ru',
|
'id', 'name', 'name_en', 'name_ru',
|
||||||
'country',
|
'country',
|
||||||
|
'timezone',
|
||||||
'enable', 'area_id', 'parsing_finished_DT',
|
'enable', 'area_id', 'parsing_finished_DT',
|
||||||
'order', 'modifiedDT', 'createDT']
|
'order', 'modifiedDT', 'createDT']
|
||||||
search_fields = ['id', 'name_en', 'name_ru', 'country__name']
|
search_fields = ['id', 'name_en', 'name_ru', 'country__name']
|
||||||
@@ -50,12 +69,21 @@ class Admin_Airport(Admin_Trans_BaseModel):
|
|||||||
'international_name',
|
'international_name',
|
||||||
# 'area_id'
|
# 'area_id'
|
||||||
]
|
]
|
||||||
}]
|
}],
|
||||||
|
[_('Дополнительно'), {
|
||||||
|
'classes': ['wide', 'collapse'],
|
||||||
|
'fields': (
|
||||||
|
'timezone',
|
||||||
|
'geo_lat', 'geo_lon',
|
||||||
|
'json_data',
|
||||||
|
)
|
||||||
|
}],
|
||||||
]
|
]
|
||||||
|
|
||||||
list_display = [
|
list_display = [
|
||||||
'id', 'name', 'name_en', 'name_ru',
|
'id', 'name', 'name_en', 'name_ru',
|
||||||
'city', 'iata_code', 'icao_code',
|
'city', 'iata_code', 'icao_code',
|
||||||
|
'timezone',
|
||||||
'international_name',
|
'international_name',
|
||||||
'enable', 'area_id', 'parsing_finished_DT',
|
'enable', 'area_id', 'parsing_finished_DT',
|
||||||
'order', 'modifiedDT', 'createDT']
|
'order', 'modifiedDT', 'createDT']
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ from .models import *
|
|||||||
import hashlib, json
|
import hashlib, json
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
from timezonefinder import TimezoneFinder
|
||||||
|
|
||||||
|
tzf = TimezoneFinder()
|
||||||
|
|
||||||
def search_cities_in_db(search_str):
|
def search_cities_in_db(search_str):
|
||||||
|
|
||||||
@@ -57,20 +59,31 @@ def create_airports_by_airportsList(airportsList, city=None):
|
|||||||
if airport_Dict['iata']:
|
if airport_Dict['iata']:
|
||||||
kwargs.update({'iata_code': airport_Dict['iata']})
|
kwargs.update({'iata_code': airport_Dict['iata']})
|
||||||
airport = Airport.objects.get(**kwargs)
|
airport = Airport.objects.get(**kwargs)
|
||||||
|
if airport.geo_lat and airport.geo_lon and not airport.timezone:
|
||||||
|
airport.timezone = tzf.timezone_at(
|
||||||
|
lng=float(airport.geo_lon), lat=float(airport.geo_lat))
|
||||||
|
airport.save(update_fields=['timezone'])
|
||||||
|
print(f'airport {airport.international_name} - {airport.timezone}')
|
||||||
except Airport.DoesNotExist:
|
except Airport.DoesNotExist:
|
||||||
print(f' - - {airport_Dict["iata"]} не найден в БД > добавляем')
|
print(f' - - {airport_Dict["iata"]} не найден в БД > добавляем')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f'error = {str(e)}')
|
print(f'error = {str(e)}')
|
||||||
|
|
||||||
if not airport:
|
if not airport:
|
||||||
|
geo_lat = float(airport_Dict['@lat'])
|
||||||
|
geo_lon = float(airport_Dict['@lon'])
|
||||||
|
tz = tzf.timezone_at(lng=geo_lon, lat=geo_lat)
|
||||||
|
print(f'airport {airport_Dict["int_name"]} - {tz}')
|
||||||
|
|
||||||
airport_kwargs = {
|
airport_kwargs = {
|
||||||
'city': city,
|
'city': city,
|
||||||
|
|
||||||
# 'name_ru': airport_Dict['name:ru'],
|
# 'name_ru': airport_Dict['name:ru'],
|
||||||
# 'name_en': airport_Dict['name:en'],
|
# 'name_en': airport_Dict['name:en'],
|
||||||
|
'timezone': tz,
|
||||||
|
|
||||||
'geo_lat': str(airport_Dict['@lat']),
|
'geo_lat': str(geo_lat),
|
||||||
'geo_lon': str(airport_Dict['@lon']),
|
'geo_lon': str(geo_lon),
|
||||||
|
|
||||||
'international_name': airport_Dict['int_name'],
|
'international_name': airport_Dict['int_name'],
|
||||||
|
|
||||||
@@ -119,7 +132,10 @@ def parse_data():
|
|||||||
|
|
||||||
country = Country.objects.get(**kwargs)
|
country = Country.objects.get(**kwargs)
|
||||||
|
|
||||||
if country.parsing_finished_DT and (datetime.now() - country.parsing_finished_DT).days < 30:
|
if (country.parsing_finished_DT
|
||||||
|
and (datetime.now() - country.parsing_finished_DT).days < 30
|
||||||
|
and country.timezone
|
||||||
|
):
|
||||||
print(f' + {country.name} - существует в БД, не требует парсинга')
|
print(f' + {country.name} - существует в БД, не требует парсинга')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -194,6 +210,11 @@ def parse_data():
|
|||||||
else:
|
else:
|
||||||
print(f'error = {str(e)}')
|
print(f'error = {str(e)}')
|
||||||
|
|
||||||
|
geo_lat = float(city_Dict['@lat'])
|
||||||
|
geo_lon = float(city_Dict['@lon'])
|
||||||
|
tz = tzf.timezone_at(lng=geo_lon, lat=geo_lat)
|
||||||
|
print(f'city {city_Dict["name:en"]} - {tz}')
|
||||||
|
|
||||||
# собираем данные
|
# собираем данные
|
||||||
city_kwargs = {
|
city_kwargs = {
|
||||||
'country': country,
|
'country': country,
|
||||||
@@ -201,8 +222,11 @@ def parse_data():
|
|||||||
# 'name_ru': city_Dict['name:ru'],
|
# 'name_ru': city_Dict['name:ru'],
|
||||||
# 'name_en': city_Dict['name:en'],
|
# 'name_en': city_Dict['name:en'],
|
||||||
|
|
||||||
'geo_lat': str(city_Dict['@lat']),
|
'timezone': tz,
|
||||||
'geo_lon': str(city_Dict['@lon']),
|
|
||||||
|
'geo_lat': str(geo_lat),
|
||||||
|
'geo_lon': str(geo_lon),
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if city_Dict['name:ru']:
|
if city_Dict['name:ru']:
|
||||||
@@ -232,6 +256,9 @@ def parse_data():
|
|||||||
hash_data = hashlib.md5(json.dumps(country_Dict, sort_keys=True, ensure_ascii=True).encode('utf-8')).hexdigest()
|
hash_data = hashlib.md5(json.dumps(country_Dict, sort_keys=True, ensure_ascii=True).encode('utf-8')).hexdigest()
|
||||||
country.add_node_to_json_data({'hash': hash_data})
|
country.add_node_to_json_data({'hash': hash_data})
|
||||||
|
|
||||||
|
country.timezone = tzf.timezone_at(lng=float(country.geo_lon), lat=float(country.geo_lat))
|
||||||
|
print(f'country {country.name} - {country.timezone}')
|
||||||
|
|
||||||
if 'parsing_status' in country_Dict and country_Dict['parsing_status'] == 'finished':
|
if 'parsing_status' in country_Dict and country_Dict['parsing_status'] == 'finished':
|
||||||
country.parsing_finished_DT = datetime.now()
|
country.parsing_finished_DT = datetime.now()
|
||||||
country.save(update_fields=['parsing_finished_DT'])
|
country.save(update_fields=['parsing_finished_DT'])
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ class Country(BaseModel):
|
|||||||
geo_lat = models.CharField(max_length=20, verbose_name=_('GPS широта'), blank=True, null=True)
|
geo_lat = models.CharField(max_length=20, verbose_name=_('GPS широта'), blank=True, null=True)
|
||||||
geo_lon = models.CharField(max_length=20, verbose_name=_('GPS долгота'), blank=True, null=True)
|
geo_lon = models.CharField(max_length=20, verbose_name=_('GPS долгота'), blank=True, null=True)
|
||||||
|
|
||||||
|
timezone = models.CharField(max_length=250, verbose_name=_('Часовая зона'), blank=True, null=True)
|
||||||
|
|
||||||
area_id = models.BigIntegerField(blank=True, null=True)
|
area_id = models.BigIntegerField(blank=True, null=True)
|
||||||
|
|
||||||
parsing_finished_DT = models.DateTimeField(verbose_name=_('Дата и время завершения парсинга'), blank=True, null=True)
|
parsing_finished_DT = models.DateTimeField(verbose_name=_('Дата и время завершения парсинга'), blank=True, null=True)
|
||||||
@@ -46,6 +48,8 @@ class City(BaseModel):
|
|||||||
|
|
||||||
area_id = models.BigIntegerField(blank=True, null=True)
|
area_id = models.BigIntegerField(blank=True, null=True)
|
||||||
|
|
||||||
|
timezone = models.CharField(max_length=250, verbose_name=_('Часовая зона'), blank=True, null=True)
|
||||||
|
|
||||||
parsing_finished_DT = models.DateTimeField(verbose_name=_('Дата и время завершения парсинга'), blank=True, null=True)
|
parsing_finished_DT = models.DateTimeField(verbose_name=_('Дата и время завершения парсинга'), blank=True, null=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
@@ -83,6 +87,8 @@ class Airport(BaseModel):
|
|||||||
geo_lat = models.CharField(max_length=20, verbose_name=_('GPS широта'), blank=True, null=True)
|
geo_lat = models.CharField(max_length=20, verbose_name=_('GPS широта'), blank=True, null=True)
|
||||||
geo_lon = models.CharField(max_length=20, verbose_name=_('GPS долгота'), blank=True, null=True)
|
geo_lon = models.CharField(max_length=20, verbose_name=_('GPS долгота'), blank=True, null=True)
|
||||||
|
|
||||||
|
timezone = models.CharField(max_length=250, verbose_name=_('Часовая зона'), blank=True, null=True)
|
||||||
|
|
||||||
area_id = models.BigIntegerField(blank=True, null=True)
|
area_id = models.BigIntegerField(blank=True, null=True)
|
||||||
|
|
||||||
parsing_finished_DT = models.DateTimeField(verbose_name=_('Дата и время завершения парсинга'), blank=True, null=True)
|
parsing_finished_DT = models.DateTimeField(verbose_name=_('Дата и время завершения парсинга'), blank=True, null=True)
|
||||||
|
|||||||
@@ -16,4 +16,5 @@ pytz==2024.1
|
|||||||
requests-pkcs12==1.24
|
requests-pkcs12==1.24
|
||||||
#django-tz-detect==0.4.0
|
#django-tz-detect==0.4.0
|
||||||
django-rosetta==0.10.0
|
django-rosetta==0.10.0
|
||||||
|
timezonefinder==6.5.2
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user