Diary of an IT Guy #AnakBinus

Build Bridges, not Walls. Collaboration Forever!

Integrasi REST API dalam Aplikasi Python

leave a comment »

Berikut adalah contoh coding sederhana untuk mengkonsumi REST API dari MAPQuest dalam sebuah aplikasi Python sederhana. Di sini akan dilakukan input antara dua kota dengan output menampilkan jumlah kilometer dan perkiraan konsumi bahan bakar dalam liter.

import urllib.parse
import requests

main_api = "https://www.mapquestapi.com/directions/v2/route?"
key = "AGhVxXq1gAn9cNLB1XfYYA6FeEQ9SG4U"

while True:
    orig = input("Starting Location: ")
    if orig == "quit" or orig == "q":
        break
    dest = input("Destination: ")
    if dest == "quit" or dest == "q":
        break
    
    url = main_api + urllib.parse.urlencode({"key":key, "from":orig, "to":dest})
    print("URL: " + (url))
    json_data = requests.get(url).json()
    json_status = json_data["info"]["statuscode"]
    if json_status == 0:
        print("API Status: " + str(json_status) + " = A successful route call.\n")
        print("=============================================")
        print("Directions from " + (orig) + " to " + (dest))
        print("Trip Duration: " + (json_data["route"]["formattedTime"]))
        #print("Miles: " + str(json_data["route"]["distance"]))
        #print("Fuel Used (Gal): " + str(json_data["route"]["fuelUsed"]))
        print("Kilometers: " + str((json_data["route"]["distance"])*1.61))
        print("Fuel Used (Ltr): " + str((json_data["route"]["fuelUsed"])*3.78))
        print("=============================================")

Hasil outputnya:

Kita upgrade app di atas menjadi lebih lengkap lagi dengan dilengkapi error input error handling sbb:

import urllib.parse
import requests

main_api = "https://www.mapquestapi.com/directions/v2/route?"
key = "AGhVxXq1gAn9cNLB1XfYYA6FeEQ9SG4U"

while True:
    orig = input("Starting Location: ")
    if orig == "quit" or orig == "q":
        break
    dest = input("Destination: ")
    if dest == "quit" or dest == "q":
        break
    
    url = main_api + urllib.parse.urlencode({"key":key, "from":orig, "to":dest})
    print("URL: " + (url))
    json_data = requests.get(url).json()
    json_status = json_data["info"]["statuscode"]
    if json_status == 0:
        print("API Status: " + str(json_status) + " = A successful route call.\n")
        print("=============================================")
        print("Directions from " + (orig) + " to " + (dest))
        print("Trip Duration: " + (json_data["route"]["formattedTime"]))
        #print("Miles: " + str(json_data["route"]["distance"]))
        #print("Fuel Used (Gal): " + str(json_data["route"]["fuelUsed"]))
        print("Kilometers: " + str((json_data["route"]["distance"])*1.61))
        print("Fuel Used (Ltr): " + str("{:.2f}".format((json_data["route"]["fuelUsed"])*3.78)))
        print("=============================================")

        for each in json_data["route"]["legs"][0]["maneuvers"]:
            print((each["narrative"]) + " (" + str("{:.2f}".format((each["distance"])*1.61) + " km)"))
        print("=============================================\n")
    
    elif json_status == 402:
        print("**********************************************")
        print("Status Code: " + str(json_status) + "; Invalid user inputs for one or both locations.")
        print("**********************************************\n")
    elif json_status == 611:
        print("**********************************************")
        print("Status Code: " + str(json_status) + "; Missing an entry for one or both locations.")
        print("**********************************************\n")
    else:
        print("************************************************************************")
        print("For Staus Code: " + str(json_status) + "; Refer to:")
        print("https://developer.mapquest.com/documentation/directions-api/status-codes")
        print("************************************************************************\n")

Hasilnya adalah sbb:

Written by isal

14 September 2021 at 09:29

Ditulis dalam Web Programming

Tagged with , ,

Phases of the Software Development Life Cycle (SDLC)

leave a comment »

The software development life cycle (SDLC) is the process of developing software, starting from an idea and ending with delivery. This process consists of six phases. Each phase takes input from the results of the previous phase. There is no standard SDLC, so the exact phases can vary, but the most common are:

Phase 1. Requirements & Analysis

Phase 2. Design

Phase 3. Implementation

Phase 4. Testing

Phase 5. Deployment

Phase 6. Maintenance

Historically, development teams usually followed these phases in order in the waterfall method. The goal of waterfall was to complete each phase of SDLC down to the last detail before proceeding to the next, never returning to a prior phase, and writing everything down along the way.

Although the waterfall methods is still widely used today, it’s gradually being superseded by more adaptive, flexible methods that produce better software, faster, with less pain. These methods are collectively known as “Agile development.”

It is important to understand that the SDLC can be applied many different ways. Its phases can be repeated, and the order reversed. Individual phases can be performed at many levels in parallel (for example, requirements can be gathered separately for user interface details, back-end integrations, operating and performance parameters, etc.).

We’ll look at the phases of the SDLC in greater detail, and in their classic order (just remember: this is a description, not a prescription) Baca entri selengkapnya »

Written by isal

2 September 2021 at 11:48

Thre data type and its characteristic

leave a comment »

Here there are :

Written by isal

24 Agustus 2021 at 15:17

Purpose is the foundation

leave a comment »

Purpose = Misi dan tujuan hidup
Goal = Target; tujuan jangka pendek

Written by isal

24 Agustus 2021 at 06:44

Ditulis dalam Uncategorized

Sehat.. Sehat.. Sehat..

leave a comment »

Makanan penuaan dini:
1. Gula
2. Alkohol
3. Makanan yang dibakar
4. Daging olahan: kornet, sosis
5. Makanan pedas
6. Lemak trans

Agar tidak pikun:
1. Aerobik
2. Tidur lebih awal
3. Makan kembang kol
4. ODOJ
5. Air putih

Written by isal

25 Juli 2021 at 20:15

Ditulis dalam Uncategorized

Data Engineering: It is about pipelines!

leave a comment »

Data engineering process handles so many pipelines like oil fields to refineries. So the end product are datas that can be used for data scientists. This is the illustration:

Oil field processing:

Data Engineering process:

Written by isal

5 Juli 2021 at 06:45

Java Practice: Nested Loop

leave a comment »

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
  Scanner read = new Scanner(System.in);
  boolean isSuspended = read.nextBoolean();
  int ourScore = read.nextInt();
  int theirScore = read.nextInt();

  // your code goes here
  if (!isSuspended ){
     if (ourScore > theirScore ){
        System.out.println("Won");
     }

     if (ourScore < theirScore ){
        System.out.println("Lost");
     }

    if (ourScore == theirScore ){
       System.out.println ("Draw");
    }

} else{
   System.out.println("Suspended");
}

}
}

Written by isal

6 Mei 2021 at 21:47

Ditulis dalam Uncategorized

Radio booms online

leave a comment »

Written by isal

26 April 2021 at 13:21

Ditulis dalam Uncategorized

Unasko FM Radio Jalur Musik Country – Joox Playlist

leave a comment »

Listen to Unasko FM Bandung – Jalur Musik County, my Playlist on JOOX. Explore your fav tunes & new music, Live and Karaoke on JOOX. https://open.joox.com/s/rd?k=jayEt #jooxid

%d blogger menyukai ini: