Python Code help..

SL MULTIMEDIA TUTORIAL

Well-known member
  • Jul 27, 2020
    1,632
    6,937
    113
    United States
    mekata Code enne kohomada 👀

    There are two online supermarkets which provide price of various products.

    You need to write a program to acquire, extract and compare the price from these two suppliers, for a given product.

    Example: Price of a coconut from the two different suppliers can be found in the following webpages.

    laughs_coconut = 'https://www.laugfssuper.com/index.php/coconut-105320.html' (Please check the update note at the end of the question)
    glomark_coconut = 'https://glomark.lk/coconut/p/11624'

    The function def compare_prices(product_laughs,product_glomark) will take-in two similar products from two suppliers, and compare the prices to recommend you which option is cheaper on a given instance of time.

    1. Visit the links in your web browser, and use the Inspect elements / View page source tools of the browser to understand the structure of the web pages given above.
    2. Complete the compare_prices function which is pre-loaded in the answer box to acquire and extract the price values from two web pages.



    When you submit your answer to be checked, be patient for a while (up to 20 seconds) until its been checked with multiple test cases.
    Example expected output

    Laughs COCONUT - Item#mr-2058 Rs.: 89.0
    Glomark Coconut Rs.: 86.0
    Glomark is cheaper: 3.0

    Here are some more test cases for you to test in your own computer.

    laughs_tissues = 'https://www.laugfssuper.com/index.php/categories/household/flora-facial-tissues-2-x-160-box.html'
    glomark_tissues = 'https://glomark.lk/flora-facial-tissues-160s/p/10470'
    compare_prices(laughs_tissues,glomark_tissues)

    laughs_bread = https://www.laugfssuper.com/index.php/crimson-bread-sliced-111452.html'
    glomark_bread = 'https://glomark.lk/top-crust-bread/p/13676'
    compare_prices(laughs_bread,glomark_bread)

    **Update:Laugfs website seems to be slow and changing quite frequently. So a backup of the required web pages are available in the following links. Your answers will be validated against these pages.:

    https://scrape-sm1.github.io/site1/COCONUT market1super.html
    https://scrape-sm1.github.io/site1/... HOUSEHOLD - Categories market1super.com.html
    https://scrape-sm1.github.io/site1/...BEVERAGES - Categories market1ssuper.com.html
    https://scrape-sm1.github.io/site1/Crimson Bread Sliced market1super.com.html

    Stock Code eka :nerd:

    Python:
    import requests
    import json
    
    import sys
    sys.path.insert(0,'bs4.zip')
    from bs4 import BeautifulSoup
    
    #Imitate the Mozilla browser.
    user_agent = {'User-agent': 'Mozilla/5.0'}
    
    
    def compare_prices(product_laughs,product_glomark):
        #TODO: Aquire the web pages which contain product Price
    
        
        
        #TODO: LaughsSuper supermarket website provides the price in a span text.
    
    
        #TODO: Glomark supermarket website provides the data in jason format in an inline script.
        #You can use the json module to extract only the price
        
        
        #TODO: Parse the values as floats, and print them.
        
        print('Laughs  ',product_name_laughs,'Rs.: ' , price_laughs)
        print('Glomark ',product_name_glomark,'Rs.: ' , price_glomark)
        
        if(price_laughs>price_glomark):
            print('Glomark is cheaper Rs.:',price_laughs - price_glomark)
        elif(price_laughs<price_glomark):
            print('Laughs is cheaper Rs.:',price_glomark - price_laughs)   
        else:
            print('Price is the same')
     

    Rowdy Baby

    Well-known member
  • Dec 22, 2018
    3,229
    4,470
    113
    Colombo
    Webscraping neda beautiful soup kiyala lib ekak tye eken pluwan wei 2015 wage ehema ekak use kala project ekakata dan lesi widi ati
     

    casc_rokz

    Well-known member
  • Jun 3, 2011
    1,559
    819
    113
    What I would do is
    1) Scrape all required data and store them in two DataFrames
    2) Using the DataFrames, create a common DF and compare the prices and do the calculations

    Pandas wage libraries use karala tiyenawada?
     

    Sonique

    Well-known member
  • Oct 22, 2007
    25,136
    11,141
    113
    Forest
    Buduamme ohoma webscrape karanna epa ban. Wenama code ekakin Unge site eken eka paarak scrape karala permenant database ekakata daahan. Inpasse eken comparison karahan. Ohoma karama wenne oka run karana run karana paarata arunge load eka wadi wela un inpasse cloudfare hari mokak hari obanawa inpasse scrape karala iwarai.
     

    SL MULTIMEDIA TUTORIAL

    Well-known member
  • Jul 27, 2020
    1,632
    6,937
    113
    United States
    What I would do is
    1) Scrape all required data and store them in two DataFrames
    2) Using the DataFrames, create a common DF and compare the prices and do the calculations

    Pandas wage libraries use karala tiyenawada?
    thiyenawa

    assignment ekak ne ?? apen monawada wenna one ??
    oka karagana code eka wenas karaganna one kohomada kiyanna puluwanda
    ------ Post added on Apr 24, 2022 at 8:20 AM
     

    Nathara96

    Member
    Sep 18, 2022
    2
    0
    1
    Plz send me the code

    Suppose you are writing a python web client to access an API of an online supermarket. Given below are the API details.

    Base URL= http://host1.open.uom.lk:8080

    table



    1. Write a python program to retrieve all the products from the API Server and print the total number of products currently stored in the server.
    Hint: the json response will be of the following example format:

    {
    "message": "success",
    "data": [
    {
    "id": 85,
    "productName": "Araliya Basmathi Rice",
    "description": "White Basmathi Rice imported from Pakistan. High-quality rice with extra fragrance. Organically grown.",
    "category": "Rice",
    "brand": "CIC",
    "expiredDate": "2023.05.04",
    "manufacturedDate": "2022.02.20",
    "batchNumber": 324567,
    "unitPrice": 1020,
    "quantity": 200,
    "createdDate": "2022.02.24"
    },
    {
    "id": 86,
    "productName": "Araliya Basmathi Rice",
    "description": "White Basmathi Rice imported from Pakistan. High-quality rice with extra fragrance. Organically grown.",
    "category": "Rice",
    "brand": "CIC",
    "expiredDate": "2023.05.04",
    "manufacturedDate": "2022.02.20",
    "batchNumber": 324567,
    "unitPrice": 1020,
    "quantity": 200,
    "createdDate": "2022.02.24"
    },
    ...
    ...
    }


    2. The following product has been entered into the API server by you in the previous question.
    However, it has been noted that the entered product's brand should be changed to "Araliya" instead of "CIC".
    Write a python program to update the entry on the API server as required. Print the JSON response of the request.

    {
    "productName":"Araliya Basmathi Rice",
    "description":"White Basmathi Rice imported from Pakistan. High-quality rice with extra fragrance. Organically grown.",
    "category":"Rice",
    "brand":"CIC",
    "expiredDate":"2023.05.04",
    "manufacturedDate":"2022.02.20",
    "batchNumber":324567,
    "unitPrice":1020,
    "quantity":200,
    "createdDate":"2022.02.24"
    }
     

    MWD

    Member
    Jan 6, 2023
    1
    0
    1
    Plz send me the code

    Suppose you are writing a python web client to access an API of an online supermarket. Given below are the API details.

    Base URL= http://host1.open.uom.lk:8080

    table



    1. Write a python program to retrieve all the products from the API Server and print the total number of products currently stored in the server.
    Hint: the json response will be of the following example format:

    {
    "message": "success",
    "data": [
    {
    "id": 85,
    "productName": "Araliya Basmathi Rice",
    "description": "White Basmathi Rice imported from Pakistan. High-quality rice with extra fragrance. Organically grown.",
    "category": "Rice",
    "brand": "CIC",
    "expiredDate": "2023.05.04",
    "manufacturedDate": "2022.02.20",
    "batchNumber": 324567,
    "unitPrice": 1020,
    "quantity": 200,
    "createdDate": "2022.02.24"
    },
    {
    "id": 86,
    "productName": "Araliya Basmathi Rice",
    "description": "White Basmathi Rice imported from Pakistan. High-quality rice with extra fragrance. Organically grown.",
    "category": "Rice",
    "brand": "CIC",
    "expiredDate": "2023.05.04",
    "manufacturedDate": "2022.02.20",
    "batchNumber": 324567,
    "unitPrice": 1020,
    "quantity": 200,
    "createdDate": "2022.02.24"
    },
    ...
    ...
    }


    2. The following product has been entered into the API server by you in the previous question.
    However, it has been noted that the entered product's brand should be changed to "Araliya" instead of "CIC".
    Write a python program to update the entry on the API server as required. Print the JSON response of the request.

    {
    "productName":"Araliya Basmathi Rice",
    "description":"White Basmathi Rice imported from Pakistan. High-quality rice with extra fragrance. Organically grown.",
    "category":"Rice",
    "brand":"CIC",
    "expiredDate":"2023.05.04",
    "manufacturedDate":"2022.02.20",
    "batchNumber":324567,
    "unitPrice":1020,
    "quantity":200,
    "createdDate":"2022.02.24"
    }
    Answers gaththa nm danna plz
     

    tsenindu44

    Member
    Feb 6, 2023
    1
    0
    1
    mekata Code enne kohomada 👀

    There are two online supermarkets which provide price of various products.

    You need to write a program to acquire, extract and compare the price from these two suppliers, for a given product.

    Example: Price of a coconut from the two different suppliers can be found in the following webpages.

    laughs_coconut = 'https://www.laugfssuper.com/index.php/coconut-105320.html' (Please check the update note at the end of the question)
    glomark_coconut = 'https://glomark.lk/coconut/p/11624'

    The function def compare_prices(product_laughs,product_glomark) will take-in two similar products from two suppliers, and compare the prices to recommend you which option is cheaper on a given instance of time.

    1. Visit the links in your web browser, and use the Inspect elements / View page source tools of the browser to understand the structure of the web pages given above.
    2. Complete the compare_prices function which is pre-loaded in the answer box to acquire and extract the price values from two web pages.



    When you submit your answer to be checked, be patient for a while (up to 20 seconds) until its been checked with multiple test cases.
    Example expected output

    Laughs COCONUT - Item#mr-2058 Rs.: 89.0
    Glomark Coconut Rs.: 86.0
    Glomark is cheaper: 3.0

    Here are some more test cases for you to test in your own computer.

    laughs_tissues = 'https://www.laugfssuper.com/index.php/categories/household/flora-facial-tissues-2-x-160-box.html'
    glomark_tissues = 'https://glomark.lk/flora-facial-tissues-160s/p/10470'
    compare_prices(laughs_tissues,glomark_tissues)

    laughs_bread = https://www.laugfssuper.com/index.php/crimson-bread-sliced-111452.html'
    glomark_bread = 'https://glomark.lk/top-crust-bread/p/13676'
    compare_prices(laughs_bread,glomark_bread)

    **Update:Laugfs website seems to be slow and changing quite frequently. So a backup of the required web pages are available in the following links. Your answers will be validated against these pages.:

    https://scrape-sm1.github.io/site1/COCONUT market1super.html
    https://scrape-sm1.github.io/site1/FLORA FACIAL TISSUES 2 X 160 BOX - HOUSEHOLD - Categories market1super.com.html
    https://scrape-sm1.github.io/site1/COCA COLA 2L (PET) - BEVERAGES - Categories market1ssuper.com.html
    https://scrape-sm1.github.io/site1/Crimson Bread Sliced market1super.com.html

    Stock Code eka :nerd:

    Python:
    import requests
    import json
    
    import sys
    sys.path.insert(0,'bs4.zip')
    from bs4 import BeautifulSoup
    
    #Imitate the Mozilla browser.
    user_agent = {'User-agent': 'Mozilla/5.0'}
    
    
    def compare_prices(product_laughs,product_glomark):
        #TODO: Aquire the web pages which contain product Price
    
       
       
        #TODO: LaughsSuper supermarket website provides the price in a span text.
    
    
        #TODO: Glomark supermarket website provides the data in jason format in an inline script.
        #You can use the json module to extract only the price
       
       
        #TODO: Parse the values as floats, and print them.
       
        print('Laughs  ',product_name_laughs,'Rs.: ' , price_laughs)
        print('Glomark ',product_name_glomark,'Rs.: ' , price_glomark)
       
        if(price_laughs>price_glomark):
            print('Glomark is cheaper Rs.:',price_laughs - price_glomark)
        elif(price_laughs<price_glomark):
            print('Laughs is cheaper Rs.:',price_glomark - price_laughs)  
        else:
            print('Price is the same')
    can you send me 3rd cource of uom 4.7 quiz 3 codes please
     
    Jun 6, 2023
    2
    0
    1
    hi

    matath okama thamai thiyana prashne

    4.7 quiz 3 ekata answer eka


    import requests

    BASE_URL = "http://host1.open.uom.lk:8080"

    data = {
    "productName": "Araliya Basmathi Rice",
    "description": "White Basmathi Rice imported from Pakistan. High-quality rice with extra fragrance. Organically grown.",
    "category": "Rice",
    "brand": "Araliya",
    "expiredDate": "2023.05.04",
    "manufacturedDate": "2022.02.20",
    "batchNumber": 324567,
    "unitPrice": 1020,
    "quantity": 200,
    "createdDate": "2022.02.24"
    }

    response = requests.put(f"{BASE_URL}/api/products/", json=data)

    if response.status_code == 200:
    print(response.json())
    else:
    print("Error occurred while updating the product")
    ------ Post added on Jun 7, 2023 at 10:20 AM
     

    chathura17

    Member
    Jul 16, 2023
    1
    0
    1
    python programing eke 7.1 kohomada karanne

    python programing 2 eke 7.1 dannawda
    ------ Post added on Jul 16, 2023 at 11:01 AM
     

    Similar threads