Save JSON file in SQL Server - json

Nested JSON file save SQL Server as one record.
How to design hierarchy model in one table?
{
"SSAAResponse": {
"TheCTerRegRequest": {
"ParentCompanyRegOrgE": "",
"StartMonth": 1,
"TheCTerRegRequestNoticesList": [
{
"CreateDateTime": "1397/11/02-12:09",
"NoticeType": 6,
"RequestNoticeText": "Language Journal offers 6 or 7 essays or research studies per quarterly issue, a professional calendar of events and news, a listing of relevant articles in other journals, an annual survey of doctoral degrees in all areas concerning foreign and second languages, and reviews of scholarly books, textbooks, videotapes, and software."
},
{
"CreateDateTime": "1397/11/01-10:36",
"NoticeType": 10,
"RequestNoticeText": "c version of The Modern Language Journal is available at"
},
{
"CreateDateTime": "1397/10/29-09:18",
"NoticeType": 8,
"RequestNoticeText": "A board of directors for a company composed entirely of one gender or race
Before Civil Rights laws, public schools in the South admitted only white studentsشاه"
}
],
"TheReceiveUnit": {
"UnitName": "Strategies That",
"State": 1,
"Code": "16519"
},
"TheCTerRegRequestNamesList": [
{
"Name": "Corp 1",
"status": 2,
"Seqnumber": 4
},
{
"Name": "Corp 2",
"status": 2,
"Seqnumber": 5
},
{
"Name": "Corp 3",
"status": 2,
"Seqnumber": 3
},
{
"Name": "Corp 4",
"status": 4,
"Seqnumber": 1
},
{
"Name": "Corp 5",
"status": 2,
"Seqnumber": 2
}
],
"TheCTerRegRequestNewspaperList": [
{
"TheGNewspaper": {
"State": 2,
"Code": "0352",
"Title": "آواي کرمانشاه"
}
}
],
"ApplicantNationalCode": "3240953501",
"SignBookMobileNumber4SMS": "",
"TheCTerRegRequestStocksList": [],
"FounderMember": "",
"CapitalDescription": "",
"TheCTerRegRequestDefectsList": [],
"MinuteStartTime": "12:00",
"DirectMemberMinuteDate": "1397/10/25",
"MinuteDate": "1397/10/25",
"ParentCompanyPublicNumber": "",
"Declaration": "programs delivering customized professional development. A former master teacher, she has been in education for more than 25 years and works with administrators and teachers in groups of varying sizes from kindergarten through high school. She is the author of Complex Text Decoded: ",
"EmaiLAddress": "",
"OwnerShipType": 1,
"CreateDateTime": "1397/10/26-11:33",
"SignBookFamily": "مژگاني",
"ParentCompanyRegOrg": "",
"TheCTerRegRequestRejectReasonsList": [
{
"RejectDesc": "Kathy Glass consults nationally with schools and districts, presents at conferences, and teaches seminars for university and county",
"RejectDateTime": "1397/11/02-11:58",
"TheCIMinutesRejectType": {
"State": 1,
"Code": "004",
"Title": "Kathy Glass consults nationally with schools and districts, presents at conferences, and teaches seminars for university and county"
}
}
],
"TotalCapital": 1000000,
"SignBookLawyerState": 1,
"ApplicantFirstName": "کسري",
"AfterRegNationalCode": "",
"InvitationLetterNumber": "",
"TheCIInstitutionType": {},
"DirectorMember": "",
"TheCTerRegRequestPersonList": [
{
"CapitalStatus": 2,
"FirstNameFA": "mostafa",
"LastNameFA": "sholeh",
"FatherNameLA": "",
"PhoneNumber": "083-37225212",
"RecordNo": "",
"FirstNameLA": "",
"MobileNumber4SMS": "09904040946",
"TheCTerRegRequestPersonStocksList": [
{
"AmountStocks": 500000,
"TheCISharesType": {
"State": 1,
"Code": "005",
"Title": "cash"
}
}
],
"BirthDateSH": "1371/11/05",
"PersonType": 1,
"PostCode": "6713945936",
"Address": "3634 N Fm 2869, Winnsboro, TX, 75494 ",
"FatherNameFA": "amir",
"TheCICompanyType": {},
"NationalityCode": "3240953501",
"ExternalNationalStatus": 1,
"LastNameLA": "",
"IdentityNo": "3240953501",
"TheCTerRegRequestPersonPostsList": [
{
"EndDateValidity": "1398/10/25",
"Description": "",
"TheCIPostType": {
"State": 1,
"Code": "004",
"Title": "Director"
},
"StartDate": "1397/10/25",
"IsNonPartnership": 2,
"PeriodTime": 1,
"PostTitle": "",
"IsNonDirectMember": 2
},
{
"EndDateValidity": "1398/10/25",
"Description": "",
"TheCIPostType": {
"State": 1,
"Code": "001",
"Title": "Boss"
},
"StartDate": "1397/10/25",
"IsNonPartnership": 2,
"PeriodTime": 1,
"PostTitle": "",
"IsNonDirectMember": 2
}
],
"Sex": 2
},
{
"CapitalStatus": 2,
"FirstNameFA": "mahdi",
"LastNameFA": "salefdkjf",
"FatherNameLA": "",
"PhoneNumber": "083-37225212",
"RecordNo": "",
"FirstNameLA": "",
"MobileNumber4SMS": "09189954983",
"TheCTerRegRequestPersonStocksList": [
{
"AmountStocks": 500000,
"TheCISharesType": {
"State": 1,
"Code": "005",
"Title": "cash"
}
}
],
"BirthDateSH": "1370/11/23",
"PersonType": 1,
"PostCode": "6713945936",
"Address": "3634 N Fm 2869, Winnsboro, TX, 75494 ",
"FatherNameFA": "mohamad",
"TheCICompanyType": {},
"NationalityCode": "3240739070",
"ExternalNationalStatus": 1,
"LastNameLA": "",
"IdentityNo": "3240739070",
"TheCTerRegRequestPersonPostsList": [
{
"EndDateValidity": "1398/10/25",
"Description": "",
"TheCIPostType": {
"State": 1,
"Code": "045",
"Title": "ghaem magham"
},
"StartDate": "1397/10/25",
"IsNonPartnership": 2,
"PeriodTime": 1,
"PostTitle": "",
"IsNonDirectMember": 2
},
{
"EndDateValidity": "1398/10/25",
"Description": "",
"TheCIPostType": {
"State": 1,
"Code": "002",
"Title": "boss heyat"
},
"StartDate": "1397/10/25",
"IsNonPartnership": 2,
"PeriodTime": 1,
"PostTitle": "",
"IsNonDirectMember": 2
}
],
"Sex": 2
}
],
"ApplicantLastNameEn": "",
"ActivityTimeState": 2,
"TheObjectState": {
"StateType": 2,
"Code": "001126",
"Title": "تadmin"
},
"SignBookDate": "",
"WebAddress": "",
"FaxNumber": "",
"AfterRegRegisterDate": "",
"CashCapital": 1000000,
"RequestNoticeText": "Interest in the relations between discourse and
(social) context has been limited mostly to sociolinguistics (Ammon, 2005) and
Critical Discourse Analysis (CDA)(Wodak, & Meyer, 2001). In these approaches,
a more or less direct link is established between social structures (for instance
conceptualized as social ‘variables’ such as gender, class or age in",
"SignBookFamilyEn": "",
"ParentCompanyRegisterDateM": "",
"Turn": 1,
"TheCTerRegRequestPledgedCapitalList": [],
"SignatureAuthorityDesc": "mostafa sholeh",
"ApplicantLastName": "sholeh",
"LicenseState": 1,
"ParentCompanyAddress": "",
"AfterRegName": "",
"ParentCompanyName": "",
"TheCTerRegRequestActivitiesList": [
{
"ActivityDesc": "Teaching this skill supports self-agency so students can define unfamiliar words independently"
}
],
"ParentCompanyRegisterDate": "",
"ParentCountryStatuteE": "",
"ApplicantNationalityType": 1,
"PostCode": "6713945936",
"ParentCompanyType": "",
"ParentCompanyLetterDate": "",
"ParentCompanyCurrency": "",
"RequestReceipt": "A refereed publication, The Modern Language Journal is dedicated to promoting scholarly exchange among teachers and researchers of all modern foreign languages and English as a second language. This journal publishes documented essays, quantitative and qualitative research studies, response articles, and editorials that challenge paradigms of language learning and teaching. The Modern Language Journal offers 6 or 7 essays or research studies per quarterly issue, a professional calendar of events and news, a listing of relevant articles in other journals, an annual survey of doctoral degrees in all areas concerning foreign and second languages, and reviews of scholarly books, textbooks, videotapes, and software. JSTOR provides a digital archive of the print version of The Modern Language Journal. The electronic version of The Modern Language Journal is available at http://www.interscience.wiley.com. Authorized users may be able to access the full text articles at this site. The Modern Language Journal also offers a fifth issue each year which alternates between a Focus Issue and a Monograph.",
"SignBookNationalityType": 1,
"CompanyLetter": "Wiley is a global provider of content and content-enabled workflow solutions in areas of scientific, technical, medical, and scholarly research; professional development; and education. Our core businesses produce scientific, technical, medical, and scholarly journals, reference works, books, database services, and advertising; professional books, subscription products, certification and training services and online applications; and education content and services including integrated online teaching and learning resources for undergraduate and graduate students and lifelong learners. Founded in 1807, John Wiley & Sons, Inc. has been a valued source of information and understanding for more than 200 years, helping people around the world meet their needs and fulfill their aspirations. Wiley has published the works of more than 450 Nobel laureates in all categories: Literature, Economics, Physiology or Medicine, Physics, Chemistry, and Peace. Wiley has partnerships with many of the world’s leading societies and publishes over 1,500 peer-reviewed journals and 1,500+ new books annually in print and online, as well as databases, major reference works and laboratory protocols in STMS subjects. With a growing open access offering, Wiley is committed to the widest possible dissemination of and access to the content we publish and supports all sustainable models of access. Our online platform, Wiley Online Library (wileyonlinelibrary.com) is one of the world’s most extensive multidisciplinary collections of online resources, covering life, health, social and physical sciences, and humanities.",
"PresenceDate": "",
"ApplicantPost": 1,
"SignBookNationalCode": "3240953501",
"SignBookPost": 1,
"SignBookLicenseDate": "",
"MinuteText": "umented essays, quantitative and qualitative research studies, response articles, and editorials that challenge paradigms of language learning and teaching. The Modern Language Journal offers 6 or 7 essays or research studies per quarterly issue, a professional calendar of events and news, a listing of relevant articles in other journals, an annual survey of doctoral degrees in all areas concerning foreign and second languages, and reviews of scholarly books, textbooks, videotapes, and software. JSTOR provides a digital archive of the print version of The Modern Language Journal. The electronic version of The Modern Language Journal is available at http://www.interscience.wiley.com. Authorized users may b",
"InvitationSessionTime": "",
"DirectMemberMinuteStartTime": "12:00",
"ParentCompanyLetterNumber": "",
"Statute": "Because youngsters with reading disabilities typically have problems involving poor phonological skills, they generally benefit from instructional approaches that provide highly explicit, systematic teaching of phonemic awareness and phonics. However, if children are taught systematic phonics in one part of the reading program but are encouraged to use context to guess at words when reading passages, they may not apply their phonics skills consistently. Thus, the phonics component of the reading program may be seriously undermined. Also, children must be placed for reading instruction in books that are a good match to their word identification accuracy and phonics skills. If they are placed in reading materials that are too difficult for their current skill levels, they may be left with few options other than guessing at words.
However, like normally-achieving readers, children with reading disabilities do benefit from encouragement to use context as an aid to comprehension. This kind of context use can occur when children are listening to text as well as when they are reading. For instance, in reading stories to children, teachers can encourage the use of sentence context or pictures to determine the meanings of unfamiliar words by modeling this process aloud: "Hmmm, what can I do if I am not sure what the word pale means? Well, the sentence says that D. W. put baby powder on her face to look pale, so I can think about what baby powder looks like…" Because youngsters with reading disabilities usually have listening comprehension that far outstrips their reading skills, oral comprehension activities often are the best ways to challenge and develop their comprehension abilities.",
"TheCTerRegRequestLicenseList": [],
"ApplicantBirthDate": "",
"AddressDesc": "he use of context in comprehension refers to something quite different from the use of context in word identification. Returning to the previous sentence about D.W.",
"FinancialCalenderType": 1,
"ApplicantFirstNameEn": "",
"DirectMemberMinuteText": "Black? Book? Box? (The guesses are often accompanied by more attention to the expression on the face of the teacher than to the print, as the child waits for this expression to change to indicate a correct guess.) Even when children are able to use context to arrive at the correct word, reliance on context to compensate for inaccurate or nonautomatic word reading creates a drain on comprehension. This kind of compensation becomes increasingly problematic as children are expected to read more challenging texts that have few or no pictures, sophisticated vocabulary, and grammatically complex sentences.",
"ParentCompanyNameE": "",
"NumOfDirectMember": 2,
"SignBookLicenseNo": "",
"FixPhoneNumber": "083-37225212",
"TheCTerRegRequestAdvertisingList": [],
"Authority": "",
"TheCICompanyType": {
"State": 1,
"Code": "001",
"Title": "Corp limited"
},
"SignBookBirthDate": "",
"SignBookNameEn": "",
"StartDay": 1,
"ActivityEndDate": "",
"SignBookName": "hamid",
"AccessNo": "3694361110607356378",
"ParentCountryStatute": "",
"TheCTerRegRequestBranchList": [],
"TheCTerRegRequestStatuteList": [
{
"Description": "phonics skills to decode occasional unknown words rapidly.",
"Clause": 0,
"Note": 0,
"Article": 2
},
{
"Description": "systems" to read words. Skilled readers do not need to rely on pictures or sentence context in word identification, because they can read most words automatically",
"Clause": 0,
"Note": 0,
"Article": 3
},
{
"Description": "increasingly accurate and automatic word identification skills, ",
"Clause": 0,
"Note": 1,
"Article": 3
},
{
"Description": "Scientific evidence strongly demonstrates that the development of skilled reading involves",
"Clause": 0,
"Note": 0,
"Article": 4
},
{
"Description": "When children encounter an unfamiliar word in reading, they may make use of context cues, that is, information from pictures or from sentences surrounding the unknown word.",
"Clause": 0,
"Note": 0,
"Article": 5
},
{
"Description": "monitor their reading to see if it was accurate",
"Clause": 0,
"Note": 0,
"Article": 6
},
{
"Description": "select the information that they need to focus on",
"Clause": 0,
"Note": 0,
"Article": 7
},
{
"Description": "Unfortunately for many students, choosing effective strategies does not come automatically. Often, students who have difficulty reading simply browse or skim through texts without a specific strategy in mind because they don’t have a clear reason for reading. ",
"Clause": 0,
"Note": 0,
"Article": 8
},
{
"Description": "For example, a situation that involves understanding and recalling details requires a different set of strategies from a situation where the reader is seeking specific information but memorization is not necessary.",
"Clause": 0,
"Note": 1,
"Article": 8
},
{
"Description": "Some students will do leisure reading because they are interested in a particular topic.",
"Clause": 0,
"Note": 0,
"Article": 9
},
{
"Description": " In fact, students may read a variety of texts for enjoyment: newspapers or magazines",
"Clause": 0,
"Note": 0,
"Article": 10
},
{
"Description": "Functional reading is what students will need to do all the time to get things done at school, at work and in their everyday lives. ",
"Clause": 0,
"Note": 0,
"Article": 11
},
{
"Description": "It may seem that only functional reading is important,",
"Clause": 0,
"Note": 0,
"Article": 12
},
{
"Description": "Students can learn to recognize contexts of reading and choose appropriate strategies through teacher-guided practice and reflection on the reading they do in various situations for various purposes.",
"Clause": 0,
"Note": 0,
"Article": 13
},
{
"Description": "Unfortunately for many students, choosing effective strategies does not come automatically. ",
"Clause": 0,
"Note": 0,
"Article": 14
},
{
"Description": "Teaching students about contexts of reading will help them be more confident and strategic in their reading",
"Clause": 0,
"Note": 0,
"Article": 15
},
{
"Description": "Contexts of reading are all the elements that influence how we read in different situations. The context includes: 1) the setting, 2) the text, and 3) the purpose for reading. There are two main types of reading contexts. In leisure contexts we choose to read for our own interest, pleasure or entertainment..",
"Clause": 0,
"Note": 0,
"Article": 16
},
{
"Description": "i am a teacher",
"Clause": 0,
"Note": 0,
"Article": 17
},
{
"Description": "i am a student",
"Clause": 0,
"Note": 0,
"Article": 18
},
{
"Description": "i am a student",
"Clause": 0,
"Note": 0,
"Article": 19
},
{
"Description": "asds was a replace",
"Clause": 0,
"Note": 0,
"Article": 20
},
{
"Description": "fghqwr hgfiqehk ewrjgfoqhg krjg",
"Clause": 0,
"Note": 0,
"Article": 21
},
{
"Description": "lkrdhgkhkhkfdg rtgerg wt,
"Clause": 0,
"Note": 0,
"Article": 22
},
{
"Description": "dgwejrfgjwegfk rgjwle ertehrgho",
"Clause": 0,
"Note": 0,
"Article": 23
},
{
"Description": "erewktlkrewhjgkw rkgjwgjkl",
"Clause": 0,
"Note": 0,
"Article": 24
},
{
"Description": "safddf dkjhaskjfgjka eirhweyhi",
"Clause": 0,
"Note": 0,
"Article": 25
},
{
"Description": "Test",
"Clause": 0,
"Note": 0,
"Article": 26
},
{
"Description": "test",
"Clause": 0,
"Note": 0,
"Article": 1
}
],
"ApplicantMobileNumber4SMS": "09904040946",
"FinalAcceptanceDate": "1397/10/27",
"Name": "test Corp",
"ParentCompanyAgentAuthority": "",
"AuthorityE": "",
"InvitationSessionDate": "",
"TheCTerRegRequestClusterGroupList": []
},
"Result": {
"Description": "send successful",
"Successful": true,
"Message": "423424",
"No": "-1",
"Code": "1000"
}
},
"CBIResponse": {
"respCode": 0,
"accessNo": "3694361110607356378"
}
}
I designed like below image:
below design is true?
USE [NFC]
GO
/****** Object: Table [dbo].[tbl_NFCInquiryStructure] Script Date: 2021-09-04 09:42:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tbl_NFCInquiryStructure](
[ID] [int] IDENTITY(1,1) NOT NULL,
[NodeName] [nvarchar](500) NULL,
[ParentId] [int] NULL,
[IsValue] [bit] NULL
) ON [PRIMARY]
GO
It shows table design that I guess that's right. Contains the parent field.
Is true?
I want to implement this hierarchical file in a table.
Help me please

Related

Deserializing Nested JSON API response with Django

I'm pretty new to the DRF and serializing/deserializing. I'm slowly building a dashboard for my business during the corona virus and learning to code. I am in a little deep, but after spending more than $10k on developers on upwork and not really get much result, I figured, what do I have to lose?
Our software provider has a full API for our needs https://developer.myvr.com/api/, but absolutely no dashboard to report statistics about our clients reservation data.
The end result will be a synchronization of some of the data from their API to my database which will be hosted through AWS. I chose to do it this way due to having to do some post processing of data from the API. For example, we need to calculate occupancy rates(which is not an endpoint), expenses from our accounting connection and a few other small calculations in which the data is not already in the provided API. I originally wanted to use the data from the API solely, but I'm hesitant due to the reasons above.
That's the backstory, here are the questions:
The API response is extremely complex and nested multiple times, what is the best practise to extract a replication of the structure of the data to my own Database? Would I have to create models for each field manually?
Example response:
```{
"uri": "https://api.myvr.com/v1/properties/b6b0f2fe278f612b/",
"id": "b6b0f2fe278f612b",
"key": "b6b0f2fe278f612b",
"accessDescription": null,
"accommodates": 11,
"active": false,
"addressOne": "11496 Zermatt Dr",
"addressTwo": null,
"allowTurns": true,
"amenities": "https://api.myvr.com/v1/property-amenities/?propertyId=b6b0f2fe278f612b",
"automaticallyApprove": false,
"baseNightlyRate": "395.00",
"baseRate": {
"uri": "https://api.myvr.com/v1/rates/660c299d4785c32e/",
"id": "660c299d4785c32e",
"key": "660c299d4785c32e",
"externalId": null,
"baseRate": true,
"changeoverDay": null,
"created": "2019-01-19T08:02:36Z",
"currency": "USD",
"endDate": "2020-01-18",
"minStay": 3,
"modified": "2019-01-19T08:02:36Z",
"monthly": 0,
"name": "Base Rate",
"weekNight": 39500,
"nightly": 39500,
"position": 0,
"property": {
"name": "API Demo Property",
"uri": "https://api.myvr.com/v1/properties/b6b0f2fe278f612b/",
"id": "b6b0f2fe278f612b",
"externalId": null,
"key": "b6b0f2fe278f612b",
"slug": "api-demo-property"
},
"ratePlan": {
"uri": "https://api.myvr.com/v1/rate-plans/862caa3f5267602d/",
"key": "862caa3f5267602d",
"name": "Default Rates for Property"
},
"repeat": true,
"startDate": "2020-01-18",
"weekend": 0,
"weekendNight": 0,
"weekly": 250000
},
"bathrooms": "4.0",
"bedrooms": 4,
"bookingUrl": "https://myvr.com/reservation/redirect/booking/b6b0f2fe278f612b/",
"checkInTime": "16:00:00",
"checkOutTime": "10:00:00",
"city": "Truckee",
"commissionStructure": null,
"countryCode": "US",
"created": "2016-01-19T00:01:48Z",
"currency": "USD",
"customFields": {},
"description": "Luxurious living, scenic mountain setting, entertainment galore. Located on a quiet street in Tahoe Donner, our well equipped modern home is nestled into the wilderness. A babbling creek greets visitors approaching the front step as it collects into a small pond with a cascading waterfall. <br/>\n<br/>\nInside, over 3,000 sqft of luxurious living space divides itself between two floors. On the first floor, a beautiful kitchen with granite counters, gas stove and stainless steel appliances opens to a large great room centered around a wood burning fireplace and featuring 30' soaring ceilings. A spacious loft overlooks the great room, showcasing a large poker/card table. Upstairs features a large entertainment room, complete with wet bar, shuffleboard table, and state-of-the-art television setup with surround sound. The scenic backyard is accessible from a large deck featuring a new hot tub with seating for 7.",
"externalId": null,
"feePlan": {
"uri": "https://api.myvr.com/v1/fee-plans/4d1c44383755051b/",
"key": "4d1c44383755051b",
"name": "Default Fees for Listing"
},
"headline": "Beautiful Four Bedroom Lake Front Property",
"houseRules": null,
"instantBookingsEnabled": false,
"lat": "39.3422523000",
"level": "unit",
"localAreaDescription": "Tahoe Donner is a year round activity resort. The amenities include private beach/boat launching facilities, pools, recreation center, tennis, horseback riding, golf, downhill skiing as well as cross country skiing. Truckee is a historical mining town-having a western feel but also has museums, theaters, fine dining plus 2 large supermarkets-all less than 3 miles from the house. Our home is also located within a 15 minute drive to 4 major ski resorts. Downtown Reno is a short 40 minute drive away for those seeking a night on the town or the thrill of a Nevada casino.",
"lon": "-120.2271947000",
"lowestNightlyRate": "395.00",
"manual": "",
"modified": "2019-10-18T17:18:43Z",
"name": "API Demo Property",
"owner": null,
"postalCode": "96161",
"ratePlan": {
"uri": "https://api.myvr.com/v1/rate-plans/862caa3f5267602d/",
"key": "862caa3f5267602d",
"name": "Default Rates for Property"
},
"ratePlanLocked": false,
"region": "CA",
"shortCode": "API",
"size": 3000,
"slug": "api-demo-property",
"suitableElderly": "yes",
"suitableEvents": "unknown",
"suitableGroups": "yes",
"suitableHandicap": "no",
"suitableInfants": "unknown",
"suitableKids": "yes",
"suitablePets": "no",
"suitableSmoking": "no",
"transitDescription": null,
"type": "house",
"weekendNights": [
5,
6
]
}```
I think the best way to populate the database would be to run a custom management command to run a once off script, I've done this previously with another database, however I'm still stuck as I don't really want to write these models manually. Also a concern is if a field is missing or the structure changes.
This project is definitely above my skills and extremely ambitious, but I would appreciate any feedback or advice anyone might have.
Thanks,
Darren
So I didn't really get any interest in this question, but I ended up working it out myself.
I hope someone googles it and might find it helpful.
import requests
from rest_framework.response import Response
from django.core.management.base import BaseCommand, CommandError
from reservation.models import Reservation
import time
MYVR_URL = 'https://api.myvr.com/'
MYVR_RESERVATION = 'v1/reservations/?limit=100'
headers = {
'Authorization': 'Basic SOmeAPiCodeHeRe123=',
}
class Command(BaseCommand):
help = 'Imports new properties and saves the objects in the database'
def handle(self, *args, **options):
url = MYVR_URL + MYVR_RESERVATION
print("Populating Reservations")
def looping_api(url, headers):
while url:
r = requests.request("GET", url, headers=headers)
url = r.json().get('next')
props_data = r.json().get('results')
start_time = time.time()
for prop in props_data:
try:
created = Reservation.objects.update_or_create(
myvr_key=prop.get('key'),
adults=prop.get('adults'),
children=prop.get('children'),
checkin=prop.get('checkIn'),
checkout=prop.get('checkOut'),
checkinTime=prop.get('checkInTime'),
checkoutTime=prop.get('checkOutTime'),
guestFirstName=prop.get('firstName'),
dateCreated=prop.get('created'),
dateBooked=prop.get('dateBooked'),
dateCancelled=prop.get('dateCanceled'),
contact=prop.get('contact').get('name'),
contact_key=prop.get('contact').get('key'),
guest_type=prop.get('guestType'),
property_name=prop.get('property').get('name'),
property_key=prop.get('property').get('key'),
source_code=prop.get('source').get('code'),
source_name=prop.get('source').get('name'),
total_due=prop.get('quote').get('totalDue'),
total_refundables=prop.get(
'quote').get('totalRefundableFees'),
total_nonrefundables=prop.get(
'quote').get('totalNonrefundableFees'),
reference_id=prop.get('referenceId'),
)
print(
f"Added obj {prop.get('key')}")
except AttributeError as error:
print(f"{error} attribute is null or owner booking")
url = r.json().get('next')
print(r.json().get('next'))
print(len(props_data))
end_time = time.time()
duration = (end_time - start_time)
print(duration)
looping_api(url, headers)

How to sort a list of restaurant names by restaurant rating (possibly from Google Places or Yelp Fusion API)

I have a csv file with thousands of restaurant names and addresses that I need to sort by rating (data that is not in the csv). Is there a way to fill in the csv with this data? Possibly with Google Places API or Yelp Fusion API?
Both the Google Places API and Yelp Fusion API let you obtain a restaurant’s rating if you query with the business name and address. I’m going to explain how to do this but, first a caution about compliance. What you describe is clearly against the terms of service for both APIs. The only permitted use of their data is to display it on a publicly available website or app. Fetching and retaining it in a csv file is clearly improper. The APIs are intended for real-time query and immediate display of results for your users.
Google requires that the Places data be displayed in conjunction with a Google map or an approved "powered by Google" image. Additionally, no "pre-fetching, caching, or storage of content" is permitted. For details see https://developers.google.com/places/web-service/policies
Yelp requires attribution, basically requiring you to display the star rating and the Yelp logo with a link back to the business page on Yelp for the restaurant you have queried. See https://www.yelp.com/developers/display_requirements Furthermore, you can’t “cache, record, pre-fetch, or otherwise store any portion of the Yelp Content for a period longer than twenty-four (24) hours from receipt of the Yelp Content, or attempt or provide a means to execute any scraping or "bulk download" operations.” For full text and terms see https://www.yelp.com/developers/api_terms
With the legalese out of the way, here’s how to request a restaurant’s rating from Google Places:
https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=Applebees,234 W 42nd St,New York,NY&inputtype=textquery&fields=formatted_address,name,rating&key=YOUR_API_KEY
And, the JSON response:
{
"candidates": [
{
"formatted_address": "234 W 42nd St, New York, NY 10036, USA",
"name": "Applebee's Grill + Bar",
"rating": 3.6
}
],
"status": "OK"
}
Here is the same request for Yelp Fusion. There is no way to request just the rating. Results always contain everything in their database for the restaurant:
https://api.yelp.com/v3/businesses/search?term=applebees&location=234 W 42nd St,New York,NY&limit=1
JSON response:
{
"businesses": [
{
"id": "gytFjzBw-z5LZD-6JSMChg",
"alias": "applebees-grill-bar-new-york-3",
"name": "Applebee's Grill + Bar",
"image_url": "https://s3-media1.fl.yelpcdn.com/bphoto/CLizyj9S7pMvwGNm2dgdiQ/o.jpg",
"is_closed": false,
"url": "https://www.yelp.com/biz/applebees-grill-bar-new-york-3?adjust_creative=pnOv3Zj2REsNDMU4Z3-SLg&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=pnOv3Zj2REsNDMU4Z3-SLg",
"review_count": 444,
"categories": [
{
"alias": "tradamerican",
"title": "American (Traditional)"
},
{
"alias": "burgers",
"title": "Burgers"
},
{
"alias": "sportsbars",
"title": "Sports Bars"
}
],
"rating": 2,
"coordinates": {
"latitude": 40.756442,
"longitude": -73.988838
},
"transactions": [
"delivery",
"pickup"
],
"price": "$$",
"location": {
"address1": "234 W 42nd St",
"address2": "",
"address3": "",
"city": "New York",
"zip_code": "10036",
"country": "US",
"state": "NY",
"display_address": [
"234 W 42nd St",
"New York, NY 10036"
]
},
"phone": "+12123917414",
"display_phone": "(212) 391-7414",
"distance": 5.938732504864397
}
],
"total": 2900,
"region": {
"center": {
"longitude": -73.98880004882812,
"latitude": 40.75648701137637
}
}
}

Wikipedia API cloud of confusion: `list` vs `generator` vs `search`

My goal is to write an API search of Wikipedia that will:
Return pages only in the category "English language films"
Of those, return pages only beginning with the letters "Avatar" (or anything, really, just using those letters for an example)
Of those, give me the url, the title, the date, a summary, and the main page image.
So far I've tried three things, none of which seem to be able to do exactly what I want.
PROBLEM: list=allpages is just generally useless
Here's a search with list=allpages:
https://en.wikipedia.org/w/api.php?action=query&format=json&prop=info%7Cpageimages%7Cextracts&list=allpages&inprop=url%7Cdisplaytitle&piprop=name%7Cthumbnail%7Coriginal&pithumbsize=100&exintro=1&explaintext=1&apprefix=Avatar&aplimit=3
Here's the result (just the first 3 pages):
{
"batchcomplete": "",
"continue": {
"apcontinue": "Avatar,_The_Last_Airbender",
"continue": "-||info|pageimages|extracts"
},
"query": {
"allpages": [
{
"pageid": 100368,
"ns": 0,
"title": "Avatar"
},
{
"pageid": 4846971,
"ns": 0,
"title": "Avatar's Abode"
},
{
"pageid": 35243953,
"ns": 0,
"title": "Avatar, Iran"
}
]
}
}
As you can see, it basically ignored all my prop requests.
PROBLEM: generator=allpages can't search by category
Here's a search using generator-allpages:
https://en.wikipedia.org/w/api.php?action=query&format=json&prop=info%7Cpageimages%7Cextracts&generator=allpages&inprop=url%7Cdisplaytitle&piprop=name%7Cthumbnail%7Coriginal&pithumbsize=100&exintro=1&explaintext=1&gapprefix=Avatar
Here's the output from that (just the first result):
{
"batchcomplete": "",
"continue": {
"gapcontinue": "Avatar's_Abode",
"continue": "gapcontinue||"
},
"query": {
"pages": {
"100368": {
"pageid": 100368,
"ns": 0,
"title": "Avatar",
"contentmodel": "wikitext",
"pagelanguage": "en",
"pagelanguagehtmlcode": "en",
"pagelanguagedir": "ltr",
"touched": "2018-05-03T11:21:07Z",
"lastrevid": 838959509,
"length": 45784,
"fullurl": "https://en.wikipedia.org/wiki/Avatar",
"editurl": "https://en.wikipedia.org/w/index.php?title=Avatar&action=edit",
"canonicalurl": "https://en.wikipedia.org/wiki/Avatar",
"displaytitle": "Avatar",
"thumbnail": {
"source": "https://upload.wikimedia.org/wikipedia/commons/thumb/a/a0/Avatars.jpg/80px-Avatars.jpg",
"width": 80,
"height": 100
},
"original": {
"source": "https://upload.wikimedia.org/wikipedia/commons/a/a0/Avatars.jpg",
"width": 357,
"height": 448
},
"pageimage": "Avatars.jpg",
"extract": "An avatar (Sanskrit: \u0905\u0935\u0924\u093e\u0930, IAST: avat\u0101ra), a concept in Hinduism that means \"descent\", refers to the material appearance or incarnation of a deity on earth. The relative verb to \"alight, to make one's appearance\" is sometimes used to refer to any guru or revered human being.\nThe word avatar does not appear in the Vedic literature, but appears in verb forms in post-Vedic literature, and as a noun particularly in the Puranic literature after the 6th century CE. Despite that, the concept of an avatar is compatible with the content of the Vedic literature like the Upanishads as it is symbolic imagery of the Saguna Brahman concept in the philosophy of Hinduism. The Rigveda describes Indra as endowed with a mysterious power of assuming any form at will. The Bhagavad Gita expounds the doctrine of Avatara but with terms other than avatar.\nTheologically, the term is most often associated with the Hindu god Vishnu, though the idea has been applied to other deities. Varying lists of avatars of Vishnu appear in Hindu scriptures, including the ten Dashavatara of the Garuda Purana and the twenty-two avatars in the Bhagavata Purana, though the latter adds that the incarnations of Vishnu are innumerable. The avatars of Vishnu are important in Vaishnavism theology. In the goddess-based Shaktism tradition of Hinduism, avatars of the Devi in different appearances such as Tripura Sundari, Durga and Kali are commonly found. While avatars of other deities such as Ganesha and Shiva are also mentioned in medieval Hindu texts, this is minor and occasional. The incarnation doctrine is one of the important differences between Vaishnavism and Shaivism traditions of Hinduism.\nIncarnation concepts similar to avatar are also found in Buddhism, Christianity and others. The scriptures of Sikhism include the names of numerous Hindu gods and goddesses, but it rejected the doctrine of savior incarnation and endorsed the view of Hindu Bhakti movement saints such as Namdev that formless eternal god is within the human heart and man is his own savior."
}
}
}
}
...and it's so close to perfect that I can't believe it... the only problem is there's no way to restrict the search to the category "English-language films".
PROBLEM: generator=categorymember won't show page images and doesn't filter by prefix, only sets start point by prefix
Here's a search using generator=categorymember:
https://en.wikipedia.org/w/api.php?action=query&format=json&prop=pageimages&generator=categorymembers&piprop=name%7Cthumbnail%7Coriginal&pithumbsize=100&gcmtitle=Category%3AEnglish-language%20films&gcmprop=&gcmtype=page&gcmlimit=10&gcmstartsortkeyprefix=Avatar
Here's the first ten results (I've left the prop=extract and prop=info parameters off--they're working fine--so you can see just the relevant detail):
{
"batchcomplete": "",
"continue": {
"gcmcontinue": "page|2953314335314b4d04354b394141011201dcbedc08|47013432",
"continue": "gcmcontinue||"
},
"query": {
"pages": {
"4273140": {
"pageid": 4273140,
"ns": 0,
"title": "Avatar (2009 film)"
},
"15945267": {
"pageid": 15945267,
"ns": 0,
"title": "Avatar (2004 film)"
},
"25813358": {
"pageid": 25813358,
"ns": 0,
"title": "Avatar 2"
},
"27442998": {
"pageid": 27442998,
"ns": 0,
"title": "Avatar 3"
},
"50071841": {
"pageid": 50071841,
"ns": 0,
"title": "Ave Maria (1918 film)"
},
"41748079": {
"pageid": 41748079,
"ns": 0,
"title": "Avenged (2013 U.S. film)"
},
"42739169": {
"pageid": 42739169,
"ns": 0,
"title": "Avenger (film)"
},
"50726142": {
"pageid": 50726142,
"ns": 0,
"title": "The Avenger (1931 film)"
},
"43707905": {
"pageid": 43707905,
"ns": 0,
"title": "The Avengers (1950 film)"
},
"22114132": {
"pageid": 22114132,
"ns": 0,
"title": "The Avengers (2012 film)"
}
}
}
}
And as you can see:
The pageimages data is nowhere to be seen
The setting gcmstartsortkeyprefix=Avatar only sets the point from which the listing starts, it doesn't actually filter out results that don't have that prefix. There's no analogue to the gapprefix parameter that's available when using generator-allpages.
PROBLEM: list=search won't show any prop values and searches by content as well as title
Here's a search using list=search, an avenue of approach I'm grateful to this page for:
https://en.wikipedia.org/w/api.php?action=query&format=jsonfm&prop=info%7Cpageimages%7Cextracts&list=search&inprop=url%7Cdisplaytitle&piprop=name%7Cthumbnail%7Coriginal&pithumbsize=100&exintro=1&explaintext=1&srsearch=Avatar+incategory:English-language_films&srlimit=3
And here's the return (just the first 3 results):
{
"batchcomplete": "",
"continue": {
"sroffset": 3,
"continue": "-||info|pageimages|extracts"
},
"query": {
"searchinfo": {
"totalhits": 224
},
"search": [
{
"ns": 0,
"title": "Avatar (2009 film)",
"pageid": 4273140,
"size": 201954,
"wordcount": 18643,
"snippet": "<span class=\"searchmatch\">Avatar</span>, marketed as James Cameron's <span class=\"searchmatch\">Avatar</span>, is a 2009 American epic science fiction film directed, written, produced, and co-edited by James Cameron, and",
"timestamp": "2018-05-01T01:52:00Z"
},
{
"ns": 0,
"title": "Avatar 2",
"pageid": 25813358,
"size": 55754,
"wordcount": 5380,
"snippet": "<span class=\"searchmatch\">Avatar</span> 2 is an upcoming American epic science fiction film directed, produced, and co-written by James Cameron, and the first of four planned sequels to",
"timestamp": "2018-05-02T10:02:34Z"
},
{
"ns": 0,
"title": "Avatar 3",
"pageid": 27442998,
"size": 17747,
"wordcount": 1374,
"snippet": "<span class=\"searchmatch\">Avatar</span> 3 is an upcoming 2021 American epic science fiction film directed, produced, co-written, and co-edited by James Cameron, scheduled to be released",
"timestamp": "2018-05-02T10:02:45Z"
}
]
}
}
Now this search does define prop=info and prop=images and prop=extracts, but they're nowhere to be seen. Plus there's also no analogue to gapprefix with this approach.
PROBLEM: generator=search won't show pageimages and searches by content as well as title
Here's the same search as above, but using generator=search:
https://en.wikipedia.org/w/api.php?action=query&format=jsonfm&prop=info%7Cpageimages%7Cextracts&generator=search&inprop=url%7Cdisplaytitle&piprop=name%7Cthumbnail%7Coriginal&pithumbsize=100&exintro=1&explaintext=1&gsrsearch=Avatar+incategory:English-language_films&gsrlimit=3
And here's the result:
{
"batchcomplete": "",
"continue": {
"gsroffset": 3,
"continue": "gsroffset||"
},
"query": {
"pages": {
"4273140": {
"pageid": 4273140,
"ns": 0,
"title": "Avatar (2009 film)",
"index": 1,
"contentmodel": "wikitext",
"pagelanguage": "en",
"pagelanguagehtmlcode": "en",
"pagelanguagedir": "ltr",
"touched": "2018-05-01T01:52:00Z",
"lastrevid": 839068297,
"length": 201954,
"fullurl": "https://en.wikipedia.org/wiki/Avatar_(2009_film)",
"editurl": "https://en.wikipedia.org/w/index.php?title=Avatar_(2009_film)&action=edit",
"canonicalurl": "https://en.wikipedia.org/wiki/Avatar_(2009_film)",
"displaytitle": "<i>Avatar</i> (2009 film)",
"extract": "Avatar, marketed as James Cameron's Avatar, is a 2009 American epic science fiction film directed, written, produced, and co-edited by James Cameron, and starring Sam Worthington, Zoe Saldana, Stephen Lang, Michelle Rodriguez, and Sigourney Weaver. The film is set in the mid-22nd century, when humans are colonizing Pandora, a lush habitable moon of a gas giant in the Alpha Centauri star system, in order to mine the mineral unobtanium, a room-temperature superconductor. The expansion of the mining colony threatens the continued existence of a local tribe of Na'vi \u2013 a humanoid species indigenous to Pandora. The film's title refers to a genetically engineered Na'vi body with the mind of a remotely located human that is used to interact with the natives of Pandora.\nDevelopment of Avatar began in 1994, when Cameron wrote an 80-page treatment for the film. Filming was supposed to take place after the completion of Cameron's 1997 film Titanic, for a planned release in 1999, but, according to Cameron, the necessary technology was not yet available to achieve his vision of the film. Work on the language of the film's extraterrestrial beings began in 2005, and Cameron began developing the screenplay and fictional universe in early 2006. Avatar was officially budgeted at $237 million. Other estimates put the cost between $280 million and $310 million for production and at $150 million for promotion. The film made extensive use of new motion capture filming techniques, and was released for traditional viewing, 3D viewing (using the RealD 3D, Dolby 3D, XpanD 3D, and IMAX 3D formats), and for \"4D\" experiences in select South Korean theaters. The stereoscopic filmmaking was touted as a breakthrough in cinematic technology.\nAvatar premiered in London on December 10, 2009, and was internationally released on December 16 and in the United States and Canada on December 18, to positive critical reviews, with critics highly praising its groundbreaking visual effects. During its theatrical run, the film broke several box office records and became the highest-grossing film of all time, as well as in the United States and Canada, surpassing Cameron's Titanic, which had held those records for twelve years. It also became the first film to gross more than $2 billion and the best-selling film of 2010 in the United States. Avatar was nominated for nine Academy Awards, including Best Picture and Best Director, and won three, for Best Art Direction, Best Cinematography and Best Visual Effects. Following the film's success, Cameron signed with 20th Century Fox to produce four sequels: Avatar 2 and Avatar 3 are currently filming, and will be released on December 18, 2020, and December 17, 2021 respectively; subsequent sequels will start shooting as soon as they wrap filming, and will be released in 2024 and 2025. Several cast members are expected to return, including Worthington, Saldana, Lang, and Weaver."
},
"25813358": {
"pageid": 25813358,
"ns": 0,
"title": "Avatar 2",
"index": 2,
"contentmodel": "wikitext",
"pagelanguage": "en",
"pagelanguagehtmlcode": "en",
"pagelanguagedir": "ltr",
"touched": "2018-05-02T10:02:34Z",
"lastrevid": 839266311,
"length": 55754,
"fullurl": "https://en.wikipedia.org/wiki/Avatar_2",
"editurl": "https://en.wikipedia.org/w/index.php?title=Avatar_2&action=edit",
"canonicalurl": "https://en.wikipedia.org/wiki/Avatar_2",
"displaytitle": "<i>Avatar 2</i>",
"extract": "Avatar 2 is an upcoming American epic science fiction film directed, produced, and co-written by James Cameron, and the first of four planned sequels to his film Avatar (2009). Cameron is producing the film with Jon Landau, with Josh Friedman originally announced as his co-writer; it was later announced that Cameron, Friedman, Rick Jaffa, Amanda Silver, and Shane Salerno took a part in the writing process of all sequels before being attributed separate scripts, making the eventual writing credits unclear. Cast members Sam Worthington, Zoe Saldana, Stephen Lang, Sigourney Weaver, Giovanni Ribisi, Joel David Moore, Dileep Rao, C. C. H. Pounder, and Matt Gerald are all expected to return.\nCameron, who had stated in 2006 that he would like to make sequels to Avatar if it were successful, announced the first two in 2010 following the widespread success of the first film, with Avatar 2 aiming for a 2014 release. However, the subsequent addition of two more sequels, and the necessity to develop new technology in order to film performance capture scenes underwater, a feature never accomplished before in motion capture history, led to significant delays to allow the crew more time to work on the writing, pre-production, and visual effects; it is currently planned for a release on December 18, 2020, exactly eleven years after the American release of the first film, with the following sequels to be released between 2021 and 2025.\nPreliminary shooting for the film started in Manhattan Beach, California on August 15, 2017, followed by principal photography simultaneously with Avatar 3 in New Zealand on September 25, 2017. The other sequels are expected to start shooting as soon as Avatar 2 and 3's filming wraps."
},
"27442998": {
"pageid": 27442998,
"ns": 0,
"title": "Avatar 3",
"index": 3,
"contentmodel": "wikitext",
"pagelanguage": "en",
"pagelanguagehtmlcode": "en",
"pagelanguagedir": "ltr",
"touched": "2018-05-02T10:02:45Z",
"lastrevid": 839266333,
"length": 17747,
"fullurl": "https://en.wikipedia.org/wiki/Avatar_3",
"editurl": "https://en.wikipedia.org/w/index.php?title=Avatar_3&action=edit",
"canonicalurl": "https://en.wikipedia.org/wiki/Avatar_3",
"displaytitle": "<i>Avatar 3</i>",
"extract": "Avatar 3 is an upcoming 2021 American epic science fiction film directed, produced, co-written, and co-edited by James Cameron, scheduled to be released on December 17, 2021. It is the second of four planned sequels to his film Avatar (2009), and will be a follow-up to Avatar 2 (2020). Cameron is producing the film with Jon Landau, with Rick Jaffa and Amanda Silver originally announced as his co-writers; it was later announced that Cameron, Jaffa, Silver, Josh Friedman and Shane Salerno took a part in the writing process of all of the sequels before being assigned to finish the separate scripts, making the eventual writing credits unclear. Cast members Sam Worthington, Zoe Saldana, Stephen Lang, Sigourney Weaver, Joel David Moore, CCH Pounder and Matt Gerald are all expected to return from the first two films.\nAvatar 3 started shooting simultaneously with Avatar 2 on August 15, 2017. Two additional sequels will start shooting as soon as the first two wrap post-production, and are expected to be released in 2024 and 2025 respectively."
}
}
}
}
...and again this one is so close to perfect, because in this version it does return the prop=info and prop=extracts results, but again it ignores prop=pageimages and I can't find any way to restrict the search to the starting letters of the titles.
Conclusion: SNAFU
...Is there any 'one search to rule them all' here? It's so tantalizing that I can almost, almost, almost get everything with one query, but in the end I can't figure out how to get 'em all. Can anyone help me through the thicket?
On a high level, list modules generate some list of pages (e.g. the pages most recently edited). Sometimes they include some additional information but mostly they are just meant to give you a list of pages. Prop modules operate on a list of pages and add some kind of extra information to each; the list can be determined by the client (via parameters like titles or pageids) or a list module (used as generator= instead of list=). You can use list= and prop= "together" but all that does is create two separate lists (one of which will be empty and not shown because there is no titles or generator parameter).
Your generator queries are fine; you'll need pilicense=any if you want non-free images in the output. Maybe you found some outdated documentation that does not mention that?
You can use intitle:... in the search term for title search (see docs).

Exclude The Links From The Navigation Templates

I know that I'm able to get the links to an article using this in my API request.
My problem is regarding the cases of inclusion. By asking for the links to a specific article, I'm also getting the links in all of the navigation templates which are included at the bottom of the article.
For example, after asking for the links to this article:
https://en.wikipedia.org/w/api.php?action=query&titles=St%C3%A9phane_Sess%C3%A8gnon&prop=linkshere
I'm also getting the links which appear at the bottom of the page, in the navigation templates:
I'm building an app which uses the mobile version of Wikipedia, so the navigation templates at the bottom of the pages are not relevant for my goal, because they are not shown in the mobile version.
I'd like to exclude those links from the result someway. I want to get only the links which actually appears in an article body, or at least detect whether they are from a template or not. Is this possible?
Are you aware that there is a mobile API? It does various transformations on the article to make it more appropriate for small-screen devices, including the removal of most navigation templates. For example:
https://en.wikipedia.org/api/rest_v1/page/mobile-sections/Fort_Horsted
{
"lead": {
"ns": 0,
"id": 35265226,
"revision": "803745099",
"lastmodified": "2017-10-04T10:37:41Z",
"lastmodifier": {
"user": "InternetArchiveBot",
"gender": "unknown"
},
"displaytitle": "Fort Horsted",
"normalizedtitle": "Fort Horsted",
"wikibase_item": "Q5471353",
"protection": {},
"editable": true,
"languagecount": 0,
"image": {
"file": "The_British_Army_in_the_United_Kingdom_1939-45_H5865.jpg",
"urls": {
"320": "https://upload.wikimedia.org/wikipedia/commons/e/e1/The_British_Army_in_the_United_Kingdom_1939-45_H5865.jpg",
"640": "https://upload.wikimedia.org/wikipedia/commons/e/e1/The_British_Army_in_the_United_Kingdom_1939-45_H5865.jpg",
"800": "https://upload.wikimedia.org/wikipedia/commons/e/e1/The_British_Army_in_the_United_Kingdom_1939-45_H5865.jpg",
"1024": "https://upload.wikimedia.org/wikipedia/commons/e/e1/The_British_Army_in_the_United_Kingdom_1939-45_H5865.jpg"
}
},
"hatnotes": [],
"geo": {
"latitude": 51.358,
"longitude": 0.513
},
"sections": [
{
"id": 0,
"text": "<span><p><b>Fort Horsted</b> is a scheduled monument (Monument Number 416040) that lies in the Horsted Valley to the South of Chatham, Kent, England. It is a late 19th-century Land Fort, and one of six constructed around Chatham and Gillingham, Kent to protect HM Dockyard Chatham from attack. Originally proposed in the Royal Commission on the Defence of the United Kingdom Report, published in 1860, it and the other land defences were omitted as part of general cost cutting with only the coastal defences on the River Medway being retained and completed under the original 1860 proposals. It was not until the mid-1870s that a revised program was accepted, which included the construction of a convict prison at Borstal, Rochester, to provide low cost labour for the construction of a line of four forts, Fort Borstal, Fort Bridgewood, Fort Horsted and Fort Luton (a further three forts were constructed with the use of convict labour). Its construction started in 1879 and was complete by 1889 after much delay.</p></span><figure class=\"mw-default-size\" id=\"mwAg\"><img src=\"//upload.wikimedia.org/wikipedia/commons/thumb/e/e1/The_British_Army_in_the_United_Kingdom_1939-45_H5865.jpg/220px-The_British_Army_in_the_United_Kingdom_1939-45_H5865.jpg\" data-file-type=\"bitmap\" height=\"163\" width=\"220\" srcset=\"//upload.wikimedia.org/wikipedia/commons/thumb/e/e1/The_British_Army_in_the_United_Kingdom_1939-45_H5865.jpg/440px-The_British_Army_in_the_United_Kingdom_1939-45_H5865.jpg 2x, //upload.wikimedia.org/wikipedia/commons/thumb/e/e1/The_British_Army_in_the_United_Kingdom_1939-45_H5865.jpg/330px-The_British_Army_in_the_United_Kingdom_1939-45_H5865.jpg 1.5x\"><figcaption>A QF 12-pounder 12 cwt AA gun mounted on Albion BY-series truck, December 1940</figcaption></figure>\n<p class=\"skipped\"><span style=\"font-size: small;\"></span></p>\n\n\n\n"
},
{
"id": 1,
"toclevel": 1,
"anchor": "Materials",
"line": "Materials"
},
{
"id": 2,
"toclevel": 1,
"anchor": "Armaments",
"line": "Armaments"
},
{
"id": 3,
"toclevel": 1,
"anchor": "World_wars",
"line": "World wars"
},
{
"id": 4,
"toclevel": 1,
"anchor": "The_name",
"line": "The name"
},
{
"id": 5,
"toclevel": 1,
"anchor": "The_fort_today",
"line": "The fort today"
},
{
"id": 6,
"toclevel": 1,
"anchor": "References",
"line": "References"
},
{
"id": 7,
"toclevel": 1,
"anchor": "External_links",
"line": "External links"
}
]
},
"remaining": {
"sections": [
{
"id": 1,
"text": "\n<p>The fort was constructed almost entirely of concrete, topped with chalk and earth with no visible concrete exposed from the outside, except from the gorge or rear of the fort. The ditch was protected by two single and one double counterscarp galleries.</p>\n\n",
"toclevel": 1,
"line": "Materials",
"anchor": "Materials"
},
{
"id": 2,
"text": "\n<p>Although the original plans of the fort proposed fixed armament, by its completion there had been a shift away from fixed armament to moveable guns. The fort would not been armed, unless actual threat materialised and then with moveable field artillery. In the event of actual invasion and an attack on HM Dockyard Chatham, additional field defence would have augmented the forts, with trenches and battery positions. In fact in 1907 during summer manoeuvres such defences were probably constructed.</p>\n\n",
"toclevel": 1,
"line": "Armaments",
"anchor": "Armaments"
},
{
"id": 3,
"text": "\n<p>Deemed to have become obsolete by 1910, the fort formed part of Chatham's land defences in both World Wars. In World War I brick emplacements and a pillbox were built on the ramparts, and fixed anti-aircraft guns of an early type were installed (possibly 12pdr coastal defence guns on improvised high angle mountings, not be confused with the later naval version).</p>\n\n",
"toclevel": 1,
"line": "World wars",
"anchor": "World_wars"
},
{
"id": 4,
"text": "\n<p>The fort was named after a local hamlet. Horsted is speculated to have been named after the legendary Saxon warrior Horsa, who was killed at nearby Aylesford while fighting the Britons.<span class=\"mw-ref\" id=\"cite_ref-1\"><span class=\"mw-reflink-text\">[1]</span></span></p>\n\n",
"toclevel": 1,
"line": "The name",
"anchor": "The_name"
},
{
"id": 5,
"text": "\n<p>The fort survives relatively intact and is currently in use as a business park. While it is in relatively good condition, its commercial use has seen some new construction and modification which has seen the significant loss of the original structure and features.</p>\n\n",
"toclevel": 1,
"line": "The fort today",
"anchor": "The_fort_today"
},
{
"id": 6,
"text": "\n<div class=\"mw-references-wrap\"><ol class=\"mw-references references\"><li id=\"cite_note-1\"> <span id=\"mw-reference-text-cite_note-1\" class=\"mw-reference-text\"><cite class=\"citation web\" id=\"mwLA\"><a rel=\"mw:ExtLink\" href=\"https://www.britannica.com/topic/Hengist\" class=\"external\">\"Hengist and Horsa\"</a>. Encyclopædia Britannica.</cite></span></li></ol></div>\n\n\n",
"toclevel": 1,
"line": "References",
"anchor": "References",
"isReferenceSection": true
},
{
"id": 7,
"text": "\n<ul><li> <a rel=\"mw:ExtLink\" href=\"http://www.ecastles.co.uk/chatham.html\" class=\"external\">Map of Chatham's defences</a></li>\n<li> <a rel=\"mw:ExtLink\" href=\"http://www.forthorsted.co.uk/content/history\" class=\"external\">Fort Horsted website history page</a></li>\n<li> <a rel=\"mw:ExtLink\" href=\"https://web.archive.org/web/20120410012117/http://www.undergroundkent.co.uk/fort_horsted.htm\" class=\"external\">Fort Horsted on the Underground Kent website</a> Dead Link</li>\n<li> <a rel=\"mw:ExtLink\" href=\"http://www.pastscape.org.uk/hob.aspx?hob_id=416040&sort=2&type=&rational=a&class1=1&period=None&county=693349&district=786118&parish=None&place=chatham&recordsperpage=10&source=text&rtype=&rnumber=&p=2&move=n&nor=39&recfc=0\" class=\"external\">Pastscape Record Fort Horstead</a></li></ul>\n\n<div role=\"navigation\" class=\"navbox\" aria-labelledby=\"Forts_in_Medway\" style=\"padding:3px\"><table class=\"nowraplinks collapsible autocollapse navbox-inner\" style=\"border-spacing:0;background:transparent;color:inherit\"><tbody><tr><th scope=\"col\" class=\"navbox-title\" colspan=\"2\" style=\"background:lightsteelblue;\"><div class=\"plainlinks hlist navbar mini\"><ul><li class=\"nv-view\"><abbr style=\";background:lightsteelblue;;background:none transparent;border:none;-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none;\">v</abbr></li><li class=\"nv-talk\"><abbr style=\";background:lightsteelblue;;background:none transparent;border:none;-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none;\">t</abbr></li><li class=\"nv-edit\"><a rel=\"mw:ExtLink\" href=\"//en.wikipedia.org/w/index.php?title=Template:Defences_of_medway&action=edit\" class=\"external\"><abbr style=\";background:lightsteelblue;;background:none transparent;border:none;-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none;\">e</abbr></a></li></ul></div><div id=\"Forts_in_Medway\" style=\"font-size:114%;margin:0 4em\">Forts in Medway</div></th></tr><tr><td colspan=\"2\" class=\"navbox-list navbox-odd hlist\" style=\"width:100%;padding:0px\"><div style=\"padding:0em 0.25em\">\n<dl><dt>Medieval</dt>\n<dd> Rochester Castle</dd></dl>\n\n<dl><dt>Tudor</dt>\n<dd> Upnor Castle</dd></dl>\n\n<dl><dt>17th century</dt>\n<dd> Cockham Wood Fort</dd>\n<dd> Fort Gillingham</dd></dl>\n\n<dl><dt>Inner Ring <span style=\"font-weight:normal;\">(Napoleonic)</span></dt>\n<dd> Fort Clarence</dd>\n<dd> Fort Pitt</dd>\n<dd> Fort Amherst</dd></dl>\n\n<dl><dt>Outer Ring <span style=\"font-weight:normal;\">(Palmerston)</span></dt>\n<dd> Fort Borstal</dd>\n<dd> Fort Bridgewood</dd>\n<dd> Fort Darland</dd>\n<dd> Fort Horsted</dd>\n<dd> Fort Luton</dd>\n<dd> Grange Redoubt</dd>\n<dd> Woodlands Redoubt</dd>\n<dd> Fort Hoo</dd>\n<dd> Fort Darnet</dd></dl>\n</div></td></tr></tbody></table></div>\n\n",
"toclevel": 1,
"line": "External links",
"anchor": "External_links"
}
]
}
}
(The response for Stéphane Sessègnon would be too large to include here.)
If you really just want the links, and only non-template ones, I don't think that's available. You can parse it yourself, using something like mwparserfromhell

How to get API.AI simply send me the JSON data of the conversation?

I am trying to understand if there is an option to get the conversation logs of the discussions with some sort of a webhook.
The API.AI docs only refer to using webhook for fulfilment purposes , but for now I don't plan my server (GCP ENGINE APP) to supply fulfilment but only to log the relevant parameters from each conversation.
Anyone knows how to approach this?
Turn on the webhook feature for the intent. You will be able to get the requests and all the data associated with it. You will be able to send back to API.AI too. Here is the full circle:
{
"id": "891db09a-851c-43dc-81c6-4c6705c94f85",
"timestamp": "2017-01-03T10:31:18.676Z",
"result": {
"source": "agent",
"resolvedQuery": "yes, France",
"action": "show.news",
"actionIncomplete": false,
"parameters": {
"adjective": "",
"subject": "France"
},
"contexts": [
{
"name": "subject",
"parameters": {
"subject.original": "France",
"adjective": "",
"subject": "France",
"adjective.original": ""
},
"lifespan": 5
},
{
"name": "region",
"parameters": {
"subject.original": "France",
"adjective": "",
"subject": "France",
"adjective.original": ""
},
"lifespan": 5
}
],
"metadata": {
"intentId": "34773849-4ac2-4e28-95a5-7abfc061044e",
"webhookUsed": "true",
"webhookForSlotFillingUsed": "false",
"intentName": "subject"
},
"fulfillment": {
"speech": "Here is the latest news\n\n According to Watson the main emotion expressed in the article is: ;( ( sadness )\n\n Son of Equatorial Guinea’s president facing trial in France\n\nPARIS — After years of investigation, France on Monday put the son of the president of Equatorial Guinea on trial for corruption, charged with spending many millions in state funds — much of it allegedly in cash — to feed an opulent lifestyle of fast cars, designer clothes, works of art and...\n\nRead more: https://www.washingtonpost.com/world/europe/son-of-equatorial-guineas-president-facing-trial-in-france/2017/01/02/b03d30d0-d0cb-11e6-9651-54a0154cf5b3_story.html",
"source": "Washington Post",
"displayText": "Here is the latest news. According to Watson the main emotion expressed in the article is: sadness",
"messages": [
{
"type": 0,
"speech": "Here is the latest news\n\n According to Watson the main emotion expressed in the article is: ;( ( sadness )\n\n Son of Equatorial Guinea’s president facing trial in France\n\nPARIS — After years of investigation, France on Monday put the son of the president of Equatorial Guinea on trial for corruption, charged with spending many millions in state funds — much of it allegedly in cash — to feed an opulent lifestyle of fast cars, designer clothes, works of art and...\n\nRead more: https://www.washingtonpost.com/world/europe/son-of-equatorial-guineas-president-facing-trial-in-france/2017/01/02/b03d30d0-d0cb-11e6-9651-54a0154cf5b3_story.html"
}
],
"data": {
"newsAgent": {
"adjective": "",
"subject": "France",
"intent": "subject",
"action": "show.news",
"news": {
"title": "Son of Equatorial Guinea’s president facing trial in France",
"source": "Washington Post",
"link": "https://www.washingtonpost.com/world/europe/son-of-equatorial-guineas-president-facing-trial-in-france/2017/01/02/b03d30d0-d0cb-11e6-9651-54a0154cf5b3_story.html",
"language": "english",
"body": "PARIS — After years of investigation, France on Monday put the son of the president of Equatorial Guinea on trial for corruption, charged with spending many millions in state funds — much of it allegedly in cash — to feed an opulent lifestyle of fast cars, designer clothes, works of art and...",
"emotion": "sadness",
"emoticon": ";("
},
"speech": "Here is the latest news",
"sessionId": "0856125a-d0bc-4cba-990d-cbcfaea536db"
}
}
},
"score": 1
},
"status": {
"code": 206,
"errorType": "partial_content",
"errorDetails": "Webhook call failed. Error message: Webhook contains contexts with empty names or names containing whitespaces. ErrorId: 131000fa-0ec1-4efb-b47c-64301ac7bb2b"
},
"sessionId": "0856125a-d0bc-4cba-990d-cbcfaea536db"
}
The result object is the request that API.AI sends you, you get the contexts objects as well.
The fulfilment object is the response my endpoint sent back to API.AI
Check the documentation