UoM Online Course 3 - Python Programming එක ඉවර කරපු අය...

SL MULTIMEDIA TUTORIAL

Well-known member
  • Jul 27, 2020
    1,639
    6,950
    113
    United States
    from traceback import print_list
    import requests
    import json

    import sys
    sys.path.insert(0,'bs4.zip')
    from bs4 import BeautifulSoup

    #Imitate the Mozilla
    user_agent = {'User-agent': 'Mozilla/5.0'}



    def compare_prices(product_laughs,product_glomark):


    # laugfs product
    html_laugfs = requests.get(product_laughs).content
    soup_laugfs = BeautifulSoup(html_laugfs, 'html.parser')

    prod_laugfs = soup_laugfs.find('span',class_="regular-price")

    prodName = soup_laugfs.find('div',class_="product-name")
    product_name_laughs=prodName.get_text()

    prod_laugfs = prod_laugfs.get_text() # Will get text from html tags
    product_laugfs = prod_laugfs.strip() # Removing special characters like \n (newline)
    #print(product_name_laughs)
    prod_price_laugfs = product_laugfs[3:]
    price_laughs = float(prod_price_laugfs)
    #print(price_laughs)

    # Glomark product

    html_glomark = requests.get(product_glomark).content
    soup_glomark = BeautifulSoup(html_glomark, 'html.parser')

    prod_glomark = soup_glomark.find_all('script')[6].text
    prod_glomark = json.loads(prod_glomark)

    product_name_glomark = prod_glomark['description']
    offers_glomark = prod_glomark['offers'][0]
    price_glomark = float(offers_glomark['price'])
    #print(product_name_glomark)
    #print(price_glomark)


    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')

    me widihata wenas karanna one,hariyatama script eke number eka one,anika kalin oya manual function ekata call karala thibba ethakota deparak output eka print wenwa,ehema unama eyala dena test cases walata hariyanne na,mkada eyalage test case eke ekai oyage ekai dekak print wenwa
    ------ Post added on Apr 26, 2022 at 12:43 AM
    :yes::love:
     

    DarkNight999

    Member
    Apr 27, 2022
    5
    0
    1
    inspect element gihilla oyata awashya element eke thiyena thana hoyaganna,eetapasse beautiful soup eken a place ekata gihin data eka ganna,eka variable ekaka save karaganna,a widihatama anith website ekatath karanna,
    a kohomada kiyannko. mata danne nathi programme akk oygen ahagann thiyei. 7.1. oya kivva wage inspect element gihin kohomda karanne? 0789424220 ta telegram massage akk dannko.please

    from traceback import print_list
    import requests
    import json

    import sys
    sys.path.insert(0,'bs4.zip')
    from bs4 import BeautifulSoup

    #Imitate the Mozilla
    user_agent = {'User-agent': 'Mozilla/5.0'}



    def compare_prices(product_laughs,product_glomark):


    # laugfs product
    html_laugfs = requests.get(product_laughs).content
    soup_laugfs = BeautifulSoup(html_laugfs, 'html.parser')

    prod_laugfs = soup_laugfs.find('span',class_="regular-price")

    prodName = soup_laugfs.find('div',class_="product-name")
    product_name_laughs=prodName.get_text()

    prod_laugfs = prod_laugfs.get_text() # Will get text from html tags
    product_laugfs = prod_laugfs.strip() # Removing special characters like \n (newline)
    #print(product_name_laughs)
    prod_price_laugfs = product_laugfs[3:]
    price_laughs = float(prod_price_laugfs)
    #print(price_laughs)

    # Glomark product

    html_glomark = requests.get(product_glomark).content
    soup_glomark = BeautifulSoup(html_glomark, 'html.parser')

    prod_glomark = soup_glomark.find_all('script')[6].text
    prod_glomark = json.loads(prod_glomark)

    product_name_glomark = prod_glomark['description']
    offers_glomark = prod_glomark['offers'][0]
    price_glomark = float(offers_glomark['price'])
    #print(product_name_glomark)
    #print(price_glomark)


    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')

    me widihata wenas karanna one,hariyatama script eke number eka one,anika kalin oya manual function ekata call karala thibba ethakota deparak output eka print wenwa,ehema unama eyala dena test cases walata hariyanne na,mkada eyalage test case eke ekai oyage ekai dekak print wenwa
    ------ Post added on Apr 26, 2022 at 12:43 AM
    wada nane. oya link tika attach karala na neda
    ------ Post added on Apr 27, 2022 at 2:54 AM
     

    pasindu201

    Well-known member
  • Dec 25, 2017
    1,737
    1,523
    113
    a kohomada kiyannko. mata danne nathi programme akk oygen ahagann thiyei. 7.1. oya kivva wage inspect element gihin kohomda karanne? 0789424220 ta telegram massage akk dannko.please


    wada nane. oya link tika attach karala na neda
    ------ Post added on Apr 27, 2022 at 2:54 AM
    khmada kiyala oya course eke kiyala denwa bn,python basic course eka karanna mulinma
     

    0x9

    Well-known member
  • Mar 18, 2015
    541
    836
    93
    menna mage Code eka meke Error eka mokakda 🥲 :sorry:

    Python:
    import requests
    import json
    
    import sys
    sys.path.insert(0,'bs4.zip')
    from bs4 import BeautifulSoup
    
    #Imitate the Mozilla
    user_agent = {'User-agent': 'Mozilla/5.0'}
    
    
    
    def compare_prices(product_laughs,product_glomark):
    
    
        # laugfs product
        html_laugfs = requests.get(product_laughs).content
        soup_laugfs = BeautifulSoup(html_laugfs, 'html.parser')
    
        prod_laugfs = soup_laugfs.find('span',class_="regular-price")
    
        prodName = soup_laugfs.find('div',class_="product-name")
        product_name_laughs=prodName.get_text()
    
        prod_laugfs = prod_laugfs.get_text() # Will get text from html tags
        product_laugfs = prod_laugfs.strip() # Removing special characters like \n (newline)
        #print(product_name_laughs)
        prod_price_laugfs = product_laugfs[3:]
        price_laughs = float(prod_price_laugfs)
        #print(price_laughs)
    
        # Glomark product
    
        html_glomark = requests.get(product_glomark).content
        soup_glomark = BeautifulSoup(html_glomark, 'html.parser')
    
        prod_glomark = soup_glomark.find('script',type="application/ld+json")
        prod_glomark = prod_glomark.get_text()
        prod_glomark = json.loads(prod_glomark)
    
        product_name_glomark = prod_glomark['description']
        offers_glomark = prod_glomark['offers'][0]
        price_glomark = float(offers_glomark['price'])
        #print(product_name_glomark)
        #print(price_glomark)
    
      
        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')
    
    
    laughs_coconut = 'https://scrape-sm1.github.io/site1/COCONUT%20market1super.html'
    glomark_coconut = 'https://glomark.lk/coconut/p/11624'
    
    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'
    
    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_coconut,glomark_coconut)
    
    compare_prices(laughs_bread,glomark_bread)

    ඔයාගේ code එකේ අවුලක් නෑ වගේ මචන්... check button එක click කලාට results අවේ නෑ එත් submit කලාම අවුලක් උනේ නෑ.. locally test කරලා test url එක්ක තියන method call remove කරලා submit කරනම් හරි

    මම submit කරපු code එක මේ

    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):
        laughs_req = requests.get(product_laughs)
        laughs_soup = BeautifulSoup(laughs_req.content, 'html.parser')
    
        glomark_req = requests.get(product_glomark)
        glomark_soup = BeautifulSoup(glomark_req.content, 'html.parser')
        
        product_name_laughs = laughs_soup.find("div",{"class":"product-name"}).text.strip()
        product_name_glomark = glomark_soup.find("div",{"class":"product-title"}).text.strip()
        
        price_laughs = float(laughs_soup.find("span",{"class":"regular-price"}).text.strip()[3:])
        price_glomark = float(json.loads(glomark_soup.find("script",{"type":"application/ld+json"}).text.strip())['offers'][0]['price'])
        
        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')

    Screenshot from 2022-04-27 11-27-44.png


    Screenshot from 2022-04-27 11-27-51.png
     

    DarkNight999

    Member
    Apr 27, 2022
    5
    0
    1
    ඔයාගේ code එකේ අවුලක් නෑ වගේ මචන්... check button එක click කලාට results අවේ නෑ එත් submit කලාම අවුලක් උනේ නෑ.. locally test කරලා test url එක්ක තියන method call remove කරලා submit කරනම් හරි

    මම submit කරපු code එක මේ

    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):
        laughs_req = requests.get(product_laughs)
        laughs_soup = BeautifulSoup(laughs_req.content, 'html.parser')
    
        glomark_req = requests.get(product_glomark)
        glomark_soup = BeautifulSoup(glomark_req.content, 'html.parser')
       
        product_name_laughs = laughs_soup.find("div",{"class":"product-name"}).text.strip()
        product_name_glomark = glomark_soup.find("div",{"class":"product-title"}).text.strip()
       
        price_laughs = float(laughs_soup.find("span",{"class":"regular-price"}).text.strip()[3:])
        price_glomark = float(json.loads(glomark_soup.find("script",{"type":"application/ld+json"}).text.strip())['offers'][0]['price'])
       
        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')

    View attachment 168965

    View attachment 168966
    https://open.uom.lk/course/view.php?id=10
    Course 3 - Python Programming ake 4.5 2nd programme akai, 5.3 3rd Question ake programme akai dannko
     

    0x9

    Well-known member
  • Mar 18, 2015
    541
    836
    93

    4.5 2nd එකේ code එක

    Python:
    # IMPORTING LIBRARIES
    import pandas as pd
    
    # LOAD THE DATA
    url='https://raw.githubusercontent.com/jbrownlee/Datasets/master/iris.csv'
    col_name = ['sepal-length','sepal-width','petal-length','petal-width','class']
    dataset = pd.read_csv(url,names = col_name)
    print(dataset.max())

    output
    sepal-length 7.9
    sepal-width 4.4
    petal-length 6.9
    petal-width 2.5
    class Iris-virginica
    dtype: object

    5.3 quiz code එක නම් කරගන්න බැරි උනා.. තිබ්බ code එකම run කරලා results එක දැම්මම "Partially correct, Marks for this submission: 7.73/8.00." කියල අවා.. next step එකට යන්න පුළුවන් උනා
     

    DarkNight999

    Member
    Apr 27, 2022
    5
    0
    1
    4.5 2nd එකේ code එක

    Python:
    # IMPORTING LIBRARIES
    import pandas as pd
    
    # LOAD THE DATA
    url='https://raw.githubusercontent.com/jbrownlee/Datasets/master/iris.csv'
    col_name = ['sepal-length','sepal-width','petal-length','petal-width','class']
    dataset = pd.read_csv(url,names = col_name)
    print(dataset.max())

    output


    5.3 quiz code එක නම් කරගන්න බැරි උනා.. තිබ්බ code එකම run කරලා results එක දැම්මම "Partially correct, Marks for this submission: 7.73/8.00." කියල අවා.. next step එකට යන්න පුළුවන් උනා
    # IMPORTING LIBRARIES
    import pandas as pd

    # LOAD THE DATA
    url='https://raw.githubusercontent.com/jbrownlee/Datasets/master/iris.csv'
    col_name = ['sepal-length','sepal-width','petal-length','petal-width','class']
    dataset = pd.read_csv(url,names = col_name)
    print(dataset.max())

    me code aka 4.5 ta dammama wada une nane
     

    0x9

    Well-known member
  • Mar 18, 2015
    541
    836
    93
    # IMPORTING LIBRARIES
    import pandas as pd

    # LOAD THE DATA
    url='https://raw.githubusercontent.com/jbrownlee/Datasets/master/iris.csv'
    col_name = ['sepal-length','sepal-width','petal-length','petal-width','class']
    dataset = pd.read_csv(url,names = col_name)
    print(dataset.max())

    me code aka 4.5 ta dammama wada une nane

    sorry මචන් මම 5.2 එක එවල තියෙන්නේ

    4.5 ට මේක

    1.
    Python:
    import xml.etree.ElementTree as ET
    tag1 = ET.Element('tag1')
    tag2 = ET.SubElement(tag1, 'tag2')
    tag2.text = 'Animal'
    tag3 = ET.SubElement(tag1, 'tag3')
    tag3.text= 'Domestic'
    tag4 = ET.SubElement(tag1, 'tag4')
    tag41 = ET.SubElement(tag4, 'tag4.1')
    tag41.text= 'Cat'
    tag42 = ET.SubElement(tag4, 'tag4.2')
    tag42.text= 'Persian'
    tag5 = ET.SubElement(tag1, 'tag5')
    tag5.text= 'Iran'
    tag6 = ET.SubElement(tag1, 'tag6')
    tag6.text= 'Male'
    tag7 = ET.SubElement(tag1, 'tag7')
    tag7.text= '2021.05.04'
    ET.dump(tag1)



    2.
    Python:
    import xml.etree.ElementTree as ET
    vehicle_xml_data_as_string = "<motorvehicles><vehicle><registration_no>CBB1456</registration_no><make>Toyota</make><model>Premio</model></vehicle><vehicle><registration_no>PR2245</registration_no><make>Mazda</make><model>Bongo</model></vehicle><vehicle><registration_no>DE2115</registration_no><make>TATA</make><model>Sumo</model></vehicle><vehicle><registration_no>CAR7785</registration_no><make>Kia</make><model>Optima</model></vehicle></motorvehicles>"
    root = ET.fromstring(vehicle_xml_data_as_string)
    for element in root.iter(tag='vehicle'):
      if(element.find('registration_no').text == 'DE2115'):
        element.find('make').text= 'Nissan'
        element.find('model').text= 'Skyline'
        print(element.find('registration_no').text)
     
    Last edited:

    thriloka

    Well-known member
  • Apr 28, 2022
    882
    964
    93
    මචන් මම මුලින්ම unlock වෙන කෝස් දෙක කරන ගමන් ඉන්නෙ. ඒ දෙක කරාම unlock වෙන කෝස් දෙකේ curriculum එක මොකක්ද කියන්න පුලුවන්ද? ඒකෙ frontend ද උගන්වන්නෙ? මොකක්ද උගන්නන technologies?
     

    pasindu201

    Well-known member
  • Dec 25, 2017
    1,737
    1,523
    113
    මචන් මම මුලින්ම unlock වෙන කෝස් දෙක කරන ගමන් ඉන්නෙ. ඒ දෙක කරාම unlock වෙන කෝස් දෙකේ curriculum එක මොකක්ද කියන්න පුලුවන්ද? ඒකෙ frontend ද උගන්වන්නෙ? මොකක්ද උගන්නන technologies?
    eetapsse python2 and fullstack webdev2 courses tha,ai enne,python 2 eke intermidiate level eke dewal ugannanawa ,github gana ugannnawa ,machine learning gana ugannanawa,godak watinwa ithin free course eke hatiyata,,,full stack webdev2 eke angular frontend webdev ugannanawa,ajax and jquery ugannanawa,harima watina free course ekak,free course walin mama dakapu hodama content thibbe meke,
     
    • Like
    Reactions: shenat and thriloka

    thriloka

    Well-known member
  • Apr 28, 2022
    882
    964
    93
    eetapsse python2 and fullstack webdev2 courses tha,ai enne,python 2 eke intermidiate level eke dewal ugannanawa ,github gana ugannnawa ,machine learning gana ugannanawa,godak watinwa ithin free course eke hatiyata,,,full stack webdev2 eke angular frontend webdev ugannanawa,ajax and jquery ugannanawa,harima watina free course ekak,free course walin mama dakapu hodama content thibbe meke,
    Thanks බන්. contents ටිකනම් හොඳයි ඒත් පොඩ්ඩක් speed වැඩි වගේ සමහර lectures ලගේ.
     

    pasindu201

    Well-known member
  • Dec 25, 2017
    1,737
    1,523
    113
    Thanks බන්. contents ටිකනම් හොඳයි ඒත් පොඩ්ඩක් speed වැඩි වගේ සමහර lectures ලගේ.
    Beggers cant be choosers machan,free unama ithin danne nadda hamadema prefect wenne na
     
    • Haha
    Reactions: thriloka

    thriloka

    Well-known member
  • Apr 28, 2022
    882
    964
    93
    Beggers cant be choosers machan,free unama ithin danne nadda hamadema prefect wenne na
    අපිට නිකන් දුන්නට නිකන් කියන්නත් බෑ. දම්මික පෙරේරා ඕවට ගෙවන්න ඇති. උගෙ brand එකනෙ promote වෙන්නෙ.
     

    pasindu201

    Well-known member
  • Dec 25, 2017
    1,737
    1,523
    113
    අපිට නිකන් දුන්නට නිකන් කියන්නත් බෑ. දම්මික පෙරේරා ඕවට ගෙවන්න ඇති. උගෙ brand එකනෙ promote වෙන්නෙ.
    ow ekanam aththa habai,