Setting up Continuous export of API data to csv for Racing lap times - api

Have access to an API that provides data for racing, including driver names, and their last lap, best lap.. etc. Completely new to coding but learning the ropes. This is an example of an output from the API.
"Successful": true,
"Session": {
"RunNumber": "47",
"SessionName": "KART DRIVERS - EXPERIENCE / PROVA 11 22:30",
"TrackName": "KGV RACE TRACKS - CIRCUITO 109",
"TrackLength": "0.725",
"CurrentTime": "23:05:24",
"SessionTime": "00:13:27",
"TimeToGo": "00:04:32",
"LapsToGo": "9999",
"FlagStatus": "Green",
"SortMode": "race",
"Classes": {
"1": {
"ClassID": "1",
"Description": "RENTAL"
}
},
"Competitors": {
"018": {
"RacerID": "018",
"Number": "018",
"Transponder": "02",
"FirstName": "LR",
"LastName": "",
"Nationality": "",
"AdditionalData": "",
"ClassID": "1",
"Position": "28",
"Laps": "8",
"TotalTime": "00:12:34.376",
"BestPosition": "26",
"BestLap": "8",
"BestLapTime": "00:01:09.158",
"LastLapTime": "00:01:09.158"
},
"043": {
"RacerID": "043",
"Number": "043",
"Transponder": "48",
"FirstName": "LORENZO",
"LastName": "",
"Nationality": "",
"AdditionalData": "",
"ClassID": "1",
"Position": "32",
"Laps": "5",
"TotalTime": "00:12:54.095",
"BestPosition": "32",
"BestLap": "4",
"BestLapTime": "00:01:38.740",
"LastLapTime": "00:02:39.277"
How would I go about reading data from this api every 30 seconds to 1 minute, and exporting that data into a CSV to put on excel?

Related

Get nested data c.<type>.<type> in SQL Query?

I've been searching everywhere for this seemingly simple action: I'd like to select only a certain few data type from a nested source.
The closest that I can get to the solution is this:
SELECT c.receipt_number, c.millitime, c.email, c.phone, c.shipping, c.shipping_note, c.amount_paid, i.description, i.quantity
FROM c
JOIN i IN c.line_items
WHERE c.millitime > 1627813253000
But this will create lots of duplicated data, like the receipt_number, email, etc in the example:
[
{
"receipt_number": null,
"millitime": 1627813377000,
"email": "test#gmail.com",
"phone": "000000000",
"shipping": {
"address": {
"city": "Sydney",
"country": "AU",
"line1": "Test Street",
"line2": null,
"postal_code": "3000",
"state": "VIC"
},
"name": "New Cust"
},
"shipping_note": "Please knock on door.",
"amount_paid": 104,
"description": "Curry Chicken",
"quantity": 1
},
{
"receipt_number": null,
"millitime": 1627813377000,
"email": "test#gmail.com",
"phone": "000000000",
"shipping": {
"address": {
"city": "Sydney",
"country": "AU",
"line1": "Test Street",
"line2": null,
"postal_code": "3000",
"state": "VIC"
},
"name": "New Cust"
},
"shipping_note": "Please knock on door.",
"amount_paid": 104,
"description": "Chicken Noodle",
"quantity": 8
}
]
Is there a way to create a nested result of c.line_items with just the desired data description and quantity? The final result should be similar to:
[
{
"receipt_number": null,
"millitime": 1627813377000,
"email": "test#gmail.com",
"phone": "000000000",
"shipping": {
"address": {
"city": "Sydney",
"country": "AU",
"line1": "Test Street",
"line2": null,
"postal_code": "3000",
"state": "VIC"
},
"name": "New Cust"
},
"shipping_note": "Please knock on door.",
"amount_paid": 104,
"line_items": [
{
"description": "Chicken Noodle",
"quantity": 8
},
{
"description": "Curry Chicken",
"quantity": 1
}
]
}
]
I have created the same in
You can use distinct keyword to remove duplicates from the results.
Add c.line_items to your select list and change i.description, i.quantity to c.description, c.quantity to add view under line_items.
Query:
SELECT distinct c.receipt_number, c.millitime, c.email, c.phone, c.shipping, c.shipping_note, c.amount_paid, c.line_items
FROM c
JOIN i IN c.line_items
WHERE c.millitime > 1627813253000
Result:
Reference: Azure Cosmos DB SQL query - JSON items

Strange prices from Amadeus

I am checking the Amadeus about flight tickets and a little confused about the prices that I get. I expected to see prices from Amadeus closer to airline website prices or a little cheaper. But, I see that prices are incredibly high. For example, I made the following request:
https://api.amadeus.com/v2/shopping/flight-offers?originLocationCode=SGN&destinationLocationCode=DAD&departureDate=2020-05-29&adults=1&nonStop=true&currencyCode=VND
Flight at Amadeus Price In USD Airline price in USD
11:45 ~70.41 ~38.72
13:50 ~70.41 ~34.43
18:00 ~70.41 ~42.93
Prices are higher significantly. Moreover, prices from Amadeus are the same for a lot of flights for the same air company.
Do I do something wrong or I skipped something?
PS: Response for first flight:
{
"type": "flight-offer",
"id": "1",
"source": "GDS",
"instantTicketingRequired": false,
"nonHomogeneous": false,
"oneWay": false,
"lastTicketingDate": "2020-05-29",
"numberOfBookableSeats": 4,
"itineraries": [{
"duration": "PT1H20M",
"segments": [{
"departure": {
"iataCode": "SGN",
"terminal": "1",
"at": "2020-05-29T11:15:00"
},
"arrival": {
"iataCode": "DAD",
"terminal": "1",
"at": "2020-05-29T12:35:00"
},
"carrierCode": "VJ",
"number": "628",
"aircraft": {
"code": "321"
},
"operating": {
"carrierCode": "VJ"
},
"duration": "PT1H20M",
"id": "9",
"numberOfStops": 0,
"blacklistedInEU": false
}]
}],
"price": {
"currency": "VND",
"total": "1640000.00",
"base": "1381000.00",
"fees": [{
"amount": "0.00",
"type": "SUPPLIER"
},
{
"amount": "0.00",
"type": "TICKETING"
}
],
"grandTotal": "1640000.00"
},
"pricingOptions": {
"fareType": [
"PUBLISHED"
],
"includedCheckedBagsOnly": true
},
"validatingAirlineCodes": [],
"travelerPricings": [{
"travelerId": "1",
"fareOption": "STANDARD",
"travelerType": "ADULT",
"price": {
"currency": "VND",
"total": "1640000.00",
"base": "1381000.00"
},
"fareDetailsBySegment": [{
"segmentId": "9",
"cabin": "ECONOMY",
"fareBasis": "JSP",
"class": "J",
"includedCheckedBags": {
"weight": 20,
"weightUnit": "KG"
}
}]
}]
},
Keep in mind that right now the only source for prices in the API is GDS. Many LCCs don't / only load their more expensive fares into GDS, as it costs them money.
Lately, many "normal" airlines have also added fees when booking from a GDS compared to directly on their website / or other direct distribution methods.
I assume VietJet is one of those carriers, as it is a low-cost airline.
Regarding your second question: That is because of the fare system in the airline industry. Airlines load so called "fares", which specifies the price of a ticket for a given route within a date window.
An example: VietJet offers SGN-DAD for a base fare of 55EUR ( without taxes& fees ). You can choose any flight by VJ on any date within the window of the fare, and the price will be the same, as long as there is availability in the booking class J , which the fare is for.

How to process payments with service fee being deducted in Visa Cybersource Payments API?

I have an app that I would like to add payment processing similar to Amazon payment processing into it where sub-merchants get paid by customers with service fee being deducted, I can see in https://developer.visa.com/capabilities/cybersource/reference#cybersource__cybs_payments_v2__v2__process_a_payment the following request body but there is no field in request body to specify a service fee:
{
"clientReferenceInformation": {
"code": "TC588171_3"
},
"processingInformation": {
"commerceIndicator": "internet"
},
"aggregatorInformation": {
"subMerchant": {
"cardAcceptorID": "1234567890",
"country": "US",
"phoneNumber": "650-432-0000",
"address1": "900 Metro Center",
"postalCode": "94404-2775",
"locality": "Foster City",
"name": "Visa Inc",
"administrativeArea": "CA",
"region": "PEN",
"email": "test#cybs.com"
},
"name": "V-Internatio",
"aggregatorID": "123456789"
},
"orderInformation": {
"billTo": {
"country": "US",
"lastName": "VDP",
"address2": "Address 2",
"address1": "201 S. Division St.",
"postalCode": "48104-2201",
"locality": "Ann Arbor",
"administrativeArea": "MI",
"firstName": "RTS",
"phoneNumber": "999999999",
"district": "MI",
"buildingNumber": "123",
"company": "Visa",
"email": "test#cybs.com"
},
"amountDetails": {
"totalAmount": "102.21",
"currency": "USD"
}
},
"paymentInformation": {
"card": {
"expirationYear": "2031",
"number": "5555555555554444",
"securityCode": "123",
"expirationMonth": "12",
"type": "002"
}
}
}
Is there a way or a workaround to get a service fee deducted?
Service fees go in the orderInformation block. Like this:
"orderInformation": {
"amountDetails": {
"totalAmount": "102.21",
"currency": "USD",
"serviceFeeAmount": "3.00"
},
There are a few prerequisites to using service fees. One of which you must be using First Data as your processor. For more details check this documentation.

How to iterate and render my fetch result in react native JSX

{
"status": true,
"live_score_domestic": [
{
"nTournamentID": "1",
"cTournamentName": "sample tournament.",
"cTournamentType": "D",
"dStartDate": "2016-12-10",
"dEndDate": "2016-12-12",
"matches": [
{
"cVenueCode": "TTAB",
"cTableName": "Table 1",
"cEventType": "Junior Boys",
"cMatchNo": "5",
"cRound": "First Round",
"nScheduledDate": "2016-12-11",
"nScheduledTime": "11:45:00",
"teamname1": "MOTHER SCHOOL",
"teamname2": "HARI SHEWA SCHOOL",
"nVenueID": "1",
"nTableID": "1",
"nTeamID1": "3",
"nTeamID2": "4",
"nTournamentID": "1",
"nFixtureDetailsID": "15",
"nEventTypeID": "5",
"image": "http://example.com/tt.png"
},
{
"cVenueCode": "TTAB",
"cTableName": "Table 1",
"cEventType": "Junior Boys",
"cMatchNo": "4",
"cRound": "First Round",
"nScheduledDate": "2016-12-11",
"nScheduledTime": "11:30:00",
"teamname1": "MOTHER SCHOOL",
"teamname2": "HARI SHEWA SCHOOL",
"nVenueID": "1",
"nTableID": "1",
"nTeamID1": "3",
"nTeamID2": "4",
"nTournamentID": "1",
"nFixtureDetailsID": "14",
"nEventTypeID": "5",
"image": "http://example.com/tt.png"
}
]
}
],
"live_score_international": [
{
"nTournamentID": "2",
"cTournamentName": "International Tournament Sample",
"cTournamentType": "I",
"dStartDate": "2016-12-22",
"dEndDate": "2016-12-24",
"matches": []
}
],
"results_domestic": [
{
"nTournamentID": "1",
"cTournamentName": "sample tournament.",
"cTournamentType": "D",
"dStartDate": "2016-12-10",
"dEndDate": "2016-12-12",
"matches": [
{
"cVenueCode": "TTAB",
"cTableName": "Table 1",
"cEventType": "Junior Boys",
"cMatchNo": "5",
"cRound": "First Round",
"nScheduledDate": "2016-12-11",
"nScheduledTime": "11:45:00",
"teamname1": "MOTHER SCHOOL",
"teamname2": "HARI SHEWA SCHOOL",
"nVenueID": "1",
"nTableID": "1",
"nTeamID1": "3",
"nTeamID2": "4",
"nTournamentID": "1",
"nFixtureDetailsID": "15",
"nEventTypeID": "5",
"image": "http://example.com/tt.png"
},
{
"cVenueCode": "TTAB",
"cTableName": "Table 1",
"cEventType": "Junior Boys",
"cMatchNo": "4",
"cRound": "First Round",
"nScheduledDate": "2016-12-11",
"nScheduledTime": "11:30:00",
"teamname1": "MOTHER SCHOOL",
"teamname2": "HARI SHEWA SCHOOL",
"nVenueID": "1",
"nTableID": "1",
"nTeamID1": "3",
"nTeamID2": "4",
"nTournamentID": "1",
"nFixtureDetailsID": "14",
"nEventTypeID": "5",
"image": "http://example.com/tt.png"
}
]
}
],
"results_international": [
{
"nTournamentID": "2",
"cTournamentName": "International Tournament Sample",
"cTournamentType": "I",
"dStartDate": "2016-12-22",
"dEndDate": "2016-12-24",
"matches": []
}
],
"fixture_point_domestic": [
{
"nTournamentID": "1",
"cTournamentName": "sample tournament.",
"cTournamentType": "D",
"dStartDate": "2016-12-10",
"dEndDate": "2016-12-12"
}
],
"fixture_point_international": [
{
"nTournamentID": "2",
"cTournamentName": "International Tournament Sample",
"cTournamentType": "I",
"dStartDate": "2016-12-22",
"dEndDate": "2016-12-24"
}
]
}
This is the fetch result.I want to render first a heading like domestic Tournaments.Then i want to loop for al tornaments in domestic.Then all matches in each tournament.How i can do this?Anyone to help.thanks in advance :)
can you please help me to figure out how to iterate all
First of all you should decide on how the data should be displayed on the screen. Should they be clickable or not, scrolled or not, what part of screen they should take etc. And depending on the visual design of your future application you can make a choice what exact react-native visual component will represent the data on the screen by the best way.
For example, if it is applicable by visual design of your application you can take a look at the react-native ListView or ScrollView components to render endless list of identical complex data.
If iterating through that entire JSON object is your intent, then an easy approach is a for...in loop.
For example:
var obj = {a: 1, b: 2, c: {a: 1, b: 2}};
function walk(obj) {
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
var val = obj[key];
console.log(val);
walk(val);
}
}
}
walk(obj);
Taken from: iterating through json object javascript
Object.keys(data).map((key) => { ... })
This will use the object properties (live_score_domestic, live_score_international, etc) to iterate through the top most data. Then you can use data[key] to get throught its contents.

Location based pricing in Softlayer via API

The script in the following link provides location based pricing for each item:
http://sldn.softlayer.com/blog/cmporter/location-based-pricing-and-you
When I run above script for example for Toronto location, the returned value does not match the pricing in the SL portal for Toronto. For example, the script returns 8GB # 0.085/hr vs pricing from portal which is 0.090 for 8GB in Tor:
"864": {
"capacity": "8",
"description": "8 GB",
"id": 864,
"itemCategory": {
"categoryCode": "ram",
"id": 3,
"name": "RAM",
"quantityLimit": 0
},
"itemTaxCategoryId": 166,
"keyName": "RAM_8_GB",
"prices": [
{
"currentPriceFlag": "",
"hourlyRecurringFee": ".085",
"id": 112677,
"itemId": 864,
"laborFee": "0",
"locationGroupId": 503,
"onSaleFlag": "",
"oneTimeFee": "0",
"packageReferences": [
{
"id": 891477,
"itemPriceId": 112677,
"packageId": 46
}
],
"quantity": "",
"recurringFee": "56.75",
"setupFee": "0",
"sort": 0
}
],
"softwareDescriptionId": "",
"units": "GB",
"upgradeItemId": ""
},
What's wrong with this APIs?
Can you make double check please? because I verified that Portal is displaying the same price than API. I believe the price that you saw was for other datacenter.
Select first the datacenter: TOR01 - Toronto
Check the price for RAM 8 GB