119 lines
3.4 KiB
Python
Executable File
119 lines
3.4 KiB
Python
Executable File
'''
|
|
Importing POI data from attractions.io api
|
|
'''
|
|
#!/usr/bin/env python3
|
|
|
|
from datetime import datetime, date
|
|
import json, requests, psycopg2
|
|
from psycopg2 import sql
|
|
|
|
db_params = {
|
|
'dbname': 'gp0',
|
|
'user': 'kuhnobowls',
|
|
'password': 'saddog095',
|
|
'host': '192.168.88.5',
|
|
'port': '5432',
|
|
'options': '-c search_path=knoebels'
|
|
}
|
|
|
|
def log_to_database(table_name, data):
|
|
with psycopg2.connect(**db_params) as conn:
|
|
with conn.cursor() as cursor:
|
|
columns = len(data[0])
|
|
query = sql.SQL("INSERT INTO {table} VALUES ({values})").format(
|
|
table=sql.Identifier(table_name),
|
|
values=sql.SQL(', ').join(sql.Placeholder() * columns)
|
|
)
|
|
|
|
cursor.executemany(query, data)
|
|
conn.commit()
|
|
|
|
def generic_query(q):
|
|
ret = []
|
|
with psycopg2.connect(**db_params) as conn:
|
|
with conn.cursor() as cursor:
|
|
cursor.execute(q)
|
|
rows = cursor.fetchall()
|
|
col_names = [desc[0] for desc in cursor.description]
|
|
|
|
for row in rows:
|
|
ret.append(row)
|
|
|
|
return ret
|
|
|
|
data = None
|
|
|
|
with open('records.json', 'r', encoding='utf-8') as file:
|
|
data = json.load(file)
|
|
|
|
rows = []
|
|
|
|
for poi in data['Item']:
|
|
aoi_id = poi['_id']
|
|
Name = poi['Name']
|
|
AbbreviatedName = poi['AbbreviatedName']
|
|
Summary = poi['Summary']
|
|
Keywords = poi['Keywords']
|
|
DefaultImage = poi['DefaultImage']
|
|
Location = poi['Location']
|
|
Featured = poi['Featured']
|
|
WayfindingEnabled = poi['WayfindingEnabled']
|
|
VisibleOnMap = poi['VisibleOnMap']
|
|
Category = poi['Category']
|
|
Parent = poi['Parent']
|
|
|
|
try:
|
|
MenuURL = poi['MenuURL']
|
|
except:
|
|
MenuURL = None
|
|
|
|
try:
|
|
MinimumHeightRequirement = poi['MinimumHeightRequirement']
|
|
except:
|
|
MinimumHeightRequirement = None
|
|
|
|
try:
|
|
MinimumUnaccompaniedHeightRequirement = poi['MinimumUnaccompaniedHeightRequirement']
|
|
except:
|
|
MinimumUnaccompaniedHeightRequirement = None
|
|
|
|
try:
|
|
MaximumHeightRequirement = poi['MaximumHeightRequirement']
|
|
except:
|
|
MaximumHeightRequirement = None
|
|
|
|
try:
|
|
MinimumAgeRequirement = poi['MinimumAgeRequirement']
|
|
except:
|
|
MinimumAgeRequirement = None
|
|
|
|
try:
|
|
MinimumUnaccompaniedAgeRequirement = poi['MinimumUnaccompaniedAgeRequirement']
|
|
except:
|
|
MinimumUnaccompaniedAgeRequirement = None
|
|
|
|
try:
|
|
MaximumAgeRequirement = poi['MaximumAgeRequirement']
|
|
except:
|
|
MaximumAgeRequirement = None
|
|
|
|
try:
|
|
RestrictionSummary = poi['RestrictionSummary']
|
|
except:
|
|
RestrictionSummary = None
|
|
|
|
row = [aoi_id, Name, AbbreviatedName, Summary, Keywords, DefaultImage, Location, Featured, WayfindingEnabled, VisibleOnMap, Category, Parent, MenuURL, MinimumHeightRequirement, MinimumUnaccompaniedHeightRequirement, MaximumHeightRequirement, MinimumAgeRequirement, MinimumUnaccompaniedAgeRequirement, MaximumAgeRequirement, RestrictionSummary]
|
|
rows.append(row)
|
|
|
|
cats = []
|
|
|
|
for cat in data['Category']:
|
|
aoi_id = cat['_id']
|
|
Name = cat['Name']
|
|
Parent = cat['Parent']
|
|
row = [aoi_id, Name, Parent]
|
|
cats.append(row)
|
|
|
|
log_to_database('LZ_attractions_io_categories', cats)
|
|
#log_to_database('LZ_attractions_io_poi', rows)
|