Header Ads Widget

Miscellaneous PY Codes

 1. Create Virus using PY


import subprocess
from time import sleep
while True:

        subprocess.Popen('notepad') #use artificial multithreading
        subprocess.Popen('calc') #use artificial multithreading
        subprocess.Popen('explorer') #use artificial multithreading
        subprocess.Popen('mspaint') #use artificial multithreading
        subprocess.Popen('excel') #use artificial multithreading
        subprocess.Popen('write') #use artificial multithreading
        sleep(.05)              


Warning :- This result might be harmful for your PC. It can crash some files from                       your PC.



2. Getting CPU Info


import psutil

print("Physical cores:", psutil.cpu_count(logical=False))
print("Total cores:", psutil.cpu_count(logical=True))

cpufreq = psutil.cpu_freq()
print(f"Max Frequency: {cpufreq.max: .2f}Mhz")
print(f"Min Frequency: {cpufreq.min: .2f}Mhz")
print(f"Current Frequency: {cpufreq.current: .2f}Mhz")

print("cpu Usage Per Core:")
for i, percentage in enumerate(psutil.cpu_percent(percpu=True, interval=1)):
    print(f"Core{i}: {percentage}%")
print(f"Total CPU Usage: {psutil.cpu_percent()}%")


Output :-


Physical cores: 2
Total cores: 4
Max Frequency:  2401.00Mhz
Min Frequency:  0.00Mhz
Current Frequency:  2401.00Mhz
cpu Usage Per Core:
Core0: 29.2%
Core1: 35.4%
Core2: 40.0%
Core3: 12.5%
Total CPU Usage: 29.7%

 
Note :- This result is different in different PCs. So, if you got changed statistics from above don't be worry. It just shows it's CPU Information.


3. Taking Screenshot


import os
import pyautogui
def screenshot():

    save_path = os.path.join(os.path.expanduser("~"), "Pictures")
    shot = pyautogui.screenshot()
    shot.save(f"{save_path}\\python_screenshot.png")
    return print(f"\nScreenshot taken, and saved to {save_path}")

if __name__ =="__main__":
    screenshot();


Note :- This will take screenshot of your running application page!


4. Generator QR Code


import os
import pyqrcode
from PIL import Image

class QR_Gen(object):
    def __init__(self, text):
        self.qr_image = self.qr_generator(text)

    @staticmethod
    def qr_generator(text):
        qr_code = pyqrcode.create(text)
        file_name = "QR Code Result"
        save_path = os.path.join(os.path.expanduser('~'), 'Desktop')
        name = f"{save_path}{file_name}.png"
        qr_code.png(name, scale=10)
        image = Image.open(name)
        image = image.resize((400,400),Image.ANTIALIAS)
        image.show()

if __name__=="__main__":
   QR_Gen(input("[QR] Enter text or link:"))


Note :- When you try this code, you have to enter any particular link. So, it will create QR code for that link or text!



5. Youtube Video Downloader


from tkinter import *
from pytube import YouTube

root = Tk()
root.geometry('500x300')
root.resizable(0,0)
root.title("Anonymous youtube video downloader")

Label(root,text = 'Youtube Video Downloader', font ='arial 20 bold').pack()

link = StringVar()

Label(root, text = 'Paste Link Here:', font = 'arial 15 bold').place(x= 160 , y = 60)
link_enter = Entry(root, width = 70,textvariable = link).place(x = 32, y = 90)

def Downloader():
    url =YouTube(str(link.get()))
    video = url.streams.first()
    video.download()
    Label(root, text = 'DOWNLOADED', font = 'arial 15').place(x= 180 , y = 210)

Button(root,text = 'DOWNLOAD', font = 'arial 15 bold' ,bg = 'pale violet red', padx = 2, command = Downloader).place(x=180 ,y = 150)

root.mainloop()


Note :- Youtube video will be download in project file path!



6. Alarm Clock


#Importing all the necessary libraries to form the alarm clock:
from tkinter import *
import datetime
import time
import winsound

def alarm(set_alarm_timer):
    while True:
        time.sleep(1)
        current_time = datetime.datetime.now()
        now = current_time.strftime("%H:%M:%S")
        date = current_time.strftime("%d/%m/%Y")
        print("The Set Date is:",date)
        print(now)
        if now == set_alarm_timer:
            print("Time to Wake up")
        winsound.PlaySound("sound.wav",winsound.SND_ASYNC)
        break

def actual_time():
    set_alarm_timer = f"{hour.get()}:{min.get()}:{sec.get()}"
    alarm(set_alarm_timer)

clock = Tk()

clock.title(" Anonymous Alarm Clock")
clock.geometry("400x200")
time_format=Label(clock, text= "Enter time in 24 hour format!", fg="red",bg="black",font="Arial").place(x=60,y=120)
addTime = Label(clock,text = "Hour  Min   Sec",font=60).place(x = 110)
setYourAlarm = Label(clock,text = "Which time should I wake you up?",fg="blue",relief = "solid",font=("Helevetica",7,"bold")).place(x=110,y=50)

# The Variables we require to set the alarm(initialization):
hour = StringVar()
min = StringVar()
sec = StringVar()

#Time required to set the alarm clock:
hourTime= Entry(clock,textvariable = hour,bg = "pink",width = 15).place(x=110,y=30)
minTime= Entry(clock,textvariable = min,bg = "pink",width = 15).place(x=150,y=30)
secTime = Entry(clock,textvariable = sec,bg = "pink",width = 15).place(x=200,y=30)

#To take the time input by user:
submit = Button(clock,text = "Set Alarm",fg="red",width = 10,command = actual_time).place(x =110,y=70)

clock.mainloop()
#Execution of the window.


Note :- Enter Time in 24-hours Format!!




7. Upload Insta post using PY Code


from instabot import Bot
bot = Bot()
bot.login(username="user_name", password="user_password")
bot.upload_photo("YourPost.jpg", caption="caption of Post Here")


Note :- This will automatically post your photo on instagram feed, just by entering your username and password.




8. Check Weather Updates


import requests
from bs4 import BeautifulSoup
search="Weather in Mehsana"
url = f"https://www.google.com/search?&q={search}"
r = requests.get(url)
s = BeautifulSoup(r.text,"html.parser")
update = s.find("div",class_="BNeawe").text
print(update)


Output :-


36°C

This will print ( show ) your area's current temperature.


9. Fibonacci Sequence



terms = int(input("Enter the Number:"))
a = 0
b = 1
count = 0

if (terms<=0):
   print("Please enter a valid integer")
elif (terms==1):
   print("Fibonacci Sequence  upto", terms, ":")
   print(a)

else:
   print("Fibonacci sequence:")
   while (count < terms):
      print(a, end = ' ')
      c = a+b
      #updating values
      a = b
      b = c
      count +=1


Output :-

 

Enter the terms : 10

Fibonacci Sequence :
0 1 1 2 3 5 8 13 21 34



9. Shut Down the computer


import os
os.system('shutdown -s')


Warning :- This will shutdown your computer, so if you want to try this, first clear all the running apps and then try it!



Post a Comment

0 Comments