0% found this document useful (0 votes)
8 views12 pages

Example PDF

Taiyo.ai weather assignment

Uploaded by

murali7835
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
8 views12 pages

Example PDF

Taiyo.ai weather assignment

Uploaded by

murali7835
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
ananon (Class_API import requests import json import os import pandas as pd import time from seleniun import webdriver from bs4 import Beautifulsoup class Weather_AaPr: def _init__ (self, keyword): self. keyword = keyword def json_print(self, obj): # create a formatted string of the Python ISON object with open(‘api_data.txt', ‘w') as json_file: [Link](obj, json_file) ‘text = [Link] (obj, sort_key: print(text) ue, indent=4) def create_dataframe(self, obj): # creating a datoframe from nested JSON objects FIELDS = ["[Link]", “[Link]”, “author”, “title”, “description”, “url", Gf = pd. json_nornalize(obj[ ‘articles’ ]) final_df = df[FIELOS] afinal_df.set_index(‘[Link]', inplace = True) display (final_df.head()) def news_api(self): # Use the news-api to obtain articles published from url = (‘[Link] .org/v2/everything?' keyword}&' " apikey=4e7@cabbsess4db0ss24a28ac33cdcid' .format(keyword = [Link])) response = [Link](url) Af (response.status_code == 200): print(‘APT call successful! ') son_response = response. json() ‘iF (Len(json_response[ ‘articles’ }) print('No News Articles Found") else: # Print a String in Json Format self. json_print (json_response) # Create a pandas DataFrane self.create_dataframe(json_response) else: print('Status code: ', response.status_code) localhost 8888inbconvertitmiTaiyolClass_API ipyno?downloat wa ananon (Class_API I class Web_Scraping: def _init_(self, location): [Link] = location def selenium webdriver(self): # Start the Driver driver = [Link](executable_path = r° Users \Aditya\Downloads\chromed # Hit the url of NASA Earth Data website and wait for 15 seconds. url = (‘https: //[Link]/search?q=(location)' .format (location = self. [Link](url) ‘time. sleep (15) # Driver scrolls down 25 times to Load the table. for i in range(o,1): driver-execute_script(" window. scrol18y(0,6000)") ‘time. sleep (19) # Fetch the webpage and store in a variable. webpage = driver.page_source # Parse the page using BeautifulSoup HTMLPage = BeautifulSoup(webpage, ‘[Link]') titles = [] description = [] Links = (] for lists in HTMLPage. find_all(class_ = 'result'): if ([Link] != '' and len(lists.find_all(‘p')) t= @): ‘[Link]([Link]) [Link]([Link]("p', class_ = ‘').text) ‘[Link]([Link]('p', class_ = ‘search-link').text) # Create a DataFrame Gf = [Link](list(zip(titles, description, links)), colunns =['title', ‘description’, 'link']) display(df) # Store to csv file #df.to_csv('[Link]', sep=",", index=False, header=True) print('Web Scraping Successful!) keyword = input ("Enter Keyword to be searched: ').lower() w_api = Weather_API(keyword) wlapi-news_api() location = input('Enter Location: ').lower() vs = Web_Scraping( India’) ws.selenium_webdriver() Enter Keyword to be searched: mumbai API call successful! "articles" t { localhost 8888inbconverthtmlaiyo!Class_APIipynb?download=also 22 ananon (Class_API author": null, "content": "Mumbai Indians lost their opening game of the season to Royal Ck allengers Bangalore\r\nctable>\r\nctr>Indian Premier League, ChennaiMumbai Indians 152 (26 overs): Suryakumar 56 (36)\u2026 [+1462 chars]" "description": "Defending champions Munbai Indians somehow earn their first win of the new Indian Premier League season with a 10-run victory against Kolkata Knight Riders.", "2021-64-13718:20:452", { 2 "bbc-news", "name": "BBC News” “Defending champions Munbai stifle Kolkata for first IPL win", yttps://[Link]/sport/cricket/56712922", “urlToImage": "https: //[Link]/Live-experience/cps/624/cpsprodpb/@8 16/production/_118007620 munbaiindianscelebrate. jpg" }, p ‘author": "The New York Times", "content": "LiveUpdated\uedaeMarch 21, 2021, 11:04 a.m. ET\r\nMarch 21, 202 1, 11:04 a.m. ET\r\nNew York finds its first case of a troubling variant first identifie 4 in Brazil. India battles a second wave centered around \u2026 [+15583 chars]", "description": "New York finds its first case of a troubling variant first i dentified in Brazil. India battles a second wave centered around Mumbai, along with vacc ine skepticism.”, “publishedat’ "2021-3-21T14:57:262", "title": "Covid Updates: Spring Breakers Defy Curfew in Miami Beach", url": “https: //[Link]. con/Live/2021/03/21/world/covid-19-coronavirus", “urlToImage": "https: //staticet .[Link]/images/2021/03/21/world/21virus-brie fing-miami-beach1/21virus-briefing-miami -beachi-facebookJunbo. jpg” h { “author”: "Manish Singh", "content": "Dream Sports, the parent firm of fantasy sports app Dreamii, has secured $400 million in a new financing round as the Munbai-headquartered firm builds wh at it calls an end-to-end sports tech company \u2626 [+3063 chars]", "description": "Dream Sports, the parent firm of fantasy sports app Dreami1, has secured $400 million in a new financing round as the Munbai-headquartered firm builc 5 what it calls an \u2@icend-to-end sports tech company\u2@id in the cricket-loving nati on, which is also the world\u2019s se\u2026", “publishedat": "2021-03-24710:55:192", "source": { id": "techcrunch", “TechCrunch” “Indian fantasy sports app Dream11\u20195 parent firm raises $400 m illion", "url": "http: //techcrunch..com/2@21/@3/24/indian-fantasy-sports-app-drean-spo rts-dream-11-raises-400-million/”, ‘urlToInage": "[Link] /2020/29/GettyImages jpg?w=563" -1148636368.. Carrying forward its ongoing probe into the SUV planting and a Thane businessman's death cases, the National Investigation Agency (NIA\r\n) on Tr ursday raided a prominent eatery in south Mumbai \u2026 [+1612 chars]”, “description”: "Carrying forward its ongoing probe into the SUV planting anc a Thane businessman's death cases, the National Investigation Agency (NIA) on Thursday r aided a prominent eatery in south Mumbai, official”, “publishedAt": "2021-04-@1710:13:602", localhost 8848inbconverthtmlaiyo!Class_APIipynb?download=also ana ananon (Class_API “source”: { "id": "the-tines-of-india", "name": "The Times of India" ‘Sachin Vaze probe: NIA raids Mumbai eatery in connection to Mukest Mumbai Mirror", “https: //munbaimirror .indiatimes .com/mumbai/crime/sachin-vaze-probe-r ia-raids-mumbai-eatery-in-connection-to-mukesh-anbani-bomb-scare/articleshow/[Link] 3", Ambani. bomb “urlToImage": "https: //[Link]/photo/ingsize-361519,msid-81833809/ 81833809. jpg" "Reuters Staff", “By Reuters Staff\r\nMUMBAT (Reuters) - At least six people dieo in a fire that engulfed a mall housing a hospital that treated coronavirus patients in M umbai, authorities said on Friday.\r\nMore than 70 \u2026 [+765 chars]”, “description”: "At least six people died in a fire that engulfed a mall hous ing a hospital that treated coronavirus patients in Mumbai, authorities said on Frida “publishedat": "2021-03-26705:47:432", “source”: { "id": "reuters", "name": "Reuters* in "title": "At least six dead in Mumbai hospital fire - Reuter: "url": “https: //[Link]/article/us-health-coronavirus-india~idUSKBN2 BIOEO", “urlTotnage": “https: //[Link]/resources/r/?m=028d=202103268t=28i =1556289434&r=LYNXMPEH2POA3&w=800" "Reuters Staff", “By Reuters Staff\r\nMUMBAT (Reuters) - At least nine coronavirus patients died in a fire that engulfed a mall housing a hospital in Mumbai, authorities s ‘iday.\r\nRescue workers were still workin\u2026 [+1414 chars]", description": "At least nine coronavirus patients died in a fire that engul fed a mall housing a hospital in Mumbai, authorities said on Friday.”, “publishedat": "2021-03-26T14:51:432", ‘Nine COVID patients dead in a Mumbai hospital fire - Reuters", + “https: //[Link]/article/health-coronavirus-india-munbai KBN2B1038", “urlTormage": “https: 28d=2021632681 =1556343236&r=LYNXMPEH2P181&w=800 ‘static. reuters. com/resources/r/2 "Reuters Staff", 1 "By Reuters Staff\r\nMUMBAI (Reuters) - The Mumbai Indians scout and wicketkeeping consultant kiran More has tested positive for COVID-19 ahead of the ne Indian Premier League (IPL) season, which begin\u2026 [+681 chars “description”: "The Munbai Indians scout and wicketkeeping consultant Kiran Nore has tested positive for COVID-19 ahead of the new Indian Premier League (IPL) seaso n, which begins on Frida “publishedat": *2921-4-06710:42:002", “source”: { "id": “reuters”, "name": "Reuters* he "title": "Mumbai Indians staffer tests positive days ahead of IPL start - Re uters", "url": "https: //[Link]..com/article/health-coronavirus-cricket-ipl-idUSK localhost 8848inbconverthtmlaiyo!Class_APIipynb?download=also ane ananon (Class_API BN28T187", “urlToImage": "https: //[Link]/resources_v2/images/rcom-default. png?w=800" h { "author": "[Link] facebook. con/bbcnews” “content”: "image copyrightGetty Inages\r\nimage captionAkshay Kunar is one of the most popular actors in Bollywood\r\nBollywood actor Akshay Kumar has been hospite lised a day after testing positive for Covid-19.\r\nT\u2026 [+1881 chars]", "description": "He is one of several Bollywood stars who have recently teste 4 positive for coronavirus.", “publishedat": "2021-04-@5T05:42:152", { "bbc-news", "name": "BBC News" ‘Akshay Kumar: Bollywood star in hospital with Covi ://www. bbc. [Link]/news /world-asia~india-56636782" , _Tnteps://ichetbocd co. uk/news/1624/branded. news /43B6/producti By Reuters Staff\r\nCHENNAL, India (Reuters) - The 14th edition of the Indian Premier League (IPL) began with an upset after Virat Kohlis Royal Challeng ers Bangalore stunned defending champions Munbai \u2026 [+1528 chars]", "description": "The 14th edition of the Indian Premier League (IPL) began wi th an upset after Virat Kohli's Royal Challengers Bangalore stunned defending champions Mumbai Indians by two wickets at Chennai's M.A. Chidambaram Stadium on Friday.”, “publishedat": "2021-64-10702:46:002", “source” "id": "reuters", "name": "Reuters* "title": "Bangalore stun champions Mumbai as IPL begins with an upset - Reut ers", ‘url": "[Link] con/article/cricket-ipl-idUSKBN2Bx012" , “urlToImage": "https: //[Link]/resources_v2/images/rcom-default. png?w=800" h { ‘author”: "Aman Chakraborty", “content: "NEW DELHI (Reuters) - Mumbai Indians have assenbled a side that Jooks even stronger than their back-to-back title-winning teams, with only Delhi Daredev ils and Sunrisers Hyderabad appearing capable o\u2026 [+2411 chars]”, "description": "Munbai Indians have assembled a side that looks even stronge + than their back-to-back title-winning teams, with only Delhi Daredevils and Sunrisers Hyderabad appearing capable of denying then a third straight Indian Premier League (IPL) crown.” “publishedat": "2621-04-@8T08:59:602", { 2 "reuters", : "Reuters* b "title": "Mumbai go from strength to strength as IPL hat-trick beckons - Ret ters", "url": "https: //[Link] .con/article/cricket-ipl-idUSKBN2BV13P", “urlToImage": "https: //[Link]/resources_v2/images/rcom-default. png?w=800" jajendra Jadhav, Aditya Kalra", "MUMBAI (Reuters) - A senior Mumbai police officer filed a comple int in the Supreme Court on Monday accusing a state government minister of corruption, t he latest development in a bizarre case that ha\u2026 [+2240 chars]”, localhost 8848inbconverthtmlaiyo!Class_APIipynb?download=also siz ananon (Class_API "description": "A senior Munbai police officer filed a complaint in the Supr eme Court on Monday accusing a state government minister of corruption, the latest devel opment in a bizarre case that has transfixed the media for weeks.”, “publishedAt": "2021-03-22T14:11:002", "source": { "id": "reuters", "Reuters* *sordid’ drama rocks India's finar ‘Car bomb, corruption and COvI ce capital - Reuters", "url": “[Link] reuters .com/article/us-india-police-idUSKBN2BE1WT", “urlTotage": "https: //[Link]/resources/r/?m=028d=202103228t=28i '=1555753879&r=LYNXMPEH2L16X8w=800" euters Staff", : "By Reuters Staff\r\nFILE PHOTO: A man and a wonan wearing protec tive face masks walk past a graffiti on a wall, amidst the spread of the coronavirus dis ease (COVID-19), in Mumbai, India, March 25, 2621\u2026 [+764 chars]", "description": "Maharashtra reported 49,414 new coronavirus cases on Sunday, the highest nunber reported by any Indian state since March 2020, government data showe a", “publishedat": "2021-03-28T16:35:002", euters", "Reuters* bh *title": "Maharashtra reports record spike in COVID-19 cases - Reuters", "url": “https: //[Link] .con/article/health-coronavirus-india-cases-idusk BN2BKOHQ” , ‘urlToInage": “https: //[Link]/resources/r/?m=@28d=2021328&t=28i =1556508703&r=LYNXMPEH2R@DO&W=800" h { “author”: "Reuters Staff", "content": "By Reuters Staff\r\nFILE PHOTO: People wearing protective masks crowd a marketplace amidst the spread of COVID-19 in Mumbai, India, March 22, 2021, REUT ERS/Niharika Kulkarni\r\nMUMBAI (Reuters) - The Ind\u2026 [+658 chars]", "description": "The Indian state of Maharashtra reported 40,414 new coronavi rus cases on Sunday, the highest number reported by any Indian state since March 2620, g overnnent data showed.”, “publishedat": "2021-03-28136:32:002", source’ "id": "reuters", "name": "Reuters* “title": "India's Maharashtra state reports record spike in COVID-19 cases - Reuters", ‘url": “https: //[Link]. com/article/us-health-coronavirus-india-cases: USKBN2BK@HO", ‘urlToInage": “https: //[Link]/resources/r/?m=@28d=2021328&t=28i =1556508670&r=LYNXMPEH2RDN&W=800 c "Abhirup Roy", FILE PHOTO: The ByteDance logo is seen in this illustration take “content” n, Nov. 27, 2619. REUTERS/Dado Ruvic/Illustration/File Photo\r\nMUMBAI (Reuters) - An Ir dian court on Tuesday dealt a blow to Chinas Byte\u2e26 [+674 chars]", "description": "An Indian court on Tuesday dealt a blow to China's ByteDance by dismissing its plea to unblock its bank accounts which have been frozen by federal av thorities investigating alleged tax evasion.", “publishedat' “source”: { "id": "reuters", "name": "Reuters* "2921-84-06710: 26:002", localhost 8848inbconverthtmlaiyo!Class_APIipynb?download=also ena ananon (Class_API "title": "India court dismisses ByteDance's plea to unblock bank accounts - Reuters UK", "url": “https: //[Link]/article/us-bytedance-india-tax-idUSKBN2BT16 ey “urlToInage": “https: //[Link]/resources/r/?m=028d=202104068t=28i =15574455368r=LYNXMPEH3SOKR8N=800" h { "News18" , “NCP chief Sharad Pawar has been admitted to Breach Candy Hospite 1 in Mumbai where he is scheduled to undergo a surgery on Monday morning for his gallble dder ailment, party leader Nawab Malik has said\u2026 [+715 chars]", "description": "Sharad Pawar To Undergo Gall Bladder Surgery Tomorrow\u@@a@\u@@a@NDTV\r\n

You might also like