Posts

Showing posts with the label Python

Automatic raining alert project with Python

Introduction:  This simple python project alerts you if it will rain in the next defined hour. All you have to do is sign up openweather API and Twilio messaging service and replace your API key below.  CODE: import requests as w import datetime import os from twilio.rest import Client END_POINT = "https://api.openweathermap.org/data/2.5/onecall" api_key = "enter_your_weather_api_key_here" long = "83.995590" lat = "28.237988" account_sid = "your_twilio_account_sid" auth_token = "your_twilio_auth_token" twilo_ph = "twilo_phone_no" client = Client(account_sid, auth_token) api_param = { "lat" : lat, "lon" : long, "appid" : api_key } response = w.get(END_POINT, params=api_param, ).json() weather = response[ "hourly" ][:13] is_raining = False for weather_data in weather: condition_code = weather_data[ "weather" ][0][ "id" ] if condition_code ...

Python Script to import CSV data into MySQL Database

import pandas as pd  import mysql.connector as msql  from mysql.connector import Error  HOST = "localhost"  DATABASE = "Employees"  USER = "root"  PATH = "data/employees.csv"  data = pd.read_csv(PATH)  data = data.to_dict(orient="records")  val = [(dept["emp_no"], dept["emp_title_id"],dept["birth_date"], dept["first_name"], dept["last_name"], dept["sex"], dept["hire_date"]) for dept in data]  try: conn = msql.connect(host= HOST, database=DATABASE, user=USER, password='')        if conn.is_connected():             cursor = conn.cursor()             sql = "INSERT INTO employees (emp_no,emp_title,                          birth_date,first_name,last_name,gender,hire_date) VALUES (%s, %s, %s, %s, %s, %s, %s)" cursor.executemany(sql, val)   ...

Automatically Send Happy Birthday Message using Python Code

 Introduction:  This application will help you to send happy birthday wishes to your friend without any hassle. The code will automatically send an email when the birthday will come. This simple python code will strengthen your friendship.  CODE: main.py import smtplib my_email = "youremail@gmail.com" password = "1234abcd()" to_email = " nandalalsun@gmail.com" def send_quots(quots, day): with smtplib.SMTP( 'smtp.gmail.com' , 587) as connection: connection.starttls() connection.login(user=my_email, password=password) connection.sendmail( from_addr=my_email, to_addrs= to_email , msg= f"Subject: { day } Quots \n\n { quots } " ) import datetime as d import random day = d.datetime.now() today = day.strftime( "%A" ) if today.upper() == "FRIDAY" : while True : with open( "wishes.txt" , mode= "r" ) as quots: # d...

Password Manager Application in Python

Image
Introduction:  This application will help to generate a very strong password, save passwords and find whenever is needed.  This is a very simple application builted in Python.  It is very suitable for python beginner learners and students who want to learn python and useful for college projects . This application also has Copied to clipboard Feature, in which, while generating a new password, you don't have to copy it. It automatically saves in your clipboard, you can directly paste wherever you need. CODE: from tkinter import * from tkinter import messagebox from random import randint, choice, shuffle import pyperclip import json letters = [ 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' , 'j' , 'k' , 'l' , 'm' , 'n' , 'o' , 'p' , 'q' , 'r' , 's' , 't' , 'u' , 'v' , 'w' , 'x' , 'y...

Blind Auction Application: Python Project

 Introduction: Blind Auction is a very simple python project, suitable for python beginners. It has very simple logic, the user will input as many as a bidder and their price and program will compare their bidding price and shows up the highest bidder as a winner.  Code: main.py from replit import clear #HINT: You can call clear() to clear the output in the console. from art import logo print(logo) name_add = True dictionary = {} price_list = [] name_list = [] while name_add is not False: name = input("What is your name?\n") price = input("What is your bid price?\n") name_list.append(name) price_list.append(price) clear() is_another = input("Do you want to add another bidder? Y or N\n").lower() if is_another != "y": name_add = False clear() dictionary["name"] = name_list dictionary["bid"] = price_list max_price = max(dictionary["bid"]) print(f"Winner is: {(dictionary['name'][diction...

Pomodoro timer application using Python

Image
 Introduction:  The  Pomodoro Technique  is a time management  method  developed by Francesco Cirillo in the late 1980s. The  technique  uses a timer to break down work into intervals, traditionally 25 minutes in length, separated by short breaks. CODE: main.py from tkinter import * import math # ---------------------------- CONSTANTS ------------------------------- # PINK = "#e2979c" RED = "#e7305b" GREEN = "#9bdeac" YELLOW = "#f7f5dd" FONT_NAME = "Courier" WORK_MIN = 25 SHORT_BREAK_MIN = 5 LONG_BREAK_MIN = 20 rept = 0 timer_v = None # ---------------------------- TIMER RESET ------------------------------- # def timer_cancle(): window.after_cancel(timer_v) timer_txt.config( text = "Timer" ) canvas.itemconfig(timer_text, text = "00:00" ) check_mark.config( text = "" ) global rept rept = 0 # ---------------------------- TIMER MECHANISM ------------------------------- # def start(): ...

U.S State guessing game using Python

Image
 Introduction: This game is very simple and easy to make. Using python and turtle library, this game is made in a simple way. User guesses the name of the U.S states and if the guess is right, the name will be printed in respective coordinate. And if the user guesses all the state right game will end, or if the user type secret code: "exit" the game will again exit. How to exit the game: 1. Complete all the answers 2. or Type "exit" as a secret code Code: main.py import turtle import pandas data = pandas.read_csv( "50_states.csv" ) all_state = data[ "state" ].to_list() title_score = 0 screen = turtle.Screen() image = "blank_states_img.gif" screen.addshape(image) turtle.shape(image) correct_answer = [] while len (correct_answer) < 50 : answer = screen.textinput( title = f" { len (correct_answer) } /50 States correct" , prompt = "Enter the name of states:" ).title() if answer == "Exit" : mi...

Number Guessing Game in Python

 Number Guessing Game Introduction of game:   Very simple game in python which is suitable for beginners of python learner. The user makes a guess and the system tell whether the guess is high or low? and this process continues until the user makes it right under the given chances. There are basically two level of game, Hard and Easy: in the hard level user will get 5 chances and on the Easy level user will have 10 chances.  First   #Create main.py file and paste the following code from art import logo from random import random import math print(logo) print("Welcome to the Number Guess Game!") print("I think of a number between 1 and 100") HARD_LEVEL_CHANCE = 5 EASY_LEVEL_CHANCE = 10 difficulty_level = input("Choose level, 'hard' or 'easy':\n").lower() answer = math.ceil(random()*100) end = False def check_answer(guess, answer, count): print(f"{level - count} times remaning") if guess > answer: return "Too high...

Bounce Ball Game in Python

  Create main.py file and paste the following code from turtle import Turtle, Screen from paddle import Paddle from ball import Ball import time from score_board import ScoreBoard screen = Screen() screen.listen() screen.setup(height=600, width=1000) screen.title( "PinPong Game" ) screen.bgcolor( "Black" ) screen.tracer(0) r_paddle = Paddle((480, 0)) l_paddle = Paddle((-490, 0)) ball = Ball((0, 0)) screen.onkey(r_paddle.move_up, "Up" ) screen.onkey(r_paddle.move_down, "Down" ) screen.onkey(l_paddle.move_up, "w" ) screen.onkey(l_paddle.move_down, "s" ) score = ScoreBoard() game_on = True while game_on: screen.update() time.sleep(ball.bounce_speed) ball.change_location() if ball.ycor() < -275 or ball.ycor() > 280: ball.bounce_on_wall() elif ball.distance(l_paddle) < 50 and ball.xcor() < -460: score.score_update_l() ball.bounce_on_peddle() elif ball.distance(r_paddle) ...