├── Pomodoro App ├── README.md ├── Alarm.mp3 ├── Tick-Tock.mp3 └── Pomodoro Application.py ├── Corona Tracker ├── india_data.JPG ├── COVID-19_India_Data.csv ├── COVID-19_Global_Data.csv ├── COVID-19_State_wise_Information.csv ├── README.md ├── COVID19_India_Information.py └── COVID19_Corona Virus_Data.py ├── Indeed_job_scraper ├── Indeed_GIF.gif ├── Python_India_Jobs.csv ├── README.md └── Indeed_job_scraper.py ├── Slack_Push_Notification.py ├── Telegram_Bot_Code.py ├── IMDB_Scraping.py ├── README.md ├── Flipkart_price_finder └── Flipkart_Price_Finder.py ├── Cricbuzz_score_Scrapper.py ├── Weather_Update_Hyderabad.py ├── Calculator - Command Line Application.py ├── Dice_game └── Dice_game.py └── Online_Coding_Platform_Rating_Tracker.py /Pomodoro App/README.md: -------------------------------------------------------------------------------- 1 | Pomodoro Application 2 | -------------------------------------------------------------------------------- /Pomodoro App/Alarm.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ram-95/Python_Applications/HEAD/Pomodoro App/Alarm.mp3 -------------------------------------------------------------------------------- /Pomodoro App/Tick-Tock.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ram-95/Python_Applications/HEAD/Pomodoro App/Tick-Tock.mp3 -------------------------------------------------------------------------------- /Corona Tracker/india_data.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ram-95/Python_Applications/HEAD/Corona Tracker/india_data.JPG -------------------------------------------------------------------------------- /Indeed_job_scraper/Indeed_GIF.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ram-95/Python_Applications/HEAD/Indeed_job_scraper/Indeed_GIF.gif -------------------------------------------------------------------------------- /Indeed_job_scraper/Python_India_Jobs.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ram-95/Python_Applications/HEAD/Indeed_job_scraper/Python_India_Jobs.csv -------------------------------------------------------------------------------- /Indeed_job_scraper/README.md: -------------------------------------------------------------------------------- 1 | # Indeed_Job_Scraper 2 | 3 | ![Indeed Job Scraper](https://raw.githubusercontent.com/Ram-95/Python_Applications/master/Indeed_job_scraper/Indeed_GIF.gif) 4 | -------------------------------------------------------------------------------- /Slack_Push_Notification.py: -------------------------------------------------------------------------------- 1 | #Slack Push Notification 2 | ''' This script is used to get a Push Notification on Mobile using Slack.''' 3 | import slack 4 | import os 5 | def slack_message(message, filename): 6 | token = os.environ.get('SLACK_TOKEN') 7 | sc = slack.WebClient(token) 8 | sc.chat_postMessage(channel= 'python-notifications', 9 | text= '<< ' + os.path.basename(filename) + ' >>\n\n' + message, 10 | username= 'Python-Script', 11 | icon_emoji= ':sunglasses:') 12 | 13 | print('\n***** SLACK Push Notification Successfully Sent. *****\n') 14 | -------------------------------------------------------------------------------- /Pomodoro App/Pomodoro Application.py: -------------------------------------------------------------------------------- 1 | #Pomodoro Application 2 | '''Requires playsound module inorder to play the music. To install --- "pip install playsound". ''' 3 | 4 | #Module to play audio files 5 | from playsound import playsound 6 | import time 7 | 8 | duration = int(input('Enter Duration for your Pomodoro{in minutes}: ')) 9 | 10 | 11 | print(time.asctime()) 12 | print('Pomodoro Started. Focus....') 13 | for i in range(10): 14 | playsound('Tick-Tock.mp3') 15 | #Giving 0.8 as argument works best for sleeping for 1second 16 | time.sleep(0.8) 17 | 18 | print('Pomodoro Completed!') 19 | playsound('Alarm.mp3') 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Corona Tracker/COVID-19_India_Data.csv: -------------------------------------------------------------------------------- 1 | DATE,TOTAL_CASES,DEATHS 2 | 1-Mar-20,3,0 3 | 2-Mar-20,5,0 4 | 3-Mar-20,6,0 5 | 4-Mar-20,28,0 6 | 5-Mar-20,30,0 7 | 6-Mar-20,31,0 8 | 7-Mar-20,34,0 9 | 8-Mar-20,39,0 10 | 9-Mar-20,44,0 11 | 10-Mar-20,50,0 12 | 11-Mar-20,60,0 13 | 12-Mar-20,73,1 14 | 13-Mar-20,81,2 15 | 14-Mar-20,84,2 16 | 15-Mar-20,110,2 17 | 16-Mar-20,114,2 18 | 17-Mar-20,137,2 19 | 18-Mar-20,162,3 20 | 19-Mar-20,173,4 21 | 20-Mar-20,223,4 22 | 21-Mar-20,283,4 23 | 22-Mar-20,360,7 24 | 23-Mar-20,434,9 25 | 24-Mar-20,519,10 26 | 25-Mar-20,606,10 27 | 26-Mar-20,694,16 28 | 27-Mar-20,724,17 29 | 28-Mar-20,1008,24 30 | 29-Mar-20,1024,27 31 | 30-Mar-20,1200,29 32 | -------------------------------------------------------------------------------- /Telegram_Bot_Code.py: -------------------------------------------------------------------------------- 1 | #Telegram Bot Code 2 | import requests 3 | import os 4 | 5 | def telegram_bot_sendtext(message): 6 | '''Sends a message to Telegram Bot''' 7 | 8 | bot_token = os.environ.get('TELEGRAM_BOT_TOKEN') 9 | bot_chatID = os.environ.get('TELEGRAM_CHAT_ID') 10 | URL = f'https://api.telegram.org/bot{bot_token}' 11 | tag_line = '<<< Python Script >>>' 12 | send_text = URL + '/sendMessage?chat_id=' + bot_chatID + '&parse_mode=Markdown&text=' + message + '\n' + tag_line 13 | 14 | response = requests.get(send_text) 15 | 16 | if response: 17 | print(f'Message sent succesfully.') 18 | 19 | '''Driver Code.''' 20 | #msg = input('Enter your message: \n').strip() 21 | #test = telegram_bot_sendtext(msg) 22 | 23 | -------------------------------------------------------------------------------- /Corona Tracker/COVID-19_Global_Data.csv: -------------------------------------------------------------------------------- 1 | DATE,TOTAL_CASES,DEATHS 2 | 1-Mar-20,88585,3050 3 | 2-Mar-20,90443,3117 4 | 3-Mar-20,93016,3202 5 | 4-Mar-20,95314,3285 6 | 5-Mar-20,98425,3387 7 | 6-Mar-20,102050,3494 8 | 7-Mar-20,106099,3599 9 | 8-Mar-20,109991,3827 10 | 9-Mar-20,114381,4025 11 | 10-Mar-20,118948,4296 12 | 11-Mar-20,126214,4628 13 | 12-Mar-20,134576,4981 14 | 13-Mar-20,145483,5429 15 | 14-Mar-20,156653,5833 16 | 15-Mar-20,169593,6519 17 | 16-Mar-20,182490,7161 18 | 17-Mar-20,198238,7978 19 | 18-Mar-20,218822,8951 20 | 19-Mar-20,236877,9828 21 | 20-Mar-20,275111,11186 22 | 21-Mar-20,301100,12948 23 | 22-Mar-20,338259,14457 24 | 23-Mar-20,372253,16312 25 | 24-Mar-20,410465,18295 26 | 25-Mar-20,452601,20500 27 | 26-Mar-20,531865,24073 28 | 27-Mar-20,596366,27343 29 | 28-Mar-20,663127,30861 30 | 29-Mar-20,723390,34064 31 | 30-Mar-20,752747,36226 32 | -------------------------------------------------------------------------------- /Corona Tracker/COVID-19_State_wise_Information.csv: -------------------------------------------------------------------------------- 1 | S.NO,STATE/UT,TOTAL ACTIVE CASES,DISCHARGED,DEAD,TOTAL CASES 2 | 1,Andhra Pradesh,19,1,0,20 3 | 2,Andaman and Nicobar Islands,9,0,0,9 4 | 3,Bihar,11,0,1,12 5 | 4,Chandigarh,8,0,0,8 6 | 5,Chhattisgarh,7,0,0,7 7 | 6,Delhi,53,6,2,61 8 | 7,Goa,5,0,0,5 9 | 8,Gujarat,58,1,5,64 10 | 9,Haryana,33,17,0,50 11 | 10,Himachal Pradesh,3,0,1,4 12 | 11,Jammu and Kashmir,31,1,2,34 13 | 12,Karnataka,80,5,3,88 14 | 13,Kerala,194,19,1,214 15 | 14,Ladakh,13,3,0,16 16 | 15,Madhya Pradesh,33,0,2,35 17 | 16,Maharashtra,193,25,8,226 18 | 17,Manipur,1,0,0,1 19 | 18,Mizoram,1,0,0,1 20 | 19,Odisha,3,0,0,3 21 | 20,Puducherry,1,0,0,1 22 | 21,Punjab,38,1,1,40 23 | 22,Rajasthan,57,3,0,60 24 | 23,Tamil Nadu,50,4,1,55 25 | 24,Telengana,69,1,1,71 26 | 25,Uttarakhand,7,2,0,9 27 | 26,Uttar Pradesh,75,11,0,86 28 | 27,West Bengal,19,0,1,20 29 | -------------------------------------------------------------------------------- /Corona Tracker/README.md: -------------------------------------------------------------------------------- 1 | # COVID-19 Analysis [World & India] 2 | 3 | ### This code tracks the spread of Novel Corona Virus (COVID-19) and shows the details such as the number of cases and deaths across the World and India. 4 | 5 | This code also creates Three CSV files to store the day-to-day data. 6 | * COVID-19_Global_Data.csv - Stores the day-to-day data across the World 7 | * COVID-19_India_Data.csv - Stores the day-to-day data across India 8 | * COVID-19_State_wise_Information - Stores the state wise detailed information of the affected states in India. 9 | 10 | The above files are then used for Data Analysis - See [COVID-19_Data_Analysis.ipynb](https://github.com/Ram-95/Python_Applications/blob/master/Corona%20Tracker/COVID-19_Data_Analysis.ipynb) 11 | 12 | #### Below is the snapshot of the data showing the detailed information in India (as on March 28th, 2020). 13 | 14 | > ![India-result](https://raw.githubusercontent.com/Ram-95/Python_Applications/master/Corona%20Tracker/india_data.JPG) 15 | -------------------------------------------------------------------------------- /IMDB_Scraping.py: -------------------------------------------------------------------------------- 1 | #IMDB Scraping 2 | '''Script that finds the Top 250 Movies on IMDB.''' 3 | import requests 4 | import bs4 as bs 5 | 6 | #List that stores the details of the movies as a Dictionary. 7 | movies = [] 8 | print('Scraping in Progress... ') 9 | 10 | for idx in range(1,4): 11 | url = 'https://www.imdb.com/list/ls068082370/?sort=list_order,asc&st_dt=&mode=detail&page=' + str(idx) 12 | response = requests.get(url) 13 | html = response.text 14 | soup = bs.BeautifulSoup(html, 'lxml') 15 | 16 | temp = soup.findAll('div', class_= 'lister-item mode-detail') 17 | 18 | 19 | for i in temp: 20 | d = dict() 21 | 22 | d['Title'] = i.find('h3', class_= 'lister-item-header').find('a').text 23 | d['Rating'] = i.find('span', class_= 'ipl-rating-star__rating').text 24 | d['Director'] = i.select_one("p:nth-of-type(3)").find('a').text 25 | 26 | stars = [i.select_one("p:nth-of-type(3)").select_one("a:nth-of-type(2)").text, 27 | i.select_one("p:nth-of-type(3)").select_one("a:nth-of-type(3)").text] 28 | d['Actors'] = stars 29 | 30 | 31 | movies.append(d) 32 | 33 | print(len(movies)) 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python - Applications 2 | [![forthebadge made-with-python](http://ForTheBadge.com/images/badges/made-with-python.svg)](https://www.python.org/) 3 | 4 | This Repository consists of different **COMMAND LINE APPLICATIONS** that I developed using Python 3. 5 | 6 | - ### Dice Game: 7 | > - Command Line Simulation of a Two player Dice Game (6 sided). 8 | > - There are two modes of playing in this game: 9 | - Computer vs Player - Where a player can play with the Computer. 10 | - Player vs Player - A player plays with another player. 11 | 12 | - ### Flipkart Mobile Price Finder: 13 | > - Given a bunch of links of different Mobile Phones on Flipkart, this script will find the price of those items and print it on the command line. 14 | > - This is used to keep a track of an item's price that a user would like to buy so that he can make a purchase when there is a price drop. 15 | 16 | - ### Online Coding Platforms Rating Tracker: 17 | > - Given the URLs of users profile in Codeforces, Codechef, Hacker Earth, SPOJ and Interview Bit, this script will print their ratings and ranks. 18 | > - By running this script, a user can check his all ratings without explicitly navigating to the respective URLs. 19 | 20 | - ### Slack Push Notification: 21 | > - Utility Code for sending Push notifications to Slack app on Mobile. 22 | -------------------------------------------------------------------------------- /Flipkart_price_finder/Flipkart_Price_Finder.py: -------------------------------------------------------------------------------- 1 | # Flipkart Items Price finder - Prints the price of the item from the URL given as arguments. 2 | 3 | #Necessary Modules 4 | import bs4 as bs 5 | import urllib.request 6 | import os 7 | 8 | def flipkart_price(url): 9 | ''' Prints the price of the Items' URLs provided as argument.''' 10 | source = urllib.request.urlopen(url).read() 11 | soup = bs.BeautifulSoup(source, 'lxml') 12 | 13 | #Getting the name of the item 14 | item_name = soup.find('p').text 15 | 16 | #Getting the price of item 17 | price = soup.find('div', class_ = '_30jeq3 _16Jk6d').text 18 | 19 | msg = "Current price of \"{}\" is: Rs. {}/-".format(item_name, price) 20 | print(msg) 21 | 22 | #List of URLs of items on Flipkart. 23 | my_list = ['https://www.flipkart.com/redmi-8-onyx-black-64-gb/p/itmaf669d074ff27', 24 | 'https://www.flipkart.com/puma-flip-flops/p/itme8e4bba87778c?pid=SFFFHUNYAEH5K7KC&lid=LSTSFFFHUNYAEH5K7KCMJNJGK&marketplace=FLIPKART&store=osp%2Fcil&srno=b_1_2&otracker=hp_omu_Deals%2Bof%2Bthe%2BDay_6_4.dealCard.OMU_P44HQ9IPWEIN_3&otracker1=hp_omu_SECTIONED_manualRanking_neo%2Fmerchandising_Deals%2Bof%2Bthe%2BDay_NA_dealCard_cc_6_NA_view-all_3&fm=neo%2Fmerchandising&iid=e55f055b-fb3c-4f3a-9810-f9a098386d8d.SFFFHUNYAEH5K7KC.SEARCH&ppt=browse&ppn=browse&ssid=vuxg3ldyio0000001623222842094', 25 | 26 | ] 27 | 28 | for i in my_list: 29 | flipkart_price(i) 30 | 31 | 32 | -------------------------------------------------------------------------------- /Cricbuzz_score_Scrapper.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import bs4 as bs 3 | import time 4 | from prettytable import PrettyTable 5 | 6 | print(f"*********************** INDIA vs. AUSTRALIA Live Score ************************\n") 7 | 8 | def score_details(): 9 | url="https://www.cricbuzz.com/live-cricket-scores/22332/indw-vs-ausw-final-icc-womens-t20-world-cup-2020" 10 | 11 | response = requests.get(url) 12 | html = response.text 13 | soup = bs.BeautifulSoup(html, 'lxml') 14 | 15 | #Extracting the score and the Batsman details 16 | score = soup.find('div', class_= 'cb-min-bat-rw') 17 | info = soup.findAll('div', class_= 'cb-min-itm-rw') 18 | 19 | table = PrettyTable(['Batsman', 'Runs(Balls)', '4s', '6s', 'Strike Rate']) 20 | 21 | #Extracting the Batsmen Details 22 | for i in range(2): 23 | batsman = info[i].select_one("div:nth-of-type(1)").text.strip() 24 | runs = info[i].select_one("div:nth-of-type(2)").text.strip() 25 | balls = info[i].select_one("div:nth-of-type(3)").text.strip() 26 | fours = info[i].select_one("div:nth-of-type(4)").text.strip() 27 | sixes = info[i].select_one("div:nth-of-type(5)").text.strip() 28 | sr = info[i].select_one("div:nth-of-type(6)").text.strip() 29 | 30 | table.add_row([batsman, runs + '(' + balls + ')', fours, sixes, sr]) 31 | 32 | 33 | print(f'Score: {score.text.strip()}\n') 34 | print(table) 35 | print(45*'+ ') 36 | 37 | 38 | '''Driver Code - Calls the score function every 30 seconds.''' 39 | x = 0 40 | while x < 10: 41 | score_details() 42 | x += 1 43 | time.sleep(25) 44 | -------------------------------------------------------------------------------- /Weather_Update_Hyderabad.py: -------------------------------------------------------------------------------- 1 | #Weather_Update - Hyderabad 2 | 3 | #Necessary Modules 4 | from prettytable import PrettyTable 5 | import requests 6 | import bs4 as bs 7 | import datetime 8 | import sys 9 | import os 10 | import Slack_Push_Notification as Slack 11 | #import Balloon_tip as Bt 12 | 13 | #Dictionary to store the Weather Details. Date as Keys and details as the value stored as a list. 14 | weather_details = {} 15 | 16 | #Current Date 17 | curr_date = datetime.datetime.now().strftime("%d-%b-%Y") 18 | date_1 = datetime.datetime.strptime(curr_date, "%d-%b-%Y") 19 | 20 | #Using a browser Agent 21 | headers = {"User-agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36"} 22 | area = 'hyderabad' 23 | 24 | #Getting the webpage of the URL 25 | url = 'https://www.timeanddate.com/weather/india/' + area + '/ext' 26 | response = requests.get(url, headers = headers) 27 | html = response.text 28 | 29 | #Extracting the necessary information 30 | soup = bs.BeautifulSoup(html, 'lxml') 31 | temp = soup.find('tbody') 32 | 33 | #Looping and extracting the Information about weather. 34 | for i in range(2): 35 | end_date = date_1 + datetime.timedelta(days=i) 36 | try: 37 | temperature = temp.select_one("tr:nth-of-type(" + str(i+1) + ")").select_one("td:nth-of-type(2)").text 38 | weather_details[end_date.strftime("%d-%b-%Y")] = [temperature] 39 | weather_details[end_date.strftime("%d-%b-%Y")].append(temp.select_one("tr:nth-of-type(" + str(i+1) + ")").select_one("td:nth-of-type(3)").text) 40 | weather_details[end_date.strftime("%d-%b-%Y")].append(temp.select_one("tr:nth-of-type(" + str(i+1) + ")").select_one("td:nth-of-type(4)").text) 41 | except AttributeError: 42 | print('Weather Forecast NOT AVAILABLE for this Location. Please Enter a popular location.') 43 | sys.exit(8) 44 | 45 | 46 | #This Part of code is used to show a desktop notification. It only shows the current day weather for the choosen location. 47 | notif = 'Today\'s Weather Update - ' + area.title() + '\nMin/Max Temp: {}\nWeather: {}\nFeels Like: {}'.format(weather_details[curr_date][0], weather_details[curr_date][1],weather_details[curr_date][2]) 48 | 49 | #Desktop Notification 50 | #Bt.balloon_tip(notif) 51 | 52 | #Slack Notification 53 | Slack.slack_message(notif, __file__) 54 | print(notif) 55 | 56 | -------------------------------------------------------------------------------- /Indeed_job_scraper/Indeed_job_scraper.py: -------------------------------------------------------------------------------- 1 | import os 2 | import csv 3 | import requests 4 | from bs4 import BeautifulSoup 5 | 6 | headers = { 7 | "User-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36"} 8 | 9 | # Skills and Place of Work 10 | skill = input('Enter your Skill: ').strip() 11 | place = input('Enter the location: ').strip() 12 | no_of_pages = int(input('Enter the #pages to scrape: ')) 13 | 14 | 15 | # Creating the Main Directory 16 | main_dir = os.getcwd() + '\\' 17 | if not os.path.exists(main_dir): 18 | os.mkdir(main_dir) 19 | print('Base Directory Created Successfully.') 20 | 21 | 22 | # Name of the CSV File 23 | file_name = skill.title() + '_' + place.title() + '_Jobs.csv' 24 | # Path of the CSV File 25 | file_path = main_dir + file_name 26 | 27 | # Writing to the CSV File 28 | with open(file_path, mode='w') as file: 29 | writer = csv.writer(file, delimiter=',', lineterminator='\n') 30 | # Adding the Column Names to the CSV File 31 | writer.writerow( 32 | ['JOB_NAME', 'COMPANY', 'LOCATION', 'POSTED', 'APPLY_LINK']) 33 | 34 | # Requesting and getting the webpage using requests 35 | print(f'\nScraping in progress...\n') 36 | for page in range(no_of_pages): 37 | url = 'https://www.indeed.co.in/jobs?q=' + skill + \ 38 | '&l=' + place + '&start=' + str(page * 10) 39 | response = requests.get(url, headers=headers) 40 | html = response.text 41 | 42 | # Scrapping the Web 43 | soup = BeautifulSoup(html, 'lxml') 44 | base_url = 'https://in.indeed.com/viewjob?jk=' 45 | d = soup.find('div', attrs={'id': 'mosaic-provider-jobcards'}) 46 | 47 | jobs = soup.find_all('a', class_='tapItem') 48 | 49 | for job in jobs: 50 | job_id = job['id'].split('_')[-1] 51 | job_title = job.find('span', title=True).text.strip() 52 | company = job.find('span', class_='companyName').text.strip() 53 | location = job.find('div', class_='companyLocation').text.strip() 54 | posted = job.find('span', class_='date').text.strip() 55 | job_link = base_url + job_id 56 | #print([job_title, company, location, posted, job_link]) 57 | 58 | # Writing to CSV File 59 | writer.writerow( 60 | [job_title, company, location.title(), posted, job_link]) 61 | 62 | print(f'Jobs data written to <{file_name}> successfully.') 63 | -------------------------------------------------------------------------------- /Calculator - Command Line Application.py: -------------------------------------------------------------------------------- 1 | #Calculator - A Command Line Application that does basic Arithmetic Opertions.(Divison, Multiplication, Addition, Subtraction) 2 | 3 | '''Postfix evaluation''' 4 | def postfix_evaluation(st, n): 5 | '''Evaluates a Postfix Expression and returns the answer(an Integer).''' 6 | 7 | #Operand Stack - Only contains the Operands 8 | operand_stack = [] 9 | 10 | for i in range(n): 11 | if st[i] not in ('/', '*', '-', '+'): 12 | operand_stack.append(st[i]) 13 | else: 14 | a = float(operand_stack.pop()) 15 | b = float(operand_stack.pop()) 16 | if st[i] == '/': 17 | val = b / a 18 | elif st[i] == '*': 19 | val = a * b 20 | elif st[i] == '+': 21 | val = a + b 22 | elif st[i] == '-': 23 | val = b - a 24 | 25 | operand_stack.append(val) 26 | #print('OS: {}'.format(operand_stack)) 27 | 28 | return operand_stack[-1] 29 | 30 | 31 | 32 | '''Infix to Postfix conversion''' 33 | def infix_to_postfix(s, n): 34 | '''Converts a given Infix expression to Postfix Expression. Returns the Postfix Expression as a String.''' 35 | #Operator Stack - Only contains Operators 36 | stack = [] 37 | #Precedence of Arithmetic Operators 38 | operator_precedence = {'/' : 4, '*' : 3, '+' : 2, '-' : 1} 39 | #To store the postfix notation as a list 40 | res = [] 41 | 42 | for i in range(n): 43 | if s[i] not in operator_precedence: 44 | if i == 0: 45 | res.append(s[i]) 46 | else: 47 | if s[i-1] not in operator_precedence: 48 | res[-1] = res[-1] + s[i] 49 | else: 50 | res.append(s[i]) 51 | 52 | else: 53 | if len(stack) == 0: 54 | stack.append(s[i]) 55 | else: 56 | if operator_precedence.get(stack[-1]) > operator_precedence.get(s[i]): 57 | res.append(stack[-1]) 58 | stack.pop() 59 | stack.append(s[i]) 60 | else: 61 | stack.append(s[i]) 62 | 63 | #Adding the remaining operators to the result 64 | while len(stack) != 0: 65 | res.append(stack[-1]) 66 | stack.pop() 67 | print(res) 68 | return postfix_evaluation(res, len(res)) 69 | 70 | 71 | 72 | 73 | #Driver Code 74 | '''Taking mathematical expression as a String''' 75 | s = input('Expression: ').strip() 76 | print(infix_to_postfix(s, len(s))) 77 | 78 | 79 | ''' 80 | To Do: 81 | --------------- 82 | Failing to handle Associativity ----> Left to Right Associativity 83 | Left Most Operation should be evaluated first. 84 | ''' 85 | -------------------------------------------------------------------------------- /Dice_game/Dice_game.py: -------------------------------------------------------------------------------- 1 | # Dice Game between 2 Players 2 | # The winner will be the first player to score a 36. 3 | 4 | 5 | from random import randint 6 | import time 7 | import sys 8 | print('Welcome to Dice Game\n---------------------------------------------') 9 | player1 = input('Enter the 1st player name: ').strip() 10 | player2 = input('Enter the 2nd player name: ').strip() 11 | print('{} -> 1st Player\n{} -> 2nd Player'.format(player1, player2)) 12 | 13 | #this is to choose the next player 0 - first player 1- second player 14 | chance = 0 15 | 16 | #tries - 1st player tries1 - 2nd player 17 | (tries,tries1) = (0,0) 18 | 19 | #Total scores of players 20 | (total, total1) = (0,0) 21 | 22 | max_score = 36 23 | DECORATE_COUNT = 45 24 | 25 | # Iterate until a player is won 26 | while(1): 27 | print(f'\nScores: ') 28 | print('='*DECORATE_COUNT) 29 | print(f'{player1}: {total}\n{player2}: {total1}') 30 | print('='*DECORATE_COUNT) 31 | #1st player chance 32 | while(chance == 0): 33 | print('\n') 34 | print('{}(1st Player\'s) Chance.. '.format(player1)) 35 | print('-----------------------------------------------') 36 | roll = input('Roll Dice! Press 1 to roll: ').strip() 37 | if roll in (1,'1'): 38 | dice = randint(1,6) 39 | total = total + dice 40 | tries = tries + 1 41 | print('{}(1st Player) rolled a {} and total is {}'.format(player1, dice, total)) 42 | else: 43 | print('\nINCORRECT KEY PRESSED.PRESS 1 TO ROLL DICE.') 44 | continue 45 | #giving chance to 2nd player 46 | chance = 1 47 | 48 | if total >= max_score: 49 | print('\n\n******************* GAME OVER ********************\n') 50 | print('\n{}(Player1) Won the Game in {} tries. Congratulations!!!'.format(player1, tries)) 51 | sys.exit() 52 | 53 | #2nd player chance 54 | while(chance == 1): 55 | print('\n') 56 | print('{}(2nd Player\'s) Chance.. '.format(player2)) 57 | print('*************************************************') 58 | roll = input('Roll Dice! Press 1 to roll: ').strip() 59 | if roll in (1, '1'): 60 | dice = randint(1,6) 61 | total1 = total1 + dice 62 | tries1 = tries1 + 1 63 | print('{}(2nd Player) rolled a {} and total is {}'.format(player2, dice, total1)) 64 | else: 65 | print('\nINCORRECT KEY PRESSED.PRESS 1 TO ROLL DICE.') 66 | continue 67 | 68 | #giving chance to 1st player 69 | chance = 0 70 | 71 | if total1 >= max_score: 72 | print('\n\n******************* GAME OVER ********************\n') 73 | print('{}(Player1) won the Game in {} tries. Congratulations!!!\n'.format(player2, tries1)) 74 | sys.exit() 75 | -------------------------------------------------------------------------------- /Corona Tracker/COVID19_India_Information.py: -------------------------------------------------------------------------------- 1 | #COVID 19 India Cases 2 | import requests 3 | import bs4 as bs 4 | import csv 5 | import os 6 | from datetime import date 7 | from prettytable import PrettyTable 8 | 9 | 10 | filename = 'COVID-19_India_Data.csv' 11 | state_filename = 'COVID-19_State_wise_Information.csv' 12 | 13 | today = date.today().strftime("%d-%b-%y") 14 | 15 | 16 | url = "http://www.mohfw.gov.in/" 17 | response = requests.get(url) 18 | html = response.text 19 | soup = bs.BeautifulSoup(html, 'lxml') 20 | 21 | x = soup.find('div', class_= 'content newtab').find('p').text.strip() 22 | 23 | 24 | t_items = soup.find('div', class_= 'content newtab').find('table').find('tbody').findAll('tr') 25 | head = ['S.No', 'State/UT', 'Total Active Cases', 'Discharged', 'Dead', 'Total Cases'] 26 | 27 | 28 | #Creating a Table 29 | ind_table = PrettyTable(head) 30 | summ_table = PrettyTable(['Total', 'Total Active Cases', 'Discharged', 'Dead', 'Total Cases']) 31 | 32 | 33 | b = soup.findAll('div', class_='iblock_text') 34 | india_total = b[1].find('div').text.strip() + '(considering only Indian Citizens) = ' + b[1].find('span').text 35 | 36 | #Writing the state wise information to a file 37 | with open(state_filename, 'w') as f: 38 | writer = csv.writer(f, delimiter= ',', lineterminator= '\n') 39 | writer.writerow([x.upper() for x in head]) 40 | 41 | 42 | for i in t_items[:len(t_items)-1]: 43 | state_data = [] 44 | for k in i.findAll('td'): 45 | state_data.append(k.text.strip()) 46 | state_data.append(int(state_data[2]) + int(state_data[3]) + int(state_data[4])) 47 | ind_table.add_row(state_data) 48 | 49 | with open(state_filename, 'a') as f: 50 | writer = csv.writer(f, delimiter=',', lineterminator='\n') 51 | writer.writerow(state_data) 52 | 53 | 54 | print('\n' + '*'*20 + ' INDIA - STATE WISE INFORMATION ' + x + ' ' + '*'*20 + '\n') 55 | print(f'{ind_table}') 56 | 57 | summ = [] 58 | for j in t_items[-1].findAll('td'): 59 | summ.append(j.text.strip()) 60 | 61 | total_cases = int(summ[1].replace('#', '')) + int(summ[2].replace('#', '')) + int(summ[3].replace('#', '')) 62 | summ.append(total_cases) 63 | 64 | summ_table.add_row(summ) 65 | 66 | print(f'\nSummary:\n{summ_table}') 67 | print(f'\n[OFFICIAL DATA] - {india_total}\n') 68 | 69 | 70 | 71 | '''Code for writing to the Files.''' 72 | #Creating the CSV File if not already present 73 | files = os.listdir() 74 | deaths = int(summ[3]) 75 | 76 | 77 | if filename not in files: 78 | with open(filename, 'w') as f: 79 | writer = csv.writer(f, delimiter=',', lineterminator='\n') 80 | writer.writerow(['DATE', 'TOTAL_CASES', 'DEATHS']) 81 | print(f'\nCSV File Created Successfully.\n') 82 | 83 | 84 | #Reading the CSV File 85 | with open(filename, 'r') as f: 86 | reader = csv.reader(f, delimiter=',', lineterminator='\n') 87 | data = list(reader) 88 | #print(f'{data}') 89 | 90 | 91 | if data[-1][0] == 'DATE': 92 | with open(filename, 'a') as f: 93 | writer = csv.writer(f, delimiter = ',', lineterminator = '\n') 94 | writer.writerow([today, total_cases, deaths]) 95 | 96 | else: 97 | if data[-1][0] == today: 98 | data[-1][1] = str(max(int(data[-1][1].replace(',', '')), total_cases)) 99 | data[-1][2] = str(max(int(data[-1][2].replace(',', '')), deaths)) 100 | 101 | with open(filename, 'w') as f: 102 | wr = csv.writer(f, delimiter= ',', lineterminator='\n') 103 | for item in data: 104 | wr.writerow(item) 105 | else: 106 | with open(filename, 'a') as f: 107 | writer = csv.writer(f, delimiter = ',', lineterminator = '\n') 108 | writer.writerow([today, total_cases, deaths]) 109 | 110 | 111 | -------------------------------------------------------------------------------- /Corona Tracker/COVID19_Corona Virus_Data.py: -------------------------------------------------------------------------------- 1 | #WHO Data 2 | import csv 3 | import requests 4 | import bs4 as bs 5 | from datetime import date 6 | from prettytable import PrettyTable 7 | import os 8 | import Slack_Push_Notification as Slack 9 | 10 | filename = 'COVID-19_Global_Data.csv' 11 | 12 | today = date.today().strftime("%d-%b-%y") 13 | 14 | 15 | table = PrettyTable(['S.No', 'Country', 'Total Cases', 'New Cases', 'Deaths', 'New Deaths', 'Total Recovered', 'Active Cases', 'Serious/Critical']) 16 | 17 | url= "https://www.worldometers.info/coronavirus/" 18 | 19 | response = requests.get(url) 20 | html = response.text 21 | soup = bs.BeautifulSoup(html, 'lxml') 22 | 23 | t_items = soup.find('table', id="main_table_countries_today").findAll('tr') 24 | sno = 0 25 | india = [] 26 | 27 | for i in t_items[1:len(t_items)-1]: 28 | sno += 1 29 | country = i.select_one("td:nth-of-type(1)").text.strip() 30 | total_cases = i.select_one("td:nth-of-type(2)").text.strip() 31 | new_cases = 0 if i.select_one("td:nth-of-type(3)").text.strip() == '' else i.select_one("td:nth-of-type(3)").text.strip() 32 | deaths = 0 if i.select_one("td:nth-of-type(4)").text.strip() == '' else i.select_one("td:nth-of-type(4)").text.strip() 33 | new_deaths = 0 if i.select_one("td:nth-of-type(5)").text.strip() == '' else i.select_one("td:nth-of-type(5)").text.strip() 34 | total_recovered = 0 if i.select_one("td:nth-of-type(6)").text.strip() == '' else i.select_one("td:nth-of-type(6)").text.strip() 35 | active_cases = 0 if i.select_one("td:nth-of-type(7)").text.strip() == '' else i.select_one("td:nth-of-type(7)").text.strip() 36 | serious = 0 if i.select_one("td:nth-of-type(8)").text.strip() == '' else i.select_one("td:nth-of-type(8)").text.strip() 37 | 38 | table.add_row([sno, country, total_cases, new_cases, deaths, new_deaths, total_recovered, active_cases, serious]) 39 | 40 | if country == 'India': 41 | india.append(country) 42 | india.append(total_cases) 43 | india.append(new_cases) 44 | india.append(deaths) 45 | 46 | 47 | #Information about India 48 | country = t_items[-1].select_one("td:nth-of-type(1)").text.strip() 49 | total_cases = t_items[-1].select_one("td:nth-of-type(2)").text.strip() 50 | deaths = t_items[-1].select_one("td:nth-of-type(4)").text.strip() 51 | new_cases = t_items[-1].select_one("td:nth-of-type(3)").text.strip() 52 | 53 | print(table) 54 | print(f'\n{country} {total_cases}\tDeaths: {deaths}') 55 | 56 | 57 | #Creating the CSV File if not already present 58 | files = os.listdir() 59 | 60 | if filename not in files: 61 | with open(filename, 'w') as f: 62 | writer = csv.writer(f, delimiter=',', lineterminator='\n') 63 | writer.writerow(['DATE', 'TOTAL_CASES', 'DEATHS']) 64 | print(f'\nCSV File Created Successfully.\n') 65 | 66 | 67 | 68 | #Reading the CSV File 69 | with open(filename, 'r') as f: 70 | reader = csv.reader(f, delimiter=',', lineterminator='\n') 71 | data = list(reader) 72 | #print(f'{data}') 73 | 74 | 75 | if data[-1][0] == 'DATE': 76 | with open(filename, 'a') as f: 77 | writer = csv.writer(f, delimiter = ',', lineterminator = '\n') 78 | writer.writerow([today, int(total_cases.replace(',', '')), int(deaths.replace(',', ''))]) 79 | 80 | else: 81 | if data[-1][0] == today: 82 | data[-1][1] = str(max(int(data[-1][1].replace(',', '')), int(total_cases.replace(',', '')))) 83 | data[-1][2] = str(max(int(data[-1][2].replace(',', '')), int(deaths.replace(',', '')))) 84 | #print(f'{data}') 85 | with open(filename, 'w') as f: 86 | wr = csv.writer(f, delimiter= ',', lineterminator='\n') 87 | for item in data: 88 | wr.writerow(item) 89 | else: 90 | with open(filename, 'a') as f: 91 | writer = csv.writer(f, delimiter = ',', lineterminator = '\n') 92 | writer.writerow([today, int(total_cases.replace(',', '')), int(deaths.replace(',', ''))]) 93 | 94 | 95 | msg = f'{country} {total_cases}\tDeaths: {deaths}\n\n{india[0]}\tCases: {india[1]}({india[2]})\tDeaths: {india[3]}' 96 | Slack.slack_message(msg, __file__) 97 | print(f'{india[0]} --> Cases: {india[1]}({india[2]})\tDeaths: {india[3]}') 98 | 99 | 100 | ch = input('\n\nDo you want to know India\'s COVID-19 State wise Information ?(y/n): \n') 101 | if ch.lower() == 'y': 102 | import COVID19_India_Information as COVID_Ind 103 | 104 | -------------------------------------------------------------------------------- /Online_Coding_Platform_Rating_Tracker.py: -------------------------------------------------------------------------------- 1 | #Online Coding Platform Rating Tracker 2 | ''' 3 | Scrapes the Online Coding Platforms like Codechef, Codeforces, HackerEarth and SPOJ with the help of given URLs and 4 | extracts the rating for a given user and prints the rating. 5 | ''' 6 | try: 7 | import bs4 as bs 8 | import requests 9 | # To print the results in a Tabular Format 10 | from prettytable import PrettyTable 11 | import Slack_Push_Notification as Slack 12 | 13 | table = PrettyTable(['Coding Platform', 'Rating / Rank / Score']) 14 | 15 | 16 | #URLs of Coding Platforms 17 | cc_url = 'https://www.codechef.com/users/ramm_y2k' 18 | cf_url = 'http://codeforces.com/profile/iamram' 19 | he_url = 'https://www.hackerearth.com/users/pagelets/ram13/coding-data/' 20 | spoj_url = 'https://www.spoj.com/users/iam_ram/' 21 | ib_url = 'https://www.interviewbit.com/profile/i.am_ram/' 22 | lc_url = 'https://leetcode.com/ram_babu/' 23 | 24 | #Codeforces Scrapping 25 | cf_response = requests.get(cf_url) 26 | cf_html = cf_response.text 27 | 28 | cf_soup = bs.BeautifulSoup(cf_html, "lxml") 29 | 30 | #Extracting the rating and the position 31 | cf_rating = cf_soup.find('div', class_= 'info').find('ul').find('li').find('span').text 32 | cf_position = cf_soup.find('div', class_ = 'user-rank').find('span').text.strip() 33 | 34 | table.add_row(['Codeforces', cf_rating + ' (' + cf_position + ')']) 35 | 36 | 37 | 38 | #Codechef Scrapping 39 | cc_response = requests.get(cc_url) 40 | cc_html = cc_response.text 41 | 42 | cc_soup = bs.BeautifulSoup(cc_html, "lxml") 43 | 44 | #Extracting the rating and stars 45 | cc_rating = cc_soup.find('div', class_= 'rating-number').text 46 | cc_stars = cc_soup.find('div', class_ = 'rating-star').text 47 | 48 | table.add_row(['CodeChef', cc_rating + ' (' + cc_stars.strip() + ')']) 49 | 50 | 51 | 52 | #HackerEarth Scrapping 53 | he_response = requests.get(he_url) 54 | he_html = he_response.text 55 | 56 | he_soup = bs.BeautifulSoup(he_html, "lxml") 57 | 58 | #Extracting the Rating 59 | he_rating = he_soup.find('a', class_= 'dark weight-700').text 60 | table.add_row(['HackerEarth', he_rating]) 61 | 62 | 63 | #LeetCode Scrapping 64 | lc_response = requests.get(lc_url) 65 | lc_html = lc_response.text 66 | lc_soup = bs.BeautifulSoup(lc_html, 'lxml') 67 | 68 | lc_rating = lc_soup.findAll('span', class_= "badge")[1].text.strip() 69 | table.add_row(['LeetCode', lc_rating]) 70 | 71 | #SPOJ Scrapping 72 | spoj_response = requests.get(spoj_url) 73 | spoj_html = spoj_response.text 74 | spoj_soup = bs.BeautifulSoup(spoj_html, "lxml") 75 | 76 | temp = spoj_soup.find('div', class_= 'col-md-3') 77 | 78 | '''Either of the below will work - The Rank is present in the third

tag''' 79 | #spoj_rank = temp.find('p').find_next('p').find_next('p').text.strip() 80 | spoj_rank = temp.select_one("p:nth-of-type(3)").text.strip() 81 | table.add_row(['SPOJ', spoj_rank.split(':')[1]]) 82 | 83 | 84 | #Interview Bit Scraping 85 | ib_response = requests.get(ib_url) 86 | ib_response = ib_response.text 87 | ib_response = bs.BeautifulSoup(ib_response, 'lxml') 88 | ib_response = ib_response.find('div', class_= 'user-stats').find('div', class_= 'stat pull-left') 89 | ib_score = ib_response.find('div', class_ = 'txt').text 90 | table.add_row(['Interview Bit Score', ib_score]) 91 | 92 | except Exception as e: 93 | print(f'Exception Occurred! \n{e}') 94 | else: 95 | print(table) 96 | 97 | 98 | ''' Code to send a Slack Push Notification ''' 99 | msg = 'Codeforces Rating: {}\nCodechef Rating: {}\nHackerEarth: {}\nLeetCode - {}\nSPOJ - {}\nInterviewBit Score: {}'.format(cf_rating + ' ' + '(' + cf_position + ')', 100 | cc_rating + ' ' + '(' + cc_stars + ')' , 101 | he_rating, 102 | lc_rating, 103 | spoj_rank, 104 | ib_score) 105 | 106 | Slack.slack_message(msg, __file__) 107 | 108 | #print('\n**** Message Preview: **** \n{}'.format(msg)) 109 | --------------------------------------------------------------------------------