├── IP_host.py ├── README.md ├── bulk_image.py ├── spinning_donut.py ├── tic-tac-toe-icon.ico ├── tic-tac-toe.png ├── tic-tac-toe.py ├── url.png ├── url_shortener.py └── wifi_pass.py /IP_host.py: -------------------------------------------------------------------------------- 1 | '''This program is used to obtain IP address and Hostname of any URL/Website''' 2 | 3 | import socket 4 | 5 | def get_hostname_IP(): 6 | hostname = input("Please enter website address(URL):") 7 | try: 8 | print (f'Hostname: {hostname}') 9 | print (f'IP: {socket.gethostbyname(hostname)}') 10 | except socket.gaierror as error: 11 | print (f'Invalid Hostname, error raised is {error}') 12 | 13 | get_hostname_IP() -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PyRandoms 2 | Utility based python programs collection 3 | -------------------------------------------------------------------------------- /bulk_image.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | import requests as rq 3 | import os 4 | from bs4 import BeautifulSoup 5 | import time 6 | 7 | # path= E:\web scraping\chromedriver_win32\chromedriver.exe 8 | path = input("Enter Path : ") 9 | 10 | url = input("Enter URL : ") 11 | 12 | output = "output" 13 | 14 | 15 | def get_url(path, url): 16 | driver = webdriver.Chrome(executable_path=r"{}".format(path)) 17 | driver.get(url) 18 | print("loading.....") 19 | res = driver.execute_script("return document.documentElement.outerHTML") 20 | 21 | return res 22 | 23 | 24 | def get_img_links(res): 25 | soup = BeautifulSoup(res, "lxml") 26 | imglinks = soup.find_all("img", src=True) 27 | return imglinks 28 | 29 | 30 | def download_img(img_link, index): 31 | try: 32 | extensions = [".jpeg", ".jpg", ".png", ".gif"] 33 | extension = ".jpg" 34 | for exe in extensions: 35 | if img_link.find(exe) > 0: 36 | extension = exe 37 | break 38 | 39 | img_data = rq.get(img_link).content 40 | with open(output + "\\" + str(index + 1) + extension, "wb+") as f: 41 | f.write(img_data) 42 | 43 | f.close() 44 | except Exception: 45 | pass 46 | 47 | 48 | result = get_url(path, url) 49 | time.sleep(60) 50 | img_links = get_img_links(result) 51 | if not os.path.isdir(output): 52 | os.mkdir(output) 53 | 54 | for index, img_link in enumerate(img_links): 55 | img_link = img_link["src"] 56 | print("Downloading...") 57 | if img_link: 58 | download_img(img_link, index) 59 | print("Download Complete!!") -------------------------------------------------------------------------------- /spinning_donut.py: -------------------------------------------------------------------------------- 1 | import os 2 | from math import sin, cos 3 | 4 | def main(): 5 | a=0 6 | b=0 7 | 8 | height=24 9 | width=80 10 | 11 | clear = "cls" 12 | if os.name == "posix": 13 | clear = "clear" 14 | 15 | os.system(clear) 16 | while True: 17 | z = [0 for _ in range(4*height*width)] 18 | screen = [' ' for _ in range(height*width)] 19 | 20 | j=0 21 | while j<6.28: 22 | j+=0.07 23 | i=0 24 | while i<6.28: 25 | i+=0.02 26 | 27 | sinA=sin(a) 28 | cosA=cos(a) 29 | cosB=cos(b) 30 | sinB=sin(b) 31 | 32 | sini=sin(i) 33 | cosi=cos(i) 34 | cosj=cos(j) 35 | sinj=sin(j) 36 | 37 | cosj2=cosj+2 38 | mess=1/(sini*cosj2*sinA+sinj*cosA+5) 39 | t=sini*cosj2*cosA-sinj* sinA 40 | 41 | # 40 is the left screen shift 42 | x = int(40+30*mess*(cosi*cosj2*cosB-t*sinB)) 43 | # 12 is the down screen shift 44 | y = int(11+15*mess*(cosi*cosj2*sinB +t*cosB)) 45 | # all are casted to int, ie floored 46 | o = int(x+width*y) 47 | # multiplying by 8 to bring in range 0-11 as 8*(sqrt(2))=11 48 | # because we have 11 luminance characters 49 | N = int(8*((sinj*sinA-sini*cosj*cosA)*cosB-sini*cosj*sinA-sinj*cosA-cosi *cosj*sinB)) 50 | # if x,y inside screen and previous z-buffer is < mess 51 | # i.e. when z[o] is 0 or the prev point is behind the new point 52 | # so we change it to the point nearer to the eye/ above prev point 53 | if 00 else 0] 56 | 57 | # prints 58 | os.system(clear) 59 | for index, char in enumerate(screen): 60 | if index % width == 0: 61 | print() 62 | else: 63 | print(char, end='') 64 | 65 | # increments 66 | a+=0.04 67 | b+=0.02 68 | 69 | if __name__ == "__main__": 70 | main() -------------------------------------------------------------------------------- /tic-tac-toe-icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MainakRepositor/PyRandoms/86d5063bfa80d206b3fa448a95bc80769c4e2e1a/tic-tac-toe-icon.ico -------------------------------------------------------------------------------- /tic-tac-toe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MainakRepositor/PyRandoms/86d5063bfa80d206b3fa448a95bc80769c4e2e1a/tic-tac-toe.png -------------------------------------------------------------------------------- /tic-tac-toe.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | from tkinter import messagebox as MsgBox 3 | from PIL import Image, ImageTk 4 | 5 | 6 | # X starts so True 7 | 8 | 9 | clicked=True 10 | count=0 11 | # disable all buttons when winner is win 12 | 13 | def WithPlayer(): 14 | 15 | # Design the window 16 | root = Tk() 17 | root.geometry("550x390") 18 | root.title('Tic Tac Toe Friend') 19 | root.resizable(False, False) 20 | root.config(bg="yellow") 21 | root.iconbitmap('tic-tac-toe-icon.ico') 22 | 23 | image1 = Image.open('tic-tac-toe.png') 24 | test = ImageTk.PhotoImage(image1) 25 | Label(image=test, bg="yellow").place(x=370, y=10) 26 | 27 | # define variables 28 | clicked = True 29 | count = 0 30 | global playerX, playerO 31 | playerX=0 32 | playerO=0 33 | playerX_var=StringVar() 34 | playerO_var=StringVar() 35 | 36 | 37 | # note the score of player and show on display 38 | def PlayerScore(): 39 | # Update score of player X and player O 40 | playerX_var.set('Player X : '+str(playerX)) 41 | playerO_var.set('Player O : '+str(playerO)) 42 | Label(root,text='SCORE',font='Helvetica 20 bold',height=1,width=6,bg="yellow", fg='blue').place(x=380,y=140) 43 | Label(root,textvariable=playerX_var,font='Helvetica 15 bold',height=1,width=9,bg="yellow").place(x=380,y=180) 44 | Label(root,textvariable=playerO_var,font='Helvetica 15 bold',height=1,width=9,bg="yellow").place(x=380,y=210) 45 | 46 | # disable all button wif player is win otherwise match is draw 47 | def disable_all_buttons(): 48 | Label(root, text='Reset Game', font='Helvetica 15 bold', height=1, width=11, bg="yellow").place(x=85, y=360) 49 | b1.config(state=DISABLED) 50 | b2.config(state=DISABLED) 51 | b3.config(state=DISABLED) 52 | b4.config(state=DISABLED) 53 | b5.config(state=DISABLED) 54 | b6.config(state=DISABLED) 55 | b7.config(state=DISABLED) 56 | b8.config(state=DISABLED) 57 | b9.config(state=DISABLED) 58 | PlayerScore() 59 | 60 | # check if someone is won 61 | def CheckifWon(): 62 | global winner, playerX, playerO 63 | winner=False 64 | 65 | # 1st Row 66 | global count, clicked 67 | if b1['text']=='X' and b2['text']=='X' and b3['text']=='X': 68 | b1.config(bg='red') 69 | b2.config(bg='red') 70 | b3.config(bg='red') 71 | winner=True 72 | playerX = playerX+1 73 | MsgBox.showinfo('Tic Tac Toe', 'Player X is win') 74 | disable_all_buttons() 75 | 76 | # 2nd Row 77 | if b4['text']=='X' and b5['text']=='X' and b6['text']=='X': 78 | b4.config(bg='red') 79 | b5.config(bg='red') 80 | b6.config(bg='red') 81 | winner=True 82 | MsgBox.showinfo('Tic Tac Toe', 'Player X is win') 83 | playerX+=1 84 | disable_all_buttons() 85 | 86 | 87 | # 3rd Row 88 | if b7['text']=='X' and b8['text']=='X' and b9['text']=='X': 89 | b7.config(bg='red') 90 | b8.config(bg='red') 91 | b9.config(bg='red') 92 | winner=True 93 | MsgBox.showinfo('Tic Tac Toe', 'Player X is win') 94 | playerX+=1 95 | disable_all_buttons() 96 | 97 | 98 | # 1st column 99 | if b1['text']=='X' and b4['text']=='X' and b7['text']=='X': 100 | b1.config(bg='red') 101 | b4.config(bg='red') 102 | b7.config(bg='red') 103 | winner=True 104 | MsgBox.showinfo('Tic Tac Toe', 'Player X is win') 105 | disable_all_buttons() 106 | # 2nd column 107 | if b2['text']=='X' and b5['text']=='X' and b8['text']=='X': 108 | b2.config(bg='red') 109 | b5.config(bg='red') 110 | b8.config(bg='red') 111 | winner=True 112 | MsgBox.showinfo('Tic Tac Toe','Player X is win') 113 | playerX+=1 114 | disable_all_buttons() 115 | # 3rd column 116 | if b3['text']=='X' and b6['text']=='X' and b9['text']=='X': 117 | b3.config(bg='red') 118 | b6.config(bg='red') 119 | b9.config(bg='red') 120 | winner=True 121 | MsgBox.showinfo('Tic Tac Toe','Player X is win') 122 | playerX+=1 123 | disable_all_buttons() 124 | 125 | # if 1 , 5, and 9 box is matching 126 | if b1['text']=='X' and b5['text']=='X' and b9['text']=='X': 127 | b1.config(bg='red') 128 | b5.config(bg='red') 129 | b9.config(bg='red') 130 | winner=True 131 | MsgBox.showinfo('Tic Tac Toe','Player X is win') 132 | playerX+=1 133 | disable_all_buttons() 134 | 135 | # if 3 , 5, and 7 box is matching 136 | if b3['text']=='X' and b5['text']=='X' and b7['text']=='X': 137 | b3.config(bg='red') 138 | b5.config(bg='red') 139 | b7.config(bg='red') 140 | winner=True 141 | MsgBox.showinfo('Tic Tac Toe','Player X is win') 142 | playerX+=1 143 | disable_all_buttons() 144 | 145 | # IF O PLAYERS WINNER 146 | # 1st row 147 | if b1['text']=='O' and b2['text']=='O' and b3['text']=='O': 148 | b1.config(bg='red') 149 | b2.config(bg='red') 150 | b3.config(bg='red') 151 | winner=True 152 | MsgBox.showinfo('Tic Tac Toe','Player O is win') 153 | playerO += 1 154 | disable_all_buttons() 155 | # 2ND ROW 156 | if b4['text']=='O' and b5['text']=='O' and b6['text']=='O': 157 | b4.config(bg='red') 158 | b5.config(bg='red') 159 | b6.config(bg='red') 160 | winner=True 161 | MsgBox.showinfo('Tic Tac Toe','Player O is win') 162 | playerO += 1 163 | disable_all_buttons() 164 | 165 | if b7['text']=='O' and b8['text']=='O' and b9['text']=='O': 166 | b7.config(bg='red') 167 | b8.config(bg='red') 168 | b9.config(bg='red') 169 | winner=True 170 | MsgBox.showinfo('Tic Tac Toe','Player O is win') 171 | playerO += 1 172 | disable_all_buttons() 173 | 174 | if b1['text']=='O' and b4['text']=='O' and b7['text']=='O': 175 | b1.config(bg='red') 176 | b4.config(bg='red') 177 | b7.config(bg='red') 178 | winner=True 179 | MsgBox.showinfo('Tic Tac Toe','Player O is win') 180 | playerO += 1 181 | disable_all_buttons() 182 | 183 | if b2['text']=='O' and b5['text']=='O' and b8['text']=='O': 184 | b2.config(bg='red') 185 | b5.config(bg='red') 186 | b8.config(bg='red') 187 | winner=True 188 | MsgBox.showinfo('Tic Tac Toe','Player O is win') 189 | playerO += 1 190 | disable_all_buttons() 191 | 192 | if b3['text']=='O' and b6['text']=='O' and b9['text']=='O': 193 | b3.config(bg='red') 194 | b6.config(bg='red') 195 | b9.config(bg='red') 196 | winner=True 197 | MsgBox.showinfo('Tic Tac Toe','Player O is win') 198 | playerO += 1 199 | disable_all_buttons() 200 | 201 | if b1['text']=='O' and b5['text']=='O' and b9['text']=='O': 202 | b1.config(bg='red') 203 | b5.config(bg='red') 204 | b9.config(bg='red') 205 | winner=True 206 | MsgBox.showinfo('Tic Tac Toe', 'Player O is win') 207 | playerO += 1 208 | disable_all_buttons() 209 | 210 | if b3['text']=='O' and b5['text']=='O' and b7['text']=='O': 211 | b3.config(bg='red') 212 | b5.config(bg='red') 213 | b7.config(bg='red') 214 | winner=True 215 | MsgBox.showinfo('Tic Tac Toe', 'Player O is win') 216 | playerO += 1 217 | disable_all_buttons() 218 | 219 | if count > 8: 220 | MsgBox.showinfo('Tic Tac Toe', 'Match is Tie') 221 | disable_all_buttons() 222 | 223 | # Button clicked function 224 | def b_click(b): 225 | global clicked, count 226 | if b['text']==" " and clicked==True: 227 | b['text']='X' 228 | clicked=False 229 | count+=1 230 | Label(root, text='Player O turn ', font='Helvetica 15 bold', height=1, width=11, bg="yellow").place(x=85, y=360) 231 | CheckifWon() 232 | 233 | 234 | elif b['text']==' ' and clicked==False: 235 | b['text']='O' 236 | clicked=True 237 | count+=1 238 | Label(root, text='Player X turn', font='Helvetica 15 bold', height=1, width=11, bg="yellow").place(x=85, y=360) 239 | CheckifWon() 240 | 241 | else: 242 | MsgBox.showerror('Tic Tac Toe','Hey! this box is already selected \n pick Another one') 243 | 244 | # reset all value when user click on reset 245 | def reset(): 246 | global clicked, count, playerX, playerO 247 | clicked = True 248 | count = 0 249 | global b1, b2, b3, b4, b5, b6, b7, b8, b9, Reset_Button 250 | Label(root, text='Player X turn ', font='Helvetica 15 bold', height=1, width=11, bg="yellow").place(x=85, y=360) 251 | b1 = Button(root, text=" ", font='Helvetica 20', height=3, width=6, bg="SystemButtonFace", command=lambda: b_click(b1)) 252 | b2 = Button(root, text=" ", font='Helvetica 20', height=3, width=6, bg="SystemButtonFace", command=lambda: b_click(b2)) 253 | b3=Button(root, text=" ", font='Helvetica 20', height=3, width=6, bg="SystemButtonFace", command=lambda: b_click(b3)) 254 | b1.grid(row=0, column=0) 255 | b2.grid(row=0, column=1) 256 | b3.grid(row=0, column=2) 257 | 258 | b4 = Button(root, text=" ", font='Helvetica 20', height=3, width=6, bg="SystemButtonFace", command=lambda: b_click(b4)) 259 | b5 = Button(root, text=" ", font='Helvetica 20', height=3, width=6, bg="SystemButtonFace", command=lambda: b_click(b5)) 260 | b6 = Button(root, text=" ", font='Helvetica 20', height=3, width=6, bg="SystemButtonFace", command=lambda: b_click(b6)) 261 | b4.grid(row=1, column=0) 262 | b5.grid(row=1, column=1) 263 | b6.grid(row=1, column=2) 264 | 265 | b7 = Button(root, text=" ", font='Helvetica 20', height=3, width=6, bg="SystemButtonFace", command=lambda: b_click(b7)) 266 | b8 = Button(root, text=" ", font='Helvetica 20', height=3, width=6, bg="SystemButtonFace", command=lambda: b_click(b8)) 267 | b9 = Button(root, text=" ", font='Helvetica 20', height=3, width=6, bg="SystemButtonFace", command=lambda: b_click(b9)) 268 | b7.grid(row=2, column=0) 269 | b8.grid(row=2, column=1) 270 | b9.grid(row=2, column=2) 271 | 272 | reset() 273 | PlayerScore() 274 | 275 | 276 | # reset button 277 | Reset_Button = Button(root, text = 'RESET', font='Helvetica 13 bold', height=1, width=17, bg="#4e5153", fg='#ffffff', command= reset) 278 | Reset_Button.place(x=350, y=260) 279 | # exit button 280 | Button(root, text='EXIT', font='Helvetica 12 bold', height=1, width=17,bg="#4e5153", fg='#ffffff', command=root.destroy).place(x=350, y=310) 281 | 282 | 283 | 284 | root.mainloop() 285 | 286 | 287 | 288 | WithPlayer() -------------------------------------------------------------------------------- /url.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MainakRepositor/PyRandoms/86d5063bfa80d206b3fa448a95bc80769c4e2e1a/url.png -------------------------------------------------------------------------------- /url_shortener.py: -------------------------------------------------------------------------------- 1 | import pyshorteners 2 | from tkinter import * 3 | from PIL import Image, ImageTk 4 | 5 | root = Tk() 6 | root.geometry('400x420') 7 | root.resizable(False, False) 8 | root.title('ChhotUrl') 9 | root.config(bg='#4a536b') 10 | 11 | 12 | image = Image.open('url.png') 13 | test = ImageTk.PhotoImage(image) 14 | Label(image=test, bg='#4a536b').pack() 15 | 16 | url = StringVar() 17 | url_short = StringVar() 18 | 19 | Label(root, text='URL Shortener', bg='#4a536b', fg='#ff9a8d', font='Times 22 bold').pack() 20 | Label(root, text='Made by : Mainak', bg='#4a536b', fg='#34deeb', font='Times 18 bold italic').pack() 21 | 22 | 23 | Label(root, text='Enter URL here', bg='#4a536b', fg='#aed6dc', font='Times 10 bold').place(x=50, y=220) 24 | Entry(root, textvariable= url, width=35, font='Times 12' ).place(x=50, y=240) 25 | 26 | Label(root, text='URl Shortener here (copy and paste on browser tab)', bg='#4a536b', fg='#aed6dc', font='Times 10 bold').place(x=50, y=330) 27 | text = Entry(root, width=47, textvariable=url_short) 28 | text.place(x = 50, y=350) 29 | 30 | def Convert_fun(): 31 | con_url = pyshorteners.Shortener().tinyurl.short(url.get()) 32 | url_short.set(con_url) 33 | 34 | 35 | Button(root, text= 'Convert', bg='yellow', fg='#000', font='Times 15 bold', command=Convert_fun).place(x=150, y=280) 36 | 37 | root.mainloop() -------------------------------------------------------------------------------- /wifi_pass.py: -------------------------------------------------------------------------------- 1 | import subprocess 2 | 3 | data = ( 4 | subprocess.check_output(["netsh", "wlan", "show", "profiles"]) 5 | .decode("utf-8") 6 | .split("\n") 7 | ) 8 | profiles = [i.split(":")[1][1:-1] for i in data if "All User Profile" in i] 9 | for i in profiles: 10 | results = ( 11 | subprocess 12 | .check_output(["netsh", "wlan", "show", "profile", i, "key=clear"]) 13 | .decode("utf-8") 14 | .split("\n") 15 | ) 16 | results = [b.split(":")[1][1:-1] for b in results if "Key Content" in b] 17 | try: 18 | print("{:<30}| {:<}".format(i, results[0])) 19 | except IndexError: 20 | print("{:<30}| {:<}".format(i, "")) --------------------------------------------------------------------------------