diff --git a/JARVIS/JARVIS.py b/JARVIS/JARVIS.py index 9bc2ca9c56e..09cf56ba166 100644 --- a/JARVIS/JARVIS.py +++ b/JARVIS/JARVIS.py @@ -1,7 +1,7 @@ ######### -__author__ = 'Mohammed Shokr ' -__version__ = 'v 0.1' +__author__ = "Mohammed Shokr " +__version__ = "v 0.1" """ JARVIS: @@ -11,21 +11,24 @@ # import modules import datetime # datetime module supplies classes for manipulating dates and times import subprocess # subprocess module allows you to spawn new processes + # master import pyjokes import requests import json from PIL import Image, ImageGrab from gtts import gTTS + # for 30 seconds clip "Jarvis, clip that!" and discord ctrl+k quick-move (might not come to fruition) from pynput import keyboard from pynput.keyboard import Key, Listener from pynput.mouse import Button, Controller + # ======= from playsound import * # for sound output + # master -import \ - speech_recognition as sr # speech_recognition Library for performing speech recognition with support for Google Speech Recognition, etc.. +import speech_recognition as sr # speech_recognition Library for performing speech recognition with support for Google Speech Recognition, etc.. # pip install pyttsx3 # need to run only once to install the library @@ -37,60 +40,66 @@ # initialisation engine = pyttsx3.init() -voices = engine.getProperty('voices') -engine.setProperty('voice', voices[0].id) -engine.setProperty('rate', 150) -exit_jarvis=False +voices = engine.getProperty("voices") +engine.setProperty("voice", voices[0].id) +engine.setProperty("rate", 150) +exit_jarvis = False + + def speak(audio): engine.say(audio) engine.runAndWait() + def speak_news(): - url = 'http://newsapi.org/v2/top-headlines?sources=the-times-of-india&apiKey=yourapikey' + url = "http://newsapi.org/v2/top-headlines?sources=the-times-of-india&apiKey=yourapikey" news = requests.get(url).text news_dict = json.loads(news) - arts = news_dict['articles'] - speak('Source: The Times Of India') - speak('Todays Headlines are..') + arts = news_dict["articles"] + speak("Source: The Times Of India") + speak("Todays Headlines are..") for index, articles in enumerate(arts): - speak(articles['title']) + speak(articles["title"]) if index == len(arts) - 1: break - speak('Moving on the next news headline..') - speak('These were the top headlines, Have a nice day Sir!!..') + speak("Moving on the next news headline..") + speak("These were the top headlines, Have a nice day Sir!!..") def sendEmail(to, content): - server = smtplib.SMTP('smtp.gmail.com', 587) + server = smtplib.SMTP("smtp.gmail.com", 587) server.ehlo() server.starttls() - server.login('youremail@gmail.com', 'yourr-password-here') - server.sendmail('youremail@gmail.com', to, content) + server.login("youremail@gmail.com", "yourr-password-here") + server.sendmail("youremail@gmail.com", to, content) server.close() + def wishme(): - #This function wishes user - hour=int(datetime.datetime.now().hour) - if(hour>=0 and hour<12): + # This function wishes user + hour = int(datetime.datetime.now().hour) + if hour >= 0 and hour < 12: speak("Good Morning!") - elif(hour>=12 and hour<18): + elif hour >= 12 and hour < 18: speak("Good Afternoon!") else: speak("Good Evening !") speak("I m Jarvis ! how can I help you sir") + + # obtain audio from the microphone def takecommand(): - #it takes user's command and returns string output + # it takes user's command and returns string output wishme() - r=sr.Recognizer() + r = sr.Recognizer() with sr.Microphone() as source: print("Listening...") - r.pause_threshold=1 - r.dynamic_energy_threshold=500 - audio=r.listen(source) + r.pause_threshold = 1 + r.dynamic_energy_threshold = 500 + audio = r.listen(source) try: print("Recognizing...") - query=r.recognize_google(audio,language="en-in") + query = r.recognize_google(audio, language="en-in") print(f"User said {query}\n") except Exception as e: print("Say that again please...") @@ -100,9 +109,9 @@ def takecommand(): # for audio output instead of print def voice(p): - myobj = gTTS(text=p, lang='en', slow=False) - myobj.save('try.mp3') - playsound('try.mp3') + myobj = gTTS(text=p, lang="en", slow=False) + myobj.save("try.mp3") + playsound("try.mp3") # recognize speech using Google Speech Recognition @@ -115,15 +124,16 @@ def on_press(key): k = key.char # single-char keys except: k = key.name # other keys - if k in ['1', '2', 'left', 'right']: # keys of interest + if k in ["1", "2", "left", "right"]: # keys of interest # self.keys.append(k) # store it in global-like variable - print('Key pressed: ' + k) + print("Key pressed: " + k) return False # stop listener; remove this if want more keys + + # Run Application with Voice Command Function # only_jarvis def on_release(key): - print('{0} release'.format( - key)) + print("{0} release".format(key)) if key == Key.esc(): # Stop listener return False @@ -177,8 +187,10 @@ def get_app(self): # ======= """ + + def get_app(Q): - current=Controller() + current = Controller() # master if Q == "time": print(datetime.now()) @@ -188,21 +200,21 @@ def get_app(Q): speak_news() elif Q == "open notepad": - subprocess.call(['Notepad.exe']) + subprocess.call(["Notepad.exe"]) elif Q == "open calculator": - subprocess.call(['calc.exe']) + subprocess.call(["calc.exe"]) elif Q == "open stikynot": - subprocess.call(['StikyNot.exe']) + subprocess.call(["StikyNot.exe"]) elif Q == "open shell": - subprocess.call(['powershell.exe']) + subprocess.call(["powershell.exe"]) elif Q == "open paint": - subprocess.call(['mspaint.exe']) + subprocess.call(["mspaint.exe"]) elif Q == "open cmd": - subprocess.call(['cmd.exe']) + subprocess.call(["cmd.exe"]) elif Q == "open discord": - subprocess.call(['discord.exe']) + subprocess.call(["discord.exe"]) elif Q == "open browser": - subprocess.call(['C:\Program Files\Internet Explorer\iexplore.exe']) + subprocess.call(["C:\Program Files\Internet Explorer\iexplore.exe"]) # patch-1 elif Q == "open youtube": webbrowser.open("https://www.youtube.com/") # open youtube @@ -210,7 +222,9 @@ def get_app(Q): webbrowser.open("https://www.google.com/") # open google elif Q == "open github": webbrowser.open("https://github.com/") - elif Q == "email to other": # here you want to change and input your mail and password whenver you implement + elif ( + Q == "email to other" + ): # here you want to change and input your mail and password whenver you implement try: speak("What should I say?") r = sr.Recognizer() @@ -219,7 +233,7 @@ def get_app(Q): r.pause_threshold = 1 audio = r.listen(source) to = "abc@gmail.com" - content=input("Enter content") + content = input("Enter content") sendEmail(to, content) speak("Email has been sent!") except Exception as e: @@ -230,9 +244,9 @@ def get_app(Q): elif Q == "Take screenshot": snapshot = ImageGrab.grab() drive_letter = "C:\\" - folder_name = r'downloaded-files' + folder_name = r"downloaded-files" folder_time = datetime.datetime.now().strftime("%Y-%m-%d_%I-%M-%S_%p") - extention = '.jpg' + extention = ".jpg" folder_to_save_files = drive_letter + folder_name + folder_time + extention snapshot.save(folder_to_save_files) @@ -240,15 +254,15 @@ def get_app(Q): speak(pyjokes.get_joke()) elif Q == "start recording": - current.add('Win', 'Alt', 'r') + current.add("Win", "Alt", "r") speak("Started recording. just say stop recording to stop.") elif Q == "stop recording": - current.add('Win', 'Alt', 'r') + current.add("Win", "Alt", "r") speak("Stopped recording. check your game bar folder for the video") elif Q == "clip that": - current.add('Win', 'Alt', 'g') + current.add("Win", "Alt", "g") speak("Clipped. check you game bar file for the video") with keyboard.Listener(on_press=on_press, on_release=on_release) as listener: listener.join() @@ -256,14 +270,8 @@ def get_app(Q): else: exit() - - - - - # master - apps = { "time": datetime.datetime.now(), "notepad": "Notepad.exe", @@ -272,18 +280,15 @@ def get_app(Q): "shell": "powershell.exe", "paint": "mspaint.exe", "cmd": "cmd.exe", - "browser": "C:\Program Files\Internet Explorer\iexplore.exe" + "browser": "C:\Program Files\Internet Explorer\iexplore.exe", } # master - - - # Call get_app(Query) Func. -if __name__ == '__main__': +if __name__ == "__main__": while not exit_jarvis: - Query=takecommand().lower() + Query = takecommand().lower() get_app(Query) - exit_jarvis=True + exit_jarvis = True diff --git a/Test-Case-Generator/test_case.py b/Test-Case-Generator/test_case.py index 7c3bfe65648..05c9e77d60a 100644 --- a/Test-Case-Generator/test_case.py +++ b/Test-Case-Generator/test_case.py @@ -9,55 +9,164 @@ import webbrowser import os -mycolor = '#262626' +mycolor = "#262626" class Case: - def __init__(self, master): gen_frame = Frame(master) gen_frame.grid() self.test_case_counter = None def home(self): - self.statement = Label(gui, text='Select Test Case Type', fg='white', height=1, font=('calibre', 12, 'normal')) + self.statement = Label( + gui, + text="Select Test Case Type", + fg="white", + height=1, + font=("calibre", 12, "normal"), + ) self.statement.configure(bg=mycolor) - self.button1 = Button(gui, justify=LEFT, text='T\nn \nA1 A2 A3...An\nn \nA1 A2 A3...An', width=13, - fg='white', bd=3, command=lambda: Type1(gui), bg='red', font='calibre') - self.button1.configure(background='grey20') - self.button2 = Button(gui, justify=LEFT, text='T\nn m \nA1 A2 A3...An\nn m\nA1 A2 A3...An', fg='white' - , command=lambda: Type2(gui), width=13, font='calibre', bd=3) - self.button2.configure(background='grey20') - self.button3 = Button(gui, justify=LEFT, text='T\nA1 B1\nA2 B2\n(t rows of)\n(A, B pair)', fg='white' - , command=lambda: Type3(gui), width=13, font='calibre', bd=3) - self.button3.configure(background='grey20') - self.button4 = Button(gui, justify=LEFT, text='T\nn m \nA1 A2...An\nB1 B2...Bm\n... ...', fg='white' - , command=lambda: Type4(gui), width=13, font='calibre', bd=3) - self.button4.configure(background='grey20') - self.button5 = Button(gui, justify=LEFT, text='T\nn m k\nn m k\n(t rows of)\n(n m k pair)', fg='white' - , command=lambda: Type5(gui), width=13, font='calibre', bd=3) - self.button5.configure(background='grey20') - self.button6 = Button(gui, justify=LEFT, text='n * m (matrix)\nA1 A2...Am\nA1 A2...Am\n__ __ ... __\n' - 'A1 A2...Am', fg='white', command=lambda: Type6(gui), width=13, font='calibre', bd=3) - self.button6.configure(background='grey20') - self.button7 = Button(gui, justify=LEFT, text='T\nn\nCustom string\n(ex: 0 1)\n(ex: + / -)' - , fg='white', command=lambda: Type7(gui), width=13, font='calibre', bd=3) - self.button7.configure(background='grey20') - self.button8 = Button(gui, justify=LEFT, text='T\nn m\nA1 B1\n... ...\nAm Bm' - , fg='white', command=lambda: Type8(gui), width=13, font='calibre', bd=3) - self.button8.configure(background='grey20') - self.button9 = Button(gui, justify=LEFT, text='T\nCustom string\n(without "n")\n(ex: 0 1)\n(ex: + / -)' - , fg='white', command=lambda: Type9(gui), width=13, font='calibre', bd=3) - self.button9.configure(background='grey20') - self.button10 = Button(gui, justify=LEFT, text='T\nn k m\nA1 A2...An\nn k m\nA1 A2...An' - , fg='white', command=lambda: Type10(gui), width=13, font='calibre', bd=3) - self.button10.configure(background='grey20') - self.button_new = Button(gui, text=' ANOTHER TYPE ', fg='black', width=13, font='calibre', bd=3 - , command=lambda: self.newformat(self=Case)) - self.button_exit = Button(gui, text=' EXIT ', fg='black', width=11, font='calibre', - bd=3, command=lambda: gui.destroy()) - self.copyright_label = Button(gui, text='© Dude901', fg='white', width=7, height=1, bd=3, command=lambda: - webbrowser.open_new_tab("https://github.com/Tanmay-901"), font=('calibre', 6, 'normal')) + self.button1 = Button( + gui, + justify=LEFT, + text="T\nn \nA1 A2 A3...An\nn \nA1 A2 A3...An", + width=13, + fg="white", + bd=3, + command=lambda: Type1(gui), + bg="red", + font="calibre", + ) + self.button1.configure(background="grey20") + self.button2 = Button( + gui, + justify=LEFT, + text="T\nn m \nA1 A2 A3...An\nn m\nA1 A2 A3...An", + fg="white", + command=lambda: Type2(gui), + width=13, + font="calibre", + bd=3, + ) + self.button2.configure(background="grey20") + self.button3 = Button( + gui, + justify=LEFT, + text="T\nA1 B1\nA2 B2\n(t rows of)\n(A, B pair)", + fg="white", + command=lambda: Type3(gui), + width=13, + font="calibre", + bd=3, + ) + self.button3.configure(background="grey20") + self.button4 = Button( + gui, + justify=LEFT, + text="T\nn m \nA1 A2...An\nB1 B2...Bm\n... ...", + fg="white", + command=lambda: Type4(gui), + width=13, + font="calibre", + bd=3, + ) + self.button4.configure(background="grey20") + self.button5 = Button( + gui, + justify=LEFT, + text="T\nn m k\nn m k\n(t rows of)\n(n m k pair)", + fg="white", + command=lambda: Type5(gui), + width=13, + font="calibre", + bd=3, + ) + self.button5.configure(background="grey20") + self.button6 = Button( + gui, + justify=LEFT, + text="n * m (matrix)\nA1 A2...Am\nA1 A2...Am\n__ __ ... __\n" + "A1 A2...Am", + fg="white", + command=lambda: Type6(gui), + width=13, + font="calibre", + bd=3, + ) + self.button6.configure(background="grey20") + self.button7 = Button( + gui, + justify=LEFT, + text="T\nn\nCustom string\n(ex: 0 1)\n(ex: + / -)", + fg="white", + command=lambda: Type7(gui), + width=13, + font="calibre", + bd=3, + ) + self.button7.configure(background="grey20") + self.button8 = Button( + gui, + justify=LEFT, + text="T\nn m\nA1 B1\n... ...\nAm Bm", + fg="white", + command=lambda: Type8(gui), + width=13, + font="calibre", + bd=3, + ) + self.button8.configure(background="grey20") + self.button9 = Button( + gui, + justify=LEFT, + text='T\nCustom string\n(without "n")\n(ex: 0 1)\n(ex: + / -)', + fg="white", + command=lambda: Type9(gui), + width=13, + font="calibre", + bd=3, + ) + self.button9.configure(background="grey20") + self.button10 = Button( + gui, + justify=LEFT, + text="T\nn k m\nA1 A2...An\nn k m\nA1 A2...An", + fg="white", + command=lambda: Type10(gui), + width=13, + font="calibre", + bd=3, + ) + self.button10.configure(background="grey20") + self.button_new = Button( + gui, + text=" ANOTHER TYPE ", + fg="black", + width=13, + font="calibre", + bd=3, + command=lambda: self.newformat(self=Case), + ) + self.button_exit = Button( + gui, + text=" EXIT ", + fg="black", + width=11, + font="calibre", + bd=3, + command=lambda: gui.destroy(), + ) + self.copyright_label = Button( + gui, + text="© Dude901", + fg="white", + width=7, + height=1, + bd=3, + command=lambda: webbrowser.open_new_tab("https://github.com/Tanmay-901"), + font=("calibre", 6, "normal"), + ) self.copyright_label.configure(bg=mycolor) self.retrieve_home(self) @@ -97,7 +206,7 @@ def retrieve_home(self): self.copyright_label.place(relx=0.92, rely=0.005) def cpy(self): - txt = self.output.get('1.0', END) + txt = self.output.get("1.0", END) gui.clipboard_clear() gui.clipboard_append(txt.strip()) @@ -110,30 +219,89 @@ def done(self, output): def display(self): self.y_scroll = Scrollbar(gui) self.x_scroll = Scrollbar(gui, orient=HORIZONTAL) - self.y_scroll.grid(row=0, column=11, sticky='NS', pady=(22, 0), padx=(0, 20)) - self.x_scroll.grid(row=1, sticky='EW', columnspan=10, padx=(20, 0), pady=(0, 30)) - self.output = Text(gui, height=12, bg="light cyan", width=82, yscrollcommand=self.y_scroll.set, - xscrollcommand=self.x_scroll.set, wrap='none') + self.y_scroll.grid(row=0, column=11, sticky="NS", pady=(22, 0), padx=(0, 20)) + self.x_scroll.grid( + row=1, sticky="EW", columnspan=10, padx=(20, 0), pady=(0, 30) + ) + self.output = Text( + gui, + height=12, + bg="light cyan", + width=82, + yscrollcommand=self.y_scroll.set, + xscrollcommand=self.x_scroll.set, + wrap="none", + ) # self.output = ScrolledText(gui, height=12, bg="light cyan", width=82, wrap='none', - # xscrollcommand=x_scroll.set) # only for y scroll - self.output.grid(row=0, column=0, columnspan=10, sticky='n', ipady=10, padx=(20, 0), pady=(22, 0)) + # xscrollcommand=x_scroll.set) # only for y scroll + self.output.grid( + row=0, + column=0, + columnspan=10, + sticky="n", + ipady=10, + padx=(20, 0), + pady=(22, 0), + ) self.y_scroll.config(command=self.output.yview) self.x_scroll.config(command=self.output.xview) - self.copy_button = Button(gui, text='COPY', fg='black', width=18, command=self.cpy, font='calibre', bd=3) - self.copy_button.grid(row=2, column=3, sticky='SW', ipady=10, pady=(10, 18), padx=15) - self.generate_button =Button(gui, text='RE-GENERATE', width=23, fg='black', command=lambda: self.generate(), - font='calibre', bd=3) + self.copy_button = Button( + gui, + text="COPY", + fg="black", + width=18, + command=self.cpy, + font="calibre", + bd=3, + ) + self.copy_button.grid( + row=2, column=3, sticky="SW", ipady=10, pady=(10, 18), padx=15 + ) + self.generate_button = Button( + gui, + text="RE-GENERATE", + width=23, + fg="black", + command=lambda: self.generate(), + font="calibre", + bd=3, + ) self.generate_button.grid(row=2, column=4, ipady=10, pady=(10, 18), padx=15) - self.change_values_button = Button(gui, text='CHANGE CONSTRAINT', fg='black' - , command=lambda: self.take_input(), width=20, font='calibre', bd=3) + self.change_values_button = Button( + gui, + text="CHANGE CONSTRAINT", + fg="black", + command=lambda: self.take_input(), + width=20, + font="calibre", + bd=3, + ) self.change_values_button.grid(row=2, column=5, ipady=10, pady=(10, 18), padx=5) - self.done_button = Button(gui, text='HOME', fg='black', command=lambda: self.done(self.output), width=20, - font='calibre', bd=3) - self.done_button.grid(row=3, column=3, columnspan=2, ipady=10, pady=(10, 20), padx=5) - self.button_exit_output = Button(gui, text=' EXIT ', fg='black', width=20, font='calibre', bd=3, - command=lambda: gui.destroy()) - self.button_exit_output.grid(row=3, column=4, columnspan=2, ipady=10, pady=(10, 20), padx=5) + self.done_button = Button( + gui, + text="HOME", + fg="black", + command=lambda: self.done(self.output), + width=20, + font="calibre", + bd=3, + ) + self.done_button.grid( + row=3, column=3, columnspan=2, ipady=10, pady=(10, 20), padx=5 + ) + self.button_exit_output = Button( + gui, + text=" EXIT ", + fg="black", + width=20, + font="calibre", + bd=3, + command=lambda: gui.destroy(), + ) + self.button_exit_output.grid( + row=3, column=4, columnspan=2, ipady=10, pady=(10, 20), padx=5 + ) def try_forget(self): self.output.grid_forget() @@ -150,64 +318,111 @@ def try_forget(self): pass def get_t(self, r): - self.test_case_count_label = Label(gui, text='T = ', font=('calibre', 10, 'bold'), width=17) # Type 1 - self.test_case_count = Entry(gui, textvariable=t, font=('calibre', 10, 'normal')) + self.test_case_count_label = Label( + gui, text="T = ", font=("calibre", 10, "bold"), width=17 + ) # Type 1 + self.test_case_count = Entry( + gui, textvariable=t, font=("calibre", 10, "normal") + ) self.test_case_count_label.grid(row=r, column=0, pady=20, ipady=1) # Type 1 self.test_case_count.grid(row=r, column=1) def get_n(self, r): - self.minimum_value_of_n = Entry(gui, textvariable=n_min, font=('calibre', 10, 'normal')) - self.min_max_values_of_n_label = Label(gui, text=' <= n <=', font=('calibre', 10, 'bold')) - self.maximum_value_of_n = Entry(gui, textvariable=n_max, font=('calibre', 10, 'normal')) + self.minimum_value_of_n = Entry( + gui, textvariable=n_min, font=("calibre", 10, "normal") + ) + self.min_max_values_of_n_label = Label( + gui, text=" <= n <=", font=("calibre", 10, "bold") + ) + self.maximum_value_of_n = Entry( + gui, textvariable=n_max, font=("calibre", 10, "normal") + ) self.minimum_value_of_n.grid(row=r, column=0, padx=10, pady=10) self.min_max_values_of_n_label.grid(row=r, column=1, ipadx=5, ipady=1) self.maximum_value_of_n.grid(row=r, column=2, padx=(10, 10)) def get_m(self, r): - self.minimum_value_of_m = Entry(gui, textvariable=m_min, font=('calibre', 10, 'normal')) - self.min_max_values_of_m_label = Label(gui, text='<= m <=', font=('calibre', 10, 'bold')) - self.maximum_value_of_m = Entry(gui, textvariable=m_max, font=('calibre', 10, 'normal')) + self.minimum_value_of_m = Entry( + gui, textvariable=m_min, font=("calibre", 10, "normal") + ) + self.min_max_values_of_m_label = Label( + gui, text="<= m <=", font=("calibre", 10, "bold") + ) + self.maximum_value_of_m = Entry( + gui, textvariable=m_max, font=("calibre", 10, "normal") + ) self.minimum_value_of_m.grid(row=r, column=0, padx=10, pady=10) self.min_max_values_of_m_label.grid(row=r, column=1, padx=10, ipadx=5, ipady=1) self.maximum_value_of_m.grid(row=r, column=2, padx=10) def get_k(self, r): - self.minimum_value_of_k = Entry(gui, textvariable=k_min, font=('calibre', 10, 'normal')) - self.min_max_values_of_k_label = Label(gui, text=' <= k <=', font=('calibre', 10, 'bold')) - self.maximum_value_of_k = Entry(gui, textvariable=k_max, font=('calibre', 10, 'normal')) + self.minimum_value_of_k = Entry( + gui, textvariable=k_min, font=("calibre", 10, "normal") + ) + self.min_max_values_of_k_label = Label( + gui, text=" <= k <=", font=("calibre", 10, "bold") + ) + self.maximum_value_of_k = Entry( + gui, textvariable=k_max, font=("calibre", 10, "normal") + ) self.minimum_value_of_k.grid(row=r, column=0, pady=10) self.min_max_values_of_k_label.grid(row=r, column=1) self.maximum_value_of_k.grid(row=r, column=2) def get_a(self, r): - self.minimum_value_of_ai = Entry(gui, textvariable=a_min, font=('calibre', 10, 'normal')) - self.min_max_values_of_ai_label = Label(gui, text=' <= Ai <=', font=('calibre', 10, 'bold')) - self.maximum_value_of_ai = Entry(gui, textvariable=a_max, font=('calibre', 10, 'normal')) + self.minimum_value_of_ai = Entry( + gui, textvariable=a_min, font=("calibre", 10, "normal") + ) + self.min_max_values_of_ai_label = Label( + gui, text=" <= Ai <=", font=("calibre", 10, "bold") + ) + self.maximum_value_of_ai = Entry( + gui, textvariable=a_max, font=("calibre", 10, "normal") + ) self.minimum_value_of_ai.grid(row=r, column=0, padx=10, pady=10) self.min_max_values_of_ai_label.grid(row=r, column=1, ipadx=2, ipady=1) self.maximum_value_of_ai.grid(row=r, column=2) def get_b(self, r): - self.minimum_value_of_bi = Entry(gui, textvariable=b_min, font=('calibre', 10, 'normal')) - self.min_max_values_of_bi_label = Label(gui, text=' <= Bi <= ', font=('calibre', 10, 'bold')) - self.maximum_value_of_bi = Entry(gui, textvariable=b_max, font=('calibre', 10, 'normal')) + self.minimum_value_of_bi = Entry( + gui, textvariable=b_min, font=("calibre", 10, "normal") + ) + self.min_max_values_of_bi_label = Label( + gui, text=" <= Bi <= ", font=("calibre", 10, "bold") + ) + self.maximum_value_of_bi = Entry( + gui, textvariable=b_max, font=("calibre", 10, "normal") + ) self.minimum_value_of_bi.grid(row=r, column=0, pady=10) self.min_max_values_of_bi_label.grid(row=r, column=1, padx=10) self.maximum_value_of_bi.grid(row=r, column=2, padx=10) def get_char_list(self, r): - self.char_list_label = Label(gui, text=' Characters : ', font=('calibre', 10, 'bold'), width=17) - self.char_list = Entry(gui, textvariable=char_lis, font=('calibre', 10, 'normal'), width=43) - self.char_list.insert(END, '(Space separated characters)') - self.char_list.bind("", lambda args: self.char_list.delete('0', 'end')) + self.char_list_label = Label( + gui, text=" Characters : ", font=("calibre", 10, "bold"), width=17 + ) + self.char_list = Entry( + gui, textvariable=char_lis, font=("calibre", 10, "normal"), width=43 + ) + self.char_list.insert(END, "(Space separated characters)") + self.char_list.bind("", lambda args: self.char_list.delete("0", "end")) self.char_list_label.grid(row=r, column=0, pady=10) self.char_list.grid(row=r, column=1, columnspan=2, padx=10) def show_button(self, r): - self.back_btn = Button(gui, text=' HOME ', command=lambda: self.forget_testcase_take_input_screen(1), - font='calibre', bd=3) - self.sub_btn = Button(gui, text=' GENERATE ', command=self.submit, font='calibre', bd=3) - self.exit_btn = Button(gui, text=' EXIT ', command=lambda: gui.destroy(), font='calibre', bd=3) + self.back_btn = Button( + gui, + text=" HOME ", + command=lambda: self.forget_testcase_take_input_screen(1), + font="calibre", + bd=3, + ) + self.sub_btn = Button( + gui, text=" GENERATE ", command=self.submit, font="calibre", bd=3 + ) + self.exit_btn = Button( + gui, text=" EXIT ", command=lambda: gui.destroy(), font="calibre", bd=3 + ) self.back_btn.grid(row=r, column=0, pady=(20, 20), ipady=1) self.sub_btn.grid(row=r, column=1, pady=(20, 20), ipady=1) self.exit_btn.grid(row=r, column=2, pady=(20, 20), ipady=1) @@ -223,8 +438,12 @@ def submit(self): except AttributeError: pass try: - self.n_min = min(int(self.minimum_value_of_n.get()), int(self.maximum_value_of_n.get())) - self.n_max = max(int(self.minimum_value_of_n.get()), int(self.maximum_value_of_n.get())) + self.n_min = min( + int(self.minimum_value_of_n.get()), int(self.maximum_value_of_n.get()) + ) + self.n_max = max( + int(self.minimum_value_of_n.get()), int(self.maximum_value_of_n.get()) + ) if self.n_min > self.n_max or self.n_max == 0 or self.n_max > 10000000: return except ValueError: @@ -232,8 +451,12 @@ def submit(self): except AttributeError: pass try: - self.m_min = min(int(self.minimum_value_of_m.get()), int(self.maximum_value_of_m.get())) - self.m_max = max(int(self.minimum_value_of_m.get()), int(self.maximum_value_of_m.get())) + self.m_min = min( + int(self.minimum_value_of_m.get()), int(self.maximum_value_of_m.get()) + ) + self.m_max = max( + int(self.minimum_value_of_m.get()), int(self.maximum_value_of_m.get()) + ) if self.m_min > self.m_max or self.m_max == 0 or self.m_max > 10000000: return except ValueError: @@ -241,8 +464,12 @@ def submit(self): except AttributeError: pass try: - self.k_min = min(int(self.minimum_value_of_k.get()), int(self.maximum_value_of_k.get())) - self.k_max = max(int(self.minimum_value_of_k.get()), int(self.maximum_value_of_k.get())) + self.k_min = min( + int(self.minimum_value_of_k.get()), int(self.maximum_value_of_k.get()) + ) + self.k_max = max( + int(self.minimum_value_of_k.get()), int(self.maximum_value_of_k.get()) + ) if self.k_min > self.k_max or self.k_max == 0 or self.k_max > 10000000: return except ValueError: @@ -250,8 +477,12 @@ def submit(self): except AttributeError: pass try: - self.a_min = min(int(self.minimum_value_of_ai.get()), int(self.maximum_value_of_ai.get())) - self.a_max = max(int(self.minimum_value_of_ai.get()), int(self.maximum_value_of_ai.get())) + self.a_min = min( + int(self.minimum_value_of_ai.get()), int(self.maximum_value_of_ai.get()) + ) + self.a_max = max( + int(self.minimum_value_of_ai.get()), int(self.maximum_value_of_ai.get()) + ) if self.a_min > self.a_max or self.a_max == 0 or self.a_max > 10000000: return except ValueError: @@ -259,8 +490,12 @@ def submit(self): except AttributeError: pass try: - self.b_min = min(int(self.minimum_value_of_bi.get()), int(self.maximum_value_of_bi.get())) - self.b_max = max(int(self.minimum_value_of_bi.get()), int(self.maximum_value_of_bi.get())) + self.b_min = min( + int(self.minimum_value_of_bi.get()), int(self.maximum_value_of_bi.get()) + ) + self.b_max = max( + int(self.minimum_value_of_bi.get()), int(self.maximum_value_of_bi.get()) + ) if self.b_min > self.b_max or self.b_max == 0 or self.b_max > 10000000: return except ValueError: @@ -269,7 +504,7 @@ def submit(self): pass try: self.char_lis = list(self.char_list.get().split()) - if self.char_lis[0] == '(Space': + if self.char_lis[0] == "(Space": return except IndexError: return @@ -335,7 +570,7 @@ def forget_testcase_take_input_screen(self, check=0): pass try: self.char_list_label.grid_forget() - self.char_list.delete('0', 'end') + self.char_list.delete("0", "end") self.char_list.grid_forget() except AttributeError: pass @@ -354,13 +589,13 @@ def forget_testcase_take_input_screen(self, check=0): class Type1(Case): def __init__(self, master): - super(Type1, self).__init__(master) # Type 1 + super(Type1, self).__init__(master) # Type 1 self.forget_home() self.take_input() def take_input(self): try: - self.try_forget() # Type 1 + self.try_forget() # Type 1 except AttributeError: pass self.get_t(0) @@ -368,30 +603,29 @@ def take_input(self): self.get_a(2) self.show_button(3) - def generate(self): # Type 1 + def generate(self): # Type 1 self.forget_testcase_take_input_screen() - self.output.delete('1.0', END) + self.output.delete("1.0", END) self.output.insert(END, self.t) - self.output.insert(END, '\n') + self.output.insert(END, "\n") for i in range(self.t): self.n = randint(self.n_min, self.n_max) self.output.insert(END, self.n) - self.output.insert(END, '\n') + self.output.insert(END, "\n") self.a = [0] * self.n for j in range(self.n): self.a[j] = randint(self.a_min, self.a_max) self.output.insert(END, self.a) - self.output.insert(END, '\n') - + self.output.insert(END, "\n") -class Type2(Case): # Type 2 +class Type2(Case): # Type 2 def __init__(self, master): super(Type2, self).__init__(master) self.forget_home() self.take_input() - def take_input(self): # Type 2 + def take_input(self): # Type 2 try: self.try_forget() except AttributeError: @@ -402,22 +636,22 @@ def take_input(self): # Type 2 self.get_a(3) self.show_button(4) - def generate(self): # Type 2 - self.output.delete('1.0', END) + def generate(self): # Type 2 + self.output.delete("1.0", END) self.output.insert(END, self.t) - self.output.insert(END, '\n') + self.output.insert(END, "\n") for i in range(self.t): self.n = randint(self.n_min, self.n_max) self.m = randint(self.m_min, self.m_max) self.output.insert(END, self.n) - self.output.insert(END, ' ') + self.output.insert(END, " ") self.output.insert(END, self.m) - self.output.insert(END, '\n') + self.output.insert(END, "\n") self.a = [0] * self.n for j in range(self.n): self.a[j] = randint(self.a_min, self.a_max) self.output.insert(END, self.a) - self.output.insert(END, '\n') + self.output.insert(END, "\n") class Type3(Case): @@ -426,7 +660,7 @@ def __init__(self, master): self.forget_home() self.take_input() - def take_input(self): # Type 3 + def take_input(self): # Type 3 try: self.try_forget() except AttributeError: @@ -436,28 +670,26 @@ def take_input(self): # Type 3 self.get_b(2) self.show_button(3) - def generate(self): # Type 3 - self.output.delete('1.0', END) + def generate(self): # Type 3 + self.output.delete("1.0", END) self.output.insert(END, self.t) - self.output.insert(END, '\n') + self.output.insert(END, "\n") for i in range(self.t): self.a = randint(self.a_min, self.a_max) self.b = randint(self.b_min, self.b_max) self.output.insert(END, self.a) - self.output.insert(END, ' ') + self.output.insert(END, " ") self.output.insert(END, self.b) - self.output.insert(END, '\n') - + self.output.insert(END, "\n") class Type4(Case): - def __init__(self, master): super(Type4, self).__init__(master) self.forget_home() self.take_input() - def take_input(self): # Type 4 + def take_input(self): # Type 4 try: self.try_forget() except AttributeError: @@ -469,27 +701,28 @@ def take_input(self): # Type 4 self.get_b(4) self.show_button(5) - def generate(self): # Type 4 - self.output.delete('1.0', END) + def generate(self): # Type 4 + self.output.delete("1.0", END) self.output.insert(END, self.t) - self.output.insert(END, '\n') + self.output.insert(END, "\n") for i in range(self.t): self.n = randint(self.n_min, self.n_max) self.m = randint(self.m_min, self.m_max) self.output.insert(END, self.n) - self.output.insert(END, ' ') + self.output.insert(END, " ") self.output.insert(END, self.m) - self.output.insert(END, '\n') + self.output.insert(END, "\n") self.a = [0] * self.n self.b = [0] * self.m for j in range(self.n): self.a[j] = randint(self.a_min, self.a_max) self.output.insert(END, self.a) - self.output.insert(END, '\n') + self.output.insert(END, "\n") for j in range(self.m): self.b[j] = randint(self.b_min, self.b_max) self.output.insert(END, self.b) - self.output.insert(END, '\n') + self.output.insert(END, "\n") + # ------------------------------------------------- ### # ------------------------------------------------- ### @@ -499,13 +732,12 @@ def generate(self): # Type 4 class Type5(Case): - def __init__(self, master): super(Type5, self).__init__(master) self.forget_home() self.take_input() - def take_input(self): # Type 5 + def take_input(self): # Type 5 try: self.try_forget() except AttributeError: @@ -516,35 +748,40 @@ def take_input(self): # Type 5 self.get_k(3) self.show_button(4) - def generate(self): # Type 5 - self.output.delete('1.0', END) + def generate(self): # Type 5 + self.output.delete("1.0", END) self.output.insert(END, self.t) - self.output.insert(END, '\n') + self.output.insert(END, "\n") for i in range(self.t): self.n = randint(self.n_min, self.n_max) self.m = randint(self.m_min, self.m_max) self.k = randint(self.k_min, self.k_max) self.output.insert(END, self.n) - self.output.insert(END, ' ') + self.output.insert(END, " ") self.output.insert(END, self.m) - self.output.insert(END, ' ') + self.output.insert(END, " ") self.output.insert(END, self.k) - self.output.insert(END, '\n') + self.output.insert(END, "\n") class Type6(Case): - - def __init__(self, master): # Type 6 + def __init__(self, master): # Type 6 super(Type6, self).__init__(master) self.forget_home() self.take_input() - def take_input(self): # Type 6 + def take_input(self): # Type 6 try: self.try_forget() except AttributeError: - pass # Type 6 - self.constraints = Label(gui, text='Enter Constraints', fg='white', height=1, font=('calibre', 12, 'normal')) + pass # Type 6 + self.constraints = Label( + gui, + text="Enter Constraints", + fg="white", + height=1, + font=("calibre", 12, "normal"), + ) self.constraints.configure(bg=mycolor) self.constraints.grid(row=0, column=1) self.get_n(1) @@ -552,30 +789,29 @@ def take_input(self): # Type 6 self.get_a(3) self.show_button(4) - def generate(self): # Type 6 - self.output.delete('1.0', END) + def generate(self): # Type 6 + self.output.delete("1.0", END) self.n = randint(self.n_min, self.n_max) self.m = randint(self.m_min, self.m_max) self.output.insert(END, self.n) - self.output.insert(END, ' ') + self.output.insert(END, " ") self.output.insert(END, self.m) - self.output.insert(END, '\n') + self.output.insert(END, "\n") for i in range(self.n): self.a = [0] * self.m for j in range(self.m): self.a[j] = randint(self.a_min, self.a_max) self.output.insert(END, self.a) - self.output.insert(END, '\n') + self.output.insert(END, "\n") class Type7(Case): - - def __init__(self, master): # Type 7 + def __init__(self, master): # Type 7 super(Type7, self).__init__(master) self.forget_home() self.take_input() - def take_input(self): # Type 7 + def take_input(self): # Type 7 try: self.try_forget() except AttributeError: @@ -585,28 +821,27 @@ def take_input(self): # Type 7 self.get_n(2) self.show_button(3) - def generate(self): # Type 7 - self.output.delete('1.0', END) + def generate(self): # Type 7 + self.output.delete("1.0", END) self.output.insert(END, self.t) - self.output.insert(END, '\n') + self.output.insert(END, "\n") for i in range(self.t): self.n = randint(self.n_min, self.n_max) self.output.insert(END, self.n) - self.output.insert(END, '\n') + self.output.insert(END, "\n") self.a = choices(self.char_lis, k=self.n) - self.output.insert(END, ''.join(self.a)) - self.output.insert(END, '\n') + self.output.insert(END, "".join(self.a)) + self.output.insert(END, "\n") class Type8(Case): - - def __init__(self, master): # Type 8 + def __init__(self, master): # Type 8 super(Type8, self).__init__(master) self.forget_home() self.take_input() def take_input(self): - try: # Type 8 + try: # Type 8 self.try_forget() except AttributeError: pass @@ -617,24 +852,24 @@ def take_input(self): self.get_b(4) self.show_button(5) - def generate(self): # Type 8 - self.output.delete('1.0', END) + def generate(self): # Type 8 + self.output.delete("1.0", END) self.output.insert(END, self.t) - self.output.insert(END, '\n') + self.output.insert(END, "\n") for i in range(self.t): self.n = randint(self.n_min, self.n_max) self.m = randint(self.m_min, self.m_max) self.output.insert(END, self.n) - self.output.insert(END, ' ') + self.output.insert(END, " ") self.output.insert(END, self.m) - self.output.insert(END, '\n') + self.output.insert(END, "\n") for j in range(self.m): self.a = randint(self.a_min, self.a_max) self.b = randint(self.b_min, self.b_max) self.output.insert(END, self.a) - self.output.insert(END, ' ') + self.output.insert(END, " ") self.output.insert(END, self.b) - self.output.insert(END, '\n') + self.output.insert(END, "\n") class Type9(Case): @@ -643,7 +878,7 @@ def __init__(self, master): self.forget_home() self.take_input() - def take_input(self): # Type 9 + def take_input(self): # Type 9 try: self.try_forget() except AttributeError: @@ -653,25 +888,24 @@ def take_input(self): # Type 9 self.get_n(2) self.show_button(3) - def generate(self): # Type 9 - self.output.delete('1.0', END) + def generate(self): # Type 9 + self.output.delete("1.0", END) self.output.insert(END, self.t) - self.output.insert(END, '\n') + self.output.insert(END, "\n") for i in range(self.t): self.n = randint(self.n_min, self.n_max) self.a = choices(self.char_lis, k=self.n) - self.output.insert(END, ''.join(self.a)) - self.output.insert(END, '\n') + self.output.insert(END, "".join(self.a)) + self.output.insert(END, "\n") class Type10(Case): - def __init__(self, master): super(Type10, self).__init__(master) self.forget_home() self.take_input() - def take_input(self): # Type 10 + def take_input(self): # Type 10 try: self.try_forget() except AttributeError: @@ -683,38 +917,38 @@ def take_input(self): # Type 10 self.get_a(4) self.show_button(5) - def generate(self): # Type 10 - self.output.delete('1.0', END) + def generate(self): # Type 10 + self.output.delete("1.0", END) self.output.insert(END, self.t) - self.output.insert(END, '\n') + self.output.insert(END, "\n") for i in range(self.t): self.n = randint(self.n_min, self.n_max) self.k = randint(self.k_min, self.k_max) self.m = randint(self.m_min, self.m_max) self.output.insert(END, self.n) - self.output.insert(END, ' ') + self.output.insert(END, " ") self.output.insert(END, self.k) - self.output.insert(END, ' ') # Type 10 + self.output.insert(END, " ") # Type 10 self.output.insert(END, self.m) - self.output.insert(END, '\n') + self.output.insert(END, "\n") self.a = [0] * self.n for j in range(self.n): self.a[j] = randint(self.a_min, self.a_max) self.output.insert(END, self.a) - self.output.insert(END, '\n') + self.output.insert(END, "\n") -if __name__ == '__main__': +if __name__ == "__main__": gui = Tk() - gui.title('TEST CASE GENERATOR') + gui.title("TEST CASE GENERATOR") gui.configure(bg=mycolor) - if os.environ.get('DISPLAY', '') == '': - print('no display found, using:0,0') - os.environ.__setitem__('DISPLAY', ':0.0') + if os.environ.get("DISPLAY", "") == "": + print("no display found, using:0,0") + os.environ.__setitem__("DISPLAY", ":0.0") else: - print('found display') - + print("found display") + t = IntVar() n_min = IntVar() n_max = IntVar() diff --git a/bookstore_manangement_system.py b/bookstore_manangement_system.py index 0f5244fb603..7ae31cb195b 100644 --- a/bookstore_manangement_system.py +++ b/bookstore_manangement_system.py @@ -1,407 +1,269 @@ import os -import mysql.connector as mys -mycon=mys.connect(host='localhost',user='root',passwd='Yksrocks',database='book_store_management') +import mysql.connector as mys + +mycon = mys.connect( + host="localhost", user="root", passwd="Yksrocks", database="book_store_management" +) if mycon.is_connected(): print() - print('successfully connected') - -mycur=mycon.cursor() - - - - + print("successfully connected") +mycur = mycon.cursor() - -def DBZ(): - +def DBZ(): # IF NO. OF BOOKS IS ZERO(0) THAN DELETE IT AUTOMATICALLY - - - display="select * from books" + display = "select * from books" mycur.execute(display) - data2=mycur.fetchall() - + data2 = mycur.fetchall() for y in data2: - - if y[6]<=0: - - delete="delete from books where Numbers_of_book<=0" + if y[6] <= 0: + + delete = "delete from books where Numbers_of_book<=0" mycur.execute(delete) mycon.commit() - - - - - - def separator(): print() print("\t\t========================================") print() - - - def end_separator(): print() print() +def login(): + user_name = input(" USER NAME --- ") + passw = input(" PASSWORD --- ") - - - - -def login(): - - - user_name=input(" USER NAME --- ") - passw=input(" PASSWORD --- ") - - - display='select * from login' + display = "select * from login" mycur.execute(display) - data2=mycur.fetchall() - + data2 = mycur.fetchall() for y in data2: - if y[1]==user_name and y[2]==passw: + if y[1] == user_name and y[2] == passw: pass else: - - + separator() - print(" Username or Password is Incorrect Try Again") - separator() - - user_name=input(" USER NAME --- ") - passw=input(" PASSWORD --- ") + user_name = input(" USER NAME --- ") + passw = input(" PASSWORD --- ") + if y[1] == user_name and y[2] == passw: - if y[1]==user_name and y[2]==passw: - pass else: separator() - + print(" Username or Password is Again Incorrect") exit() - - - - - - def ViewAll(): - + print("\u0332".join("BOOK NAMES~~")) print("------------------------------------") - - display='select * from books' + display = "select * from books" mycur.execute(display) - data2=mycur.fetchall() - c=0 + data2 = mycur.fetchall() + c = 0 - for y in data2: - c=c+1 - print(c,"-->",y[1]) - - - - - + c = c + 1 + print(c, "-->", y[1]) - -def CNB1(): +def CNB1(): - - if y[6]==0: + if y[6] == 0: separator() print(" NOW THIS BOOK IS NOT AVAILABLE ") - - - elif y[6]>0 and y[6]<=8: + elif y[6] > 0 and y[6] <= 8: separator() print("WARNING!!!!!!!!!!!!!!!!!!!!!!!") - print("NO. OF THIS BOOK IS LOW","\tONLY",y[6]-1,"LEFT") - + print("NO. OF THIS BOOK IS LOW", "\tONLY", y[6] - 1, "LEFT") print() print() - - - - elif y[6]>8: + + elif y[6] > 8: separator() - - print("NO. OF BOOKS LEFT IS ",y[6]-1) + print("NO. OF BOOKS LEFT IS ", y[6] - 1) print() print() +def CNB2(): - - - - -def CNB2(): - - - if y[6]<=8: + if y[6] <= 8: separator() print("WARNING!!!!!!!!!!!!!!!!!!!!!!!") - print("NO. OF THIS BOOK IS LOW","\tONLY",y[6],"LEFT") - - - - - + print("NO. OF THIS BOOK IS LOW", "\tONLY", y[6], "LEFT") else: separator() - print("NO. OF BOOKS LEFT IS ",y[6]) - - - + print("NO. OF BOOKS LEFT IS ", y[6]) - - - - - - separator() - - - - - - # LOGIN - -display12='select * from visit' +display12 = "select * from visit" mycur.execute(display12) -data2222=mycur.fetchall() +data2222 = mycur.fetchall() for m in data2222: - if m[0]==0: + if m[0] == 0: - - c=m[0] - display11='select * from login' + c = m[0] + display11 = "select * from login" mycur.execute(display11) - data222=mycur.fetchall() + data222 = mycur.fetchall() + if c == 0: - if c==0: - - if c==0: - + if c == 0: print("\t\t\t\t REGESTER ") print("\t\t\t\t----------------------------") - print() print() - - user_name=input("ENTER USER NAME -- ") - passw=input("ENTER PASSWORD limit 8-20 -- ") - lenght=len(passw) + user_name = input("ENTER USER NAME -- ") + passw = input("ENTER PASSWORD limit 8-20 -- ") + lenght = len(passw) - - if lenght>=8 and lenght<=20: + if lenght >= 8 and lenght <= 20: - c=c+1 - insert55=(c,user_name,passw) - insert22="insert into login values(%s,%s,%s)" - mycur.execute(insert22,insert55) + c = c + 1 + insert55 = (c, user_name, passw) + insert22 = "insert into login values(%s,%s,%s)" + mycur.execute(insert22, insert55) mycon.commit() - separator() - login() - - - else: - - if lenght<8: + if lenght < 8: - separator() - print(" Password Is less than 8 Characters Enter Again") - separator() - - - user_name2=input("ENTER USER NAME -- ") - passw2=input("ENTER PASSWORD AGAIN (limit 8-20) -- ") - lenght1=len(passw2) - - - if lenght1>=8 and lenght1<=20: - - - c=c+1 - insert555=(c,user_name2,passw2) - insert222="insert into login values(%s,%s,%s)" - mycur.execute(insert222,insert555) - mycon.commit() - - separator() + user_name2 = input("ENTER USER NAME -- ") + passw2 = input("ENTER PASSWORD AGAIN (limit 8-20) -- ") + lenght1 = len(passw2) + if lenght1 >= 8 and lenght1 <= 20: + c = c + 1 + insert555 = (c, user_name2, passw2) + insert222 = "insert into login values(%s,%s,%s)" + mycur.execute(insert222, insert555) + mycon.commit() - + separator() - login() - - - - elif lenght>20: - + elif lenght > 20: separator() - - print(" Password Is Greater than 20 Characters Enter Again") - + print( + " Password Is Greater than 20 Characters Enter Again" + ) separator() - - user_name=input("ENTER USER NAME -- ") - passw=input("ENTER PASSWORD AGAIN (limit 8-20) -- ") - lenght=len(passw) + user_name = input("ENTER USER NAME -- ") + passw = input("ENTER PASSWORD AGAIN (limit 8-20) -- ") + lenght = len(passw) - - if lenght>=8 and lenght>=20: + if lenght >= 8 and lenght >= 20: - - c=c+1 - insert55=(c,user_name,passw) - insert22="insert into login values(%s,%s,%s)" - mycur.execute(insert22,insert55) + c = c + 1 + insert55 = (c, user_name, passw) + insert22 = "insert into login values(%s,%s,%s)" + mycur.execute(insert22, insert55) mycon.commit() - separator() - login() - - - - update33="update visit set visits=%s"%(c) + update33 = "update visit set visits=%s" % (c) mycur.execute(update33) mycon.commit() - - - elif m[0]==1: + elif m[0] == 1: - if m[0]==1: + if m[0] == 1: login() - - - - separator() - - - - DBZ() - - - - - # REPETITION -a=True - - -while a==True: - - +a = True +while a == True: # PROGRAM STARTED - - - - print(" *TO VIEW ALL ENTER 1") print(" *TO SEARCH and BUY BOOK ENTER 2") print(" *TO ADD BOOK ENTER 3") @@ -409,44 +271,25 @@ def CNB2(): print(" *TO DELETE BOOK ENTER 5") print(" *TO CLOSE ENTER 6") - print() - - choice=int(input("ENTER YOUR CHOICE -- ")) - + choice = int(input("ENTER YOUR CHOICE -- ")) separator() + # VIEW - - - - - - - - - #VIEW - - - - if choice==1: + if choice == 1: print() - - ViewAll() - + ViewAll() separator() + rep = input("Do You Want To Restart ?? yes / no -- ").lower() - - rep=input("Do You Want To Restart ?? yes / no -- ").lower() - - - if rep=="yes": + if rep == "yes": end_separator() @@ -461,338 +304,248 @@ def CNB2(): end_separator() DBZ() - - os._exit(0) - - + os._exit(0) end_separator() - - - - - - - - + # SEARCH / BUY + if choice == 2: - - #SEARCH / BUY - - - - if choice==2: - - - book_name=input("ENTER BOOK NAME ---- ") - + book_name = input("ENTER BOOK NAME ---- ") separator() - - display="select * from books where Name='%s'"%(book_name) + display = "select * from books where Name='%s'" % (book_name) mycur.execute(display) - data2=mycur.fetchone() + data2 = mycur.fetchone() - - if data2!=None: + if data2 != None: - print("BOOK IS AVAILABLE") - - - - - - - - - - #BUY OR NOT - - + # BUY OR NOT separator() - print("\t*WANT TO BUY PRESS 1") print("\t*IF NOT PRESS 2") print() - - choice2=int(input("ENTER YOUR CHOICE -- ")) - - - if choice2==1: - - - - - - - - - - - #BUY 1 OR MORE + choice2 = int(input("ENTER YOUR CHOICE -- ")) + if choice2 == 1: + # BUY 1 OR MORE separator() - print("\t*IF YOU WANT ONE BOOK PRESS 1") print("\t*IF YOU WANT MORE THAN ONE BOOK PRESS 2") print() - - choice3=int(input("ENTER YOUR CHOICE -- ")) - - - if choice3==1: + choice3 = int(input("ENTER YOUR CHOICE -- ")) + if choice3 == 1: - display='select * from books' + display = "select * from books" mycur.execute(display) - data2=mycur.fetchall() + data2 = mycur.fetchall() - for y in data2: - - if y[1]==book_name: - - if y[6]>0: + if y[1] == book_name: - separator() - - - u="update books set Numbers_of_book=Numbers_of_book - 1 where name='%s';"%(book_name) - mycur.execute(u) - mycon.commit() + if y[6] > 0: + separator() - print("BOOK WAS BOUGHT") - + u = ( + "update books set Numbers_of_book=Numbers_of_book - 1 where name='%s';" + % (book_name) + ) + mycur.execute(u) + mycon.commit() - separator() + print("BOOK WAS BOUGHT") + separator() - print("THANKS FOR COMING") + print("THANKS FOR COMING") + CNB1() - CNB1() + separator() + rep = input( + "Do You Want To Restart ?? yes / no -- " + ).lower() + if rep == "yes": + end_separator() separator() + DBZ() + continue - rep=input("Do You Want To Restart ?? yes / no -- ").lower() - - - if rep=="yes": - - end_separator() - - separator() - - DBZ() - - continue - - else: - - end_separator() - - DBZ() - - os._exit(0) - + else: + end_separator() + DBZ() - - if choice3==2: + os._exit(0) + if choice3 == 2: separator() - - wb=int(input("ENTER NO. OF BOOKS -- ")) - + wb = int(input("ENTER NO. OF BOOKS -- ")) separator() - - display='select * from books' + display = "select * from books" mycur.execute(display) - data2=mycur.fetchall() + data2 = mycur.fetchall() - for y in data2: - if y[1]==book_name: - - if wb>y[6]: - - if y[6]>0: - - - print("YOU CAN'T BUT THAT MUCH BOOKS") - - - separator() - + if y[1] == book_name: - print("BUT YOU CAN BUY",y[6],"BOOKS MAX") + if wb > y[6]: + if y[6] > 0: - separator() + print("YOU CAN'T BUT THAT MUCH BOOKS") - - choice44=input("DO YOU WANT TO BUY BOOK ? Y/N -- ") - - - separator() - - - k=y[6] - - - if choice44=="y" or choice44=="Y": - - - u2="update books set numbers_of_book=numbers_of_book -%s where name='%s'"%(k,book_name) - mycur.execute(u2) - mycon.commit() - - - print("BOOK WAS BOUGHT") - - - separator() - - - print("THANKS FOR COMING") - - - separator() - - - display='select * from books' - mycur.execute(display) - data2=mycur.fetchall() - - - for y in data2: - - if y[1]==book_name: - - if y[6]<=8: - - - print("WARNING!!!!!!!!!!!!!!!!!!!!!!!") - print("NO. OF THIS BOOK IS LOW","\tONLY",y[6],"LEFT") + separator() + print("BUT YOU CAN BUY", y[6], "BOOKS MAX") - end_separator() + separator() - - break + choice44 = input( + "DO YOU WANT TO BUY BOOK ? Y/N -- " + ) + separator() + k = y[6] - separator() + if choice44 == "y" or choice44 == "Y": + u2 = ( + "update books set numbers_of_book=numbers_of_book -%s where name='%s'" + % (k, book_name) + ) + mycur.execute(u2) + mycon.commit() - rep=input("Do You Want To Restart ?? yes / no -- ").lower() + print("BOOK WAS BOUGHT") + separator() - if rep=="yes": + print("THANKS FOR COMING") - end_separator() + separator() - separator() + display = "select * from books" + mycur.execute(display) + data2 = mycur.fetchall() - DBZ() + for y in data2: - continue + if y[1] == book_name: - else: + if y[6] <= 8: - end_separator() + print( + "WARNING!!!!!!!!!!!!!!!!!!!!!!!" + ) + print( + "NO. OF THIS BOOK IS LOW", + "\tONLY", + y[6], + "LEFT", + ) - DBZ() - - os._exit(0) + end_separator() + break + separator() - elif choice44=="n" or choice44=="N": + rep = input( + "Do You Want To Restart ?? yes / no -- " + ).lower() - - print("SORRY FOR INCONVENIENCE WE WILL TRY TO FULLFILL YOUR REQUIREMENT AS SOON AS POSSIBLE") + if rep == "yes": + end_separator() - end_separator() + separator() - + DBZ() + continue + else: + end_separator() - separator() + DBZ() - + os._exit(0) - rep=input("Do You Want To Restart ?? yes / no -- ").lower() + elif choice44 == "n" or choice44 == "N": + print( + "SORRY FOR INCONVENIENCE WE WILL TRY TO FULLFILL YOUR REQUIREMENT AS SOON AS POSSIBLE" + ) - if rep=="yes": + end_separator() - separator() + separator() - DBZ() + rep = input( + "Do You Want To Restart ?? yes / no -- " + ).lower() - continue + if rep == "yes": - else: + separator() - end_separator() + DBZ() - DBZ() + continue - os._exit(0) + else: + end_separator() + DBZ() - - elif y[6]==0: + os._exit(0) - - print("SORRY NO BOOK LEFT WE WILL TRY TO FULLFILL YOUR REQUIREMENT AS SOON AS POSSIBLE") + elif y[6] == 0: + print( + "SORRY NO BOOK LEFT WE WILL TRY TO FULLFILL YOUR REQUIREMENT AS SOON AS POSSIBLE" + ) end_separator() - - - separator() - - - rep=input("Do You Want To Restart ?? yes / no -- ").lower() - + rep = input( + "Do You Want To Restart ?? yes / no -- " + ).lower() - if rep=="yes": + if rep == "yes": separator() @@ -801,52 +554,45 @@ def CNB2(): continue else: - + end_separator() DBZ() os._exit(0) - - else: - - u2="update books set numbers_of_book=numbers_of_book -%s where name='%s'"%(wb,book_name) + u2 = ( + "update books set numbers_of_book=numbers_of_book -%s where name='%s'" + % (wb, book_name) + ) mycur.execute(u2) mycon.commit() - print("BOOK WAS BOUGHT") - separator() - print("THANKS FOR COMING") - - display='select * from books' + display = "select * from books" mycur.execute(display) - data2=mycur.fetchall() + data2 = mycur.fetchall() - for y in data2: - - if y[1]==book_name: - - CNB2() + if y[1] == book_name: - separator() - - + CNB2() - rep=input("Do You Want To Restart ?? yes / no -- ").lower() + separator() + rep = input( + "Do You Want To Restart ?? yes / no -- " + ).lower() - if rep=="yes": + if rep == "yes": separator() @@ -861,33 +607,20 @@ def CNB2(): DBZ() os._exit(0) - - else: - separator() - print("NO BOOK IS BOUGHT") - end_separator() - - - - - separator() - + rep = input("Do You Want To Restart ?? yes / no -- ").lower() - rep=input("Do You Want To Restart ?? yes / no -- ").lower() - - - if rep=="yes": + if rep == "yes": separator() @@ -903,32 +636,19 @@ def CNB2(): os._exit(0) - - - else: - separator() - print("SORRY NO BOOK WITH THIS NAME EXIST / NAME IS INCORRECT") - end_separator() - - - - separator() - - - rep=input("Do You Want To Restart ?? yes / no -- ").lower() - + rep = input("Do You Want To Restart ?? yes / no -- ").lower() - if rep=="yes": + if rep == "yes": separator() @@ -944,79 +664,50 @@ def CNB2(): os._exit(0) - - - - - - - - - # ADDING BOOK + if choice == 3: - - if choice==3: - - - q10=int(input("ENTER NO. OF BOOKS TO ADD -- ")) - + q10 = int(input("ENTER NO. OF BOOKS TO ADD -- ")) separator() - for k in range(q10): - - SNo10=int(input("ENTER SNo OF BOOK -- ")) - name10=input("ENTER NAME OF BOOK --- ") - author10=input("ENTER NAME OF AUTHOR -- ") - year10=int(input("ENTER YEAR OF PUBLISHING -- ")) - ISBN10=input("ENTER ISBN OF BOOK -- ") - price10=int(input("ENTER PRICE OF BOOK -- ")) - nob10=int(input("ENTER NO. OF BOOKS -- ")) + SNo10 = int(input("ENTER SNo OF BOOK -- ")) + name10 = input("ENTER NAME OF BOOK --- ") + author10 = input("ENTER NAME OF AUTHOR -- ") + year10 = int(input("ENTER YEAR OF PUBLISHING -- ")) + ISBN10 = input("ENTER ISBN OF BOOK -- ") + price10 = int(input("ENTER PRICE OF BOOK -- ")) + nob10 = int(input("ENTER NO. OF BOOKS -- ")) - - - display10="select * from books where ISBN='%s'"%(ISBN10) + display10 = "select * from books where ISBN='%s'" % (ISBN10) mycur.execute(display10) - data20=mycur.fetchone() + data20 = mycur.fetchone() - + if data20 != None: - if data20!=None: - print("This ISBN Already Exists") os._exit(0) else: - - insert=(SNo10,name10,author10,year10,ISBN10,price10,nob10) - insert20="insert into books values(%s,%s,%s,%s,%s,%s,%s)" - mycur.execute(insert20,insert) + insert = (SNo10, name10, author10, year10, ISBN10, price10, nob10) + insert20 = "insert into books values(%s,%s,%s,%s,%s,%s,%s)" + mycur.execute(insert20, insert) mycon.commit() - separator() - print("BOOK IS ADDED") - separator() + rep = input("Do You Want To Restart ?? yes / no -- ").lower() - - - - - rep=input("Do You Want To Restart ?? yes / no -- ").lower() - - - if rep=="yes": + if rep == "yes": separator() @@ -1024,7 +715,6 @@ def CNB2(): continue - else: end_separator() @@ -1033,63 +723,41 @@ def CNB2(): os._exit(0) - - - - - - - - - # UPDATING BOOK + if choice == 4: + choice4 = input("ENTER ISBN OF BOOK -- ") - if choice==4: - - - choice4=input("ENTER ISBN OF BOOK -- ") - - separator() - - display="select * from books where ISBN='%s'"%(choice4) + display = "select * from books where ISBN='%s'" % (choice4) mycur.execute(display) - data2=mycur.fetchone() - - - if data2!=None: - - - SNo1=int(input("ENTER NEW SNo OF BOOK -- ")) - name1=input("ENTER NEW NAME OF BOOK --- ") - author1=input("ENTER NEW NAME OF AUTHOR -- ") - year1=int(input("ENTER NEW YEAR OF PUBLISHING -- ")) - ISBN1=input("ENTER NEW ISBN OF BOOK -- ") - price1=int(input("ENTER NEW PRICE OF BOOK -- ")) - nob=int(input("ENTER NEW NO. OF BOOKS -- ")) - insert=(SNo1,name1,author1,year1,ISBN1,price1,nob,choice4) - update="update books set SNo=%s,Name=%s,Author=%s,Year=%s,ISBN=%s,Price=%s,numbers_of_book=%s where ISBN=%s" - mycur.execute(update,insert) + data2 = mycur.fetchone() + + if data2 != None: + + SNo1 = int(input("ENTER NEW SNo OF BOOK -- ")) + name1 = input("ENTER NEW NAME OF BOOK --- ") + author1 = input("ENTER NEW NAME OF AUTHOR -- ") + year1 = int(input("ENTER NEW YEAR OF PUBLISHING -- ")) + ISBN1 = input("ENTER NEW ISBN OF BOOK -- ") + price1 = int(input("ENTER NEW PRICE OF BOOK -- ")) + nob = int(input("ENTER NEW NO. OF BOOKS -- ")) + insert = (SNo1, name1, author1, year1, ISBN1, price1, nob, choice4) + update = "update books set SNo=%s,Name=%s,Author=%s,Year=%s,ISBN=%s,Price=%s,numbers_of_book=%s where ISBN=%s" + mycur.execute(update, insert) mycon.commit() - separator() - print("BOOK IS UPDATED") - separator() - + rep = input("Do You Want To Restart ?? yes / no -- ").lower() - rep=input("Do You Want To Restart ?? yes / no -- ").lower() - - - if rep=="yes": + if rep == "yes": separator() @@ -1097,7 +765,6 @@ def CNB2(): continue - else: end_separator() @@ -1106,25 +773,18 @@ def CNB2(): os._exit(0) - else: - - print("SORRY NO BOOK WITH THIS ISBN IS EXIST / INCORRECT ISBN") + print("SORRY NO BOOK WITH THIS ISBN IS EXIST / INCORRECT ISBN") print() print() - - separator() - + rep = input("Do You Want To Restart ?? yes / no -- ").lower() - rep=input("Do You Want To Restart ?? yes / no -- ").lower() - - - if rep=="yes": + if rep == "yes": separator() @@ -1132,7 +792,6 @@ def CNB2(): continue - else: end_separator() @@ -1141,68 +800,42 @@ def CNB2(): os._exit(0) - - - - - - - - # DELETING A BOOK + if choice == 5: - - if choice==5: - - - ISBN1=input("ENTER ISBN OF THAT BOOK THAT YOU WANT TO DELETE -- ") - display="select * from books where ISBN='%s'"%(ISBN1) + ISBN1 = input("ENTER ISBN OF THAT BOOK THAT YOU WANT TO DELETE -- ") + display = "select * from books where ISBN='%s'" % (ISBN1) mycur.execute(display) - data2=mycur.fetchone() - - - if data2!=None: + data2 = mycur.fetchone() + if data2 != None: separator() - - choice5=input("ARE YOU SURE TO DELETE THIS BOOK ENTER Y/N -- ") - - - if choice5=='Y' or choice5=='y': + choice5 = input("ARE YOU SURE TO DELETE THIS BOOK ENTER Y/N -- ") + if choice5 == "Y" or choice5 == "y": separator() - - ISBN2=input("PLEASE ENTER ISBN AGAIN -- ") - delete="delete from books where ISBN='%s'"%(ISBN2) + ISBN2 = input("PLEASE ENTER ISBN AGAIN -- ") + delete = "delete from books where ISBN='%s'" % (ISBN2) mycur.execute(delete) mycon.commit() - separator() - print("BOOK IS DELETED") - print() print() - - - separator() - - - rep=input("Do You Want To Restart ?? yes / no -- ").lower() + rep = input("Do You Want To Restart ?? yes / no -- ").lower() - - if rep=="yes": + if rep == "yes": separator() @@ -1210,7 +843,6 @@ def CNB2(): continue - else: end_separator() @@ -1218,30 +850,21 @@ def CNB2(): DBZ() os._exit(0) - - else: - separator() - print("NO BOOK IS DELETED") - print() print() - separator() - - - rep=input("Do You Want To Restart ?? yes / no -- ").lower() - + rep = input("Do You Want To Restart ?? yes / no -- ").lower() - if rep=="yes": + if rep == "yes": separator() @@ -1249,7 +872,6 @@ def CNB2(): continue - else: end_separator() @@ -1258,30 +880,20 @@ def CNB2(): os._exit(0) - - else: - separator() - print("SORRY NO BOOK WITH THIS ISBN AVAILABLE / ISBN IS INCORRECT") - print() print() - - separator() - + rep = input("Do You Want To Restart ?? yes / no -- ").lower() - rep=input("Do You Want To Restart ?? yes / no -- ").lower() - - - if rep=="yes": + if rep == "yes": separator() @@ -1289,7 +901,6 @@ def CNB2(): continue - else: end_separator() @@ -1298,45 +909,26 @@ def CNB2(): os._exit(0) - - - - - - - - - # CLOSE - if choice==6: + if choice == 6: exit() os._exit(0) - - - - - - - - # IF NO. OF BOOKS IS ZERO( 0 ) THAN DELETE IT AUTOMATICALLY - -display="select * from books" +display = "select * from books" mycur.execute(display) -data2=mycur.fetchall() +data2 = mycur.fetchall() for y in data2: - - if y[6]<=0: - - delete="delete from books where Numbers_of_book<=0" + if y[6] <= 0: + + delete = "delete from books where Numbers_of_book<=0" mycur.execute(delete) mycon.commit() diff --git a/calculator-gui.py b/calculator-gui.py index bb77ca1b2fc..e0a0ea5a28d 100755 --- a/calculator-gui.py +++ b/calculator-gui.py @@ -2,6 +2,7 @@ import tkinter as tk from tkinter import ttk from tkinter import messagebox + # =================================================== # ==================== Classes ====================== @@ -25,14 +26,20 @@ def __init__(self, parent): self.cal_buttons() # <---------- Buttons On Calculator def output_box(self): - show = ttk.Entry(self.cal_frame, textvariable=self.out_var, width=25, font=('calibri', 16), state='readonly') + show = ttk.Entry( + self.cal_frame, + textvariable=self.out_var, + width=25, + font=("calibri", 16), + state="readonly", + ) show.grid(row=0, column=0, sticky=tk.W, ipady=6, ipadx=1, columnspan=4) show.focus() # ========== * Button Events * ========== < --- Sequence 789456123 def press_7(self): current = self.out_var.get() - if current == '': + if current == "": self.out_var.set(7) else: current += str(7) @@ -40,7 +47,7 @@ def press_7(self): def press_8(self): current = self.out_var.get() - if current == '': + if current == "": self.out_var.set(8) else: current += str(8) @@ -48,7 +55,7 @@ def press_8(self): def press_9(self): current = self.out_var.get() - if current == '': + if current == "": self.out_var.set(9) else: current += str(9) @@ -56,7 +63,7 @@ def press_9(self): def press_4(self): current = self.out_var.get() - if current == '': + if current == "": self.out_var.set(4) else: current += str(4) @@ -64,7 +71,7 @@ def press_4(self): def press_5(self): current = self.out_var.get() - if current == '': + if current == "": self.out_var.set(5) else: current += str(5) @@ -72,7 +79,7 @@ def press_5(self): def press_6(self): current = self.out_var.get() - if current == '': + if current == "": self.out_var.set(6) else: current += str(6) @@ -80,7 +87,7 @@ def press_6(self): def press_1(self): current = self.out_var.get() - if current == '': + if current == "": self.out_var.set(1) else: current += str(1) @@ -88,7 +95,7 @@ def press_1(self): def press_2(self): current = self.out_var.get() - if current == '': + if current == "": self.out_var.set(2) else: current += str(2) @@ -96,7 +103,7 @@ def press_2(self): def press_3(self): current = self.out_var.get() - if current == '': + if current == "": self.out_var.set(3) else: current += str(3) @@ -104,7 +111,7 @@ def press_3(self): def press_0(self): current = self.out_var.get() - if current == '': + if current == "": self.out_var.set(0) else: current += str(0) @@ -112,115 +119,263 @@ def press_0(self): # ========== Operators Button Handling Function ========== def press_clear(self): - self.out_var.set('') + self.out_var.set("") def press_reset(self): - self.out_var.set('') + self.out_var.set("") def press_plus(self): self.value1 = self.out_var.get() - if self.value1 == '': - messagebox.showwarning('Operator Before Number', 'Please Enter Number Before Operator') + if self.value1 == "": + messagebox.showwarning( + "Operator Before Number", "Please Enter Number Before Operator" + ) else: - self.out_var.set('') - self.opr = '+' + self.out_var.set("") + self.opr = "+" def press_min(self): self.value1 = self.out_var.get() - if self.value1 == '': - messagebox.showwarning('Operator Before Number', 'Please Enter Number Before Operator') + if self.value1 == "": + messagebox.showwarning( + "Operator Before Number", "Please Enter Number Before Operator" + ) else: - self.out_var.set('') - self.opr = '-' + self.out_var.set("") + self.opr = "-" def press_mul(self): self.value1 = self.out_var.get() - if self.value1 == '': - messagebox.showwarning('Operator Before Number', 'Please Enter Number Before Operator') + if self.value1 == "": + messagebox.showwarning( + "Operator Before Number", "Please Enter Number Before Operator" + ) else: - self.out_var.set('') - self.opr = '*' + self.out_var.set("") + self.opr = "*" def press_div(self): self.value1 = self.out_var.get() - if self.value1 == '': - messagebox.showwarning('Operator Before Number', 'Please Enter Number Before Operator') + if self.value1 == "": + messagebox.showwarning( + "Operator Before Number", "Please Enter Number Before Operator" + ) else: - self.out_var.set('') - self.opr = '/' + self.out_var.set("") + self.opr = "/" # ============================================== # ========== ***** Equal Button Function ***** ========== def press_equal(self): self.value2 = self.out_var.get() - if self.value2 == '': - messagebox.showerror('Second Number', 'Please Enter Second Number To Perform Calculation') + if self.value2 == "": + messagebox.showerror( + "Second Number", "Please Enter Second Number To Perform Calculation" + ) else: try: - if self.opr == '+': + if self.opr == "+": self.value1 = int(self.value1) self.value2 = int(self.value2) result = self.value1 + self.value2 self.out_var.set(result) - if self.opr == '-': + if self.opr == "-": self.value1 = int(self.value1) self.value2 = int(self.value2) result = self.value1 - self.value2 self.out_var.set(result) - if self.opr == '*': + if self.opr == "*": self.value1 = int(self.value1) self.value2 = int(self.value2) result = self.value1 * self.value2 self.out_var.set(result) - if self.opr == '/': + if self.opr == "/": self.value1 = int(self.value1) self.value2 = int(self.value2) result = self.value1 / self.value2 self.out_var.set(result) except ValueError: - messagebox.showinfo('Restart', 'Please Close And Restart Application...Sorry') + messagebox.showinfo( + "Restart", "Please Close And Restart Application...Sorry" + ) def cal_buttons(self): # ===== Row 1 ===== - btn_c = tk.Button(self.cal_frame, text='Clear', width=6, height=2, bd=2, bg='#58a8e0', command=self.press_clear) + btn_c = tk.Button( + self.cal_frame, + text="Clear", + width=6, + height=2, + bd=2, + bg="#58a8e0", + command=self.press_clear, + ) btn_c.grid(row=1, column=0, sticky=tk.W, pady=5) - btn_div = tk.Button(self.cal_frame, text='/', width=6, height=2, bd=2, bg='#58a8e0', command=self.press_div) + btn_div = tk.Button( + self.cal_frame, + text="/", + width=6, + height=2, + bd=2, + bg="#58a8e0", + command=self.press_div, + ) btn_div.grid(row=1, column=1, sticky=tk.W) - btn_mul = tk.Button(self.cal_frame, text='*', width=6, height=2, bd=2, bg='#58a8e0', command=self.press_mul) + btn_mul = tk.Button( + self.cal_frame, + text="*", + width=6, + height=2, + bd=2, + bg="#58a8e0", + command=self.press_mul, + ) btn_mul.grid(row=1, column=2, sticky=tk.E) - btn_min = tk.Button(self.cal_frame, text='-', width=6, height=2, bd=2, bg='#58a8e0', command=self.press_min) + btn_min = tk.Button( + self.cal_frame, + text="-", + width=6, + height=2, + bd=2, + bg="#58a8e0", + command=self.press_min, + ) btn_min.grid(row=1, column=3, sticky=tk.E) # ===== Row 2 ===== - btn_7 = tk.Button(self.cal_frame, text='7', width=6, height=2, bd=2, bg='#90a9b8', command=self.press_7) + btn_7 = tk.Button( + self.cal_frame, + text="7", + width=6, + height=2, + bd=2, + bg="#90a9b8", + command=self.press_7, + ) btn_7.grid(row=2, column=0, sticky=tk.W, pady=2) - btn_8 = tk.Button(self.cal_frame, text='8', width=6, height=2, bd=2, bg='#90a9b8', command=self.press_8) + btn_8 = tk.Button( + self.cal_frame, + text="8", + width=6, + height=2, + bd=2, + bg="#90a9b8", + command=self.press_8, + ) btn_8.grid(row=2, column=1, sticky=tk.W) - btn_9 = tk.Button(self.cal_frame, text='9', width=6, height=2, bd=2, bg='#90a9b8', command=self.press_9) + btn_9 = tk.Button( + self.cal_frame, + text="9", + width=6, + height=2, + bd=2, + bg="#90a9b8", + command=self.press_9, + ) btn_9.grid(row=2, column=2, sticky=tk.E) - btn_plus = tk.Button(self.cal_frame, text='+', width=6, height=5, bd=2, bg='#58a8e0', command=self.press_plus) + btn_plus = tk.Button( + self.cal_frame, + text="+", + width=6, + height=5, + bd=2, + bg="#58a8e0", + command=self.press_plus, + ) btn_plus.grid(row=2, column=3, sticky=tk.E, rowspan=2) # ===== Row 3 ===== - btn_4 = tk.Button(self.cal_frame, text='4', width=6, height=2, bd=2, bg='#90a9b8', command=self.press_4) + btn_4 = tk.Button( + self.cal_frame, + text="4", + width=6, + height=2, + bd=2, + bg="#90a9b8", + command=self.press_4, + ) btn_4.grid(row=3, column=0, sticky=tk.W, pady=2) - btn_5 = tk.Button(self.cal_frame, text='5', width=6, height=2, bd=2, bg='#90a9b8', command=self.press_5) + btn_5 = tk.Button( + self.cal_frame, + text="5", + width=6, + height=2, + bd=2, + bg="#90a9b8", + command=self.press_5, + ) btn_5.grid(row=3, column=1, sticky=tk.W) - btn_6 = tk.Button(self.cal_frame, text='6', width=6, height=2, bd=2, bg='#90a9b8', command=self.press_6) + btn_6 = tk.Button( + self.cal_frame, + text="6", + width=6, + height=2, + bd=2, + bg="#90a9b8", + command=self.press_6, + ) btn_6.grid(row=3, column=2, sticky=tk.E) # ===== Row 4 ===== - btn_1 = tk.Button(self.cal_frame, text='1', width=6, height=2, bd=2, bg='#90a9b8', command=self.press_1) + btn_1 = tk.Button( + self.cal_frame, + text="1", + width=6, + height=2, + bd=2, + bg="#90a9b8", + command=self.press_1, + ) btn_1.grid(row=4, column=0, sticky=tk.W, pady=2) - btn_2 = tk.Button(self.cal_frame, text='2', width=6, height=2, bd=2, bg='#90a9b8', command=self.press_2) + btn_2 = tk.Button( + self.cal_frame, + text="2", + width=6, + height=2, + bd=2, + bg="#90a9b8", + command=self.press_2, + ) btn_2.grid(row=4, column=1, sticky=tk.W) - btn_3 = tk.Button(self.cal_frame, text='3', width=6, height=2, bd=2, bg='#90a9b8', command=self.press_3) + btn_3 = tk.Button( + self.cal_frame, + text="3", + width=6, + height=2, + bd=2, + bg="#90a9b8", + command=self.press_3, + ) btn_3.grid(row=4, column=2, sticky=tk.E) - btn_equal = tk.Button(self.cal_frame, text='=', width=6, height=5, bd=2, bg='orange', command=self.press_equal) + btn_equal = tk.Button( + self.cal_frame, + text="=", + width=6, + height=5, + bd=2, + bg="orange", + command=self.press_equal, + ) btn_equal.grid(row=4, column=3, sticky=tk.E, rowspan=2) # ===== Row 5 ===== - btn_0 = tk.Button(self.cal_frame, text='0', width=14, height=2, bd=2, bg='#90a9b8', command=self.press_0) + btn_0 = tk.Button( + self.cal_frame, + text="0", + width=14, + height=2, + bd=2, + bg="#90a9b8", + command=self.press_0, + ) btn_0.grid(row=5, column=0, sticky=tk.W, pady=2, columnspan=2) - btn_reset = tk.Button(self.cal_frame, text='Reset', width=6, height=2, bd=2, bg='#90a9b8', command=self.press_reset) + btn_reset = tk.Button( + self.cal_frame, + text="Reset", + width=6, + height=2, + bd=2, + bg="#90a9b8", + command=self.press_reset, + ) btn_reset.grid(row=5, column=2, sticky=tk.E) @@ -228,7 +383,7 @@ class Main(tk.Tk): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # ----- Title ----- - self.title('Calculator') + self.title("Calculator") # ----------------- # ----- Geometry Settings ----- self.geometry_settings() @@ -239,9 +394,11 @@ def geometry_settings(self): _com_height = self.winfo_screenheight() _my_width = 360 _my_height = 350 - _x = int(_com_width/2 - _my_width/2) - _y = int(_com_height/2 - _my_height/2) - geo_string = str(_my_width)+"x"+str(_my_height)+"+"+str(_x)+"+"+str(_y) + _x = int(_com_width / 2 - _my_width / 2) + _y = int(_com_height / 2 - _my_height / 2) + geo_string = ( + str(_my_width) + "x" + str(_my_height) + "+" + str(_x) + "+" + str(_y) + ) # ----- Setting Now ----- self.geometry(geo_string) self.resizable(width=False, height=False) diff --git a/changemac.py b/changemac.py index 1cf7a875edc..b5e86ceae09 100644 --- a/changemac.py +++ b/changemac.py @@ -1,4 +1,4 @@ -# Author- RIZWAN AHMAD +# Author- RIZWAN AHMAD # Simple python Script to change mac address of linux generate random or enter mac address @@ -9,24 +9,24 @@ # function for returning terminal command def cret(command): - process = Popen( - args=command, - stdout=PIPE, - shell=True - ) + process = Popen(args=command, stdout=PIPE, shell=True) return process.communicate()[0] # function for genrate mac address random def randmac(): - return [0x00, 0x16, 0x3e, - random.randint(0x00, 0x7f), - random.randint(0x00, 0xff), - random.randint(0x00, 0xff)] + return [ + 0x00, + 0x16, + 0x3E, + random.randint(0x00, 0x7F), + random.randint(0x00, 0xFF), + random.randint(0x00, 0xFF), + ] def retrandmac(mac): - return ':'.join(map(lambda x: "%02x" % x, mac)) + return ":".join(map(lambda x: "%02x" % x, mac)) print(" +-+-+-+ +-+-+-+-+-+-+-+") @@ -36,13 +36,16 @@ def retrandmac(mac): infname = cret('ifconfig -a | egrep "^[wl-wl]+" | sed "s/: .*//" | grep -v "lo"') # INTERFACE NAME 6 character so return 6 last character infname = infname[:6] -infname = infname.decode('utf-8') +infname = infname.decode("utf-8") # GETTING MAC Address from /sys/class/net/wlan0/address directory -cmdgetmac = ('cat /sys/class/net/' + infname + '/address') +cmdgetmac = "cat /sys/class/net/" + infname + "/address" crrntmac = cret("cat /sys/class/net/" + infname + "/address") -crrntmac = crrntmac.decode('utf-8') +crrntmac = crrntmac.decode("utf-8") print( - "Your Current mac address = " + crrntmac + "\nEnter Option to change Your MAC:\n1. Enter MAC address manually \n2. Automatic Random MAC address") + "Your Current mac address = " + + crrntmac + + "\nEnter Option to change Your MAC:\n1. Enter MAC address manually \n2. Automatic Random MAC address" +) opt = int(input()) if opt == 1: @@ -52,16 +55,16 @@ def retrandmac(mac): print("Please wait changing mac address..................") # first turn off wifi - cret('nmcli radio wifi off') + cret("nmcli radio wifi off") changemaccmd = "sudo ip link set dev " + infname + " address " + newmac # executing command with new mac address cret(changemaccmd) # turning on wifi - cret('nmcli radio wifi on') + cret("nmcli radio wifi on") # GETTING MAC Address from /sys/class/net/wlan0/address directory cr = cret("cat /sys/class/net/" + infname + "/address") - cr = cr.decode('utf-8') + cr = cr.decode("utf-8") print("\nNow Your Current mac address = " + cr) @@ -69,12 +72,12 @@ def retrandmac(mac): elif opt == 2: genmac = retrandmac(randmac()) print("Please wait generating new mac address.....................") - cret('nmcli radio wifi off') + cret("nmcli radio wifi off") changemaccmd = "sudo ip link set dev " + infname + " address " + genmac cret(changemaccmd) - cret('nmcli radio wifi on') + cret("nmcli radio wifi on") cr = cret("cat /sys/class/net/" + infname + "/address") - cr = cr.decode('utf-8') + cr = cr.decode("utf-8") print("Now Your Current mac address = " + cr) else: diff --git a/encrypter-decrypter-gui.py b/encrypter-decrypter-gui.py index bca9db628b1..ea46ea95bb9 100644 --- a/encrypter-decrypter-gui.py +++ b/encrypter-decrypter-gui.py @@ -4,13 +4,14 @@ from tkinter import ttk from tkinter.messagebox import showerror from tkinter.scrolledtext import ScrolledText + # ============================================================= class Main(tk.Tk): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.title('Alphacrypter') + self.title("Alphacrypter") # ----- Setting Geometry ----- self.geometry_settings() @@ -20,8 +21,8 @@ def geometry_settings(self): _my_w = 300 _my_h = 450 # ----- Now Getting X and Y Coordinates - _x = int(_com_scr_w/2 - _my_w/2) - _y = int(_com_scr_h/2 - _my_h/2) + _x = int(_com_scr_w / 2 - _my_w / 2) + _y = int(_com_scr_h / 2 - _my_h / 2) _geo_string = str(_my_w) + "x" + str(_my_h) + "+" + str(_x) + "+" + str(_y) self.geometry(_geo_string) # ----- Geometry Setting Completed Now Disabling Resize Screen Button ----- @@ -33,35 +34,77 @@ def __init__(self, parent): self.parent = parent # ========== Data Key ========== self.data_dic = { - 'a': 'q', 'b': 'w', 'c': 'e', 'd': 'r', 'e': 't', 'f': 'y', 'g': 'u', 'h': 'i', 'i': 'o', 'j': 'p', - 'k': 'a', 'l': 's', 'm': 'd', 'n': 'f', 'o': 'g', 'p': 'h', 'q': 'j', 'r': 'k', 's': 'l', - 't': 'z', 'u': 'x', 'v': 'c', 'w': 'v', 'x': 'b', 'y': 'n', 'z': 'm', - '1': '_', '2': '-', '3': '|', '4': '?', '5': '*', '6': '!', '7': '@', '8': '#', '9': '$', '0': '~', - '.': '/', ',': '+', ' ': '&' + "a": "q", + "b": "w", + "c": "e", + "d": "r", + "e": "t", + "f": "y", + "g": "u", + "h": "i", + "i": "o", + "j": "p", + "k": "a", + "l": "s", + "m": "d", + "n": "f", + "o": "g", + "p": "h", + "q": "j", + "r": "k", + "s": "l", + "t": "z", + "u": "x", + "v": "c", + "w": "v", + "x": "b", + "y": "n", + "z": "m", + "1": "_", + "2": "-", + "3": "|", + "4": "?", + "5": "*", + "6": "!", + "7": "@", + "8": "#", + "9": "$", + "0": "~", + ".": "/", + ",": "+", + " ": "&", } # ============================== # ----- Notebook With Two Pages ----- self.nb = ttk.Notebook(self.parent) self.page1 = ttk.Frame(self.nb) self.page2 = ttk.Frame(self.nb) - self.nb.add(self.page1, text='Encrypt The Words') - self.nb.add(self.page2, text='Decrypt The Words') - self.nb.pack(expand=True, fill='both') + self.nb.add(self.page1, text="Encrypt The Words") + self.nb.add(self.page2, text="Decrypt The Words") + self.nb.pack(expand=True, fill="both") # ----- LabelFrames ----- - self.page1_main_label = ttk.LabelFrame(self.page1, text='Encrypt Any Text') # <----- Page1 LabelFrame1 + self.page1_main_label = ttk.LabelFrame( + self.page1, text="Encrypt Any Text" + ) # <----- Page1 LabelFrame1 self.page1_main_label.grid(row=0, column=0, pady=20, padx=2, ipadx=20) - self.page1_output_label = ttk.LabelFrame(self.page1, text='Decrypted Text') + self.page1_output_label = ttk.LabelFrame(self.page1, text="Decrypted Text") self.page1_output_label.grid(row=1, column=0, pady=10, padx=2) - self.page2_main_label = ttk.LabelFrame(self.page2, text='Decrypt Any Text') # <----- Page1 LabelFrame1 + self.page2_main_label = ttk.LabelFrame( + self.page2, text="Decrypt Any Text" + ) # <----- Page1 LabelFrame1 self.page2_main_label.grid(row=0, column=0, pady=20, padx=2, ipadx=20) - self.page2_output_label = ttk.LabelFrame(self.page2, text='Real Text') + self.page2_output_label = ttk.LabelFrame(self.page2, text="Real Text") self.page2_output_label.grid(row=1, column=0, pady=10, padx=2) # <---Scrolled Text Global - self.decrypted_text_box = ScrolledText(self.page1_output_label, width=30, height=5, state='normal') + self.decrypted_text_box = ScrolledText( + self.page1_output_label, width=30, height=5, state="normal" + ) self.decrypted_text_box.grid(row=1, column=0, padx=2, pady=10) - self.text_box = ScrolledText(self.page2_output_label, width=30, height=5, state='normal') + self.text_box = ScrolledText( + self.page2_output_label, width=30, height=5, state="normal" + ) self.text_box.grid(row=1, column=0, padx=2, pady=10) # ----- Variables ----- self.user_text = tk.StringVar() @@ -75,51 +118,88 @@ def __init__(self, parent): def page1_inside(self): style = ttk.Style() - user_text_label = ttk.Label(self.page1_main_label, text='Enter Your Text Here : ', font=('', 14)) + user_text_label = ttk.Label( + self.page1_main_label, text="Enter Your Text Here : ", font=("", 14) + ) user_text_label.grid(row=0, column=0, pady=10) - user_entry_box = ttk.Entry(self.page1_main_label, width=35, textvariable=self.user_text) + user_entry_box = ttk.Entry( + self.page1_main_label, width=35, textvariable=self.user_text + ) user_entry_box.grid(row=1, column=0) - style.configure('TButton', foreground='black', background='white', relief='groove', font=('', 12)) - encrypt_btn = ttk.Button(self.page1_main_label, text='Encrypt Text', style='TButton', command=self.encrypt_now) + style.configure( + "TButton", + foreground="black", + background="white", + relief="groove", + font=("", 12), + ) + encrypt_btn = ttk.Button( + self.page1_main_label, + text="Encrypt Text", + style="TButton", + command=self.encrypt_now, + ) encrypt_btn.grid(row=2, column=0, pady=15) + # ---------- Page1 Button Binding Function ---------- def encrypt_now(self): user_text = self.user_text.get() - if user_text == '': - showerror('Nothing Found', 'Please Enter Something In Entry Box To Encrypt...!') + if user_text == "": + showerror( + "Nothing Found", "Please Enter Something In Entry Box To Encrypt...!" + ) return else: - self.decrypted_user_text = self.backend_work('Encrypt', user_text) + self.decrypted_user_text = self.backend_work("Encrypt", user_text) self.decrypted_text_box.insert(tk.INSERT, self.decrypted_user_text, tk.END) # --------------------------------------------------Binding Functions of Page1 End Here # Page2 ------------------> def page2_inside(self): style = ttk.Style() - user_text_label = ttk.Label(self.page2_main_label, text='Enter Decrypted Text Here : ', font=('', 14)) + user_text_label = ttk.Label( + self.page2_main_label, text="Enter Decrypted Text Here : ", font=("", 14) + ) user_text_label.grid(row=0, column=0, pady=10) - user_entry_box = ttk.Entry(self.page2_main_label, width=35, textvariable=self.user_text2) + user_entry_box = ttk.Entry( + self.page2_main_label, width=35, textvariable=self.user_text2 + ) user_entry_box.grid(row=1, column=0) - style.configure('TButton', foreground='black', background='white', relief='groove', font=('', 12)) - encrypt_btn = ttk.Button(self.page2_main_label, text='Decrypt Text', style='TButton', command=self.decrypt_now) + style.configure( + "TButton", + foreground="black", + background="white", + relief="groove", + font=("", 12), + ) + encrypt_btn = ttk.Button( + self.page2_main_label, + text="Decrypt Text", + style="TButton", + command=self.decrypt_now, + ) encrypt_btn.grid(row=2, column=0, pady=15) # ---------- Page1 Button Binding Function ---------- def decrypt_now(self): user_text = self.user_text2.get() - if user_text == '': - showerror('Nothing Found', 'Please Enter Something In Entry Box To Encrypt...!') + if user_text == "": + showerror( + "Nothing Found", "Please Enter Something In Entry Box To Encrypt...!" + ) return else: - self.real_text = self.backend_work('Decrypt', user_text) + self.real_text = self.backend_work("Decrypt", user_text) self.text_box.insert(tk.INSERT, self.real_text, tk.END) def backend_work(self, todo, text_coming): - text_to_return = '' - if todo == 'Encrypt': + text_to_return = "" + if todo == "Encrypt": try: - text_coming = str(text_coming).lower() # <----- Lowering the letters as dic in lower letter + text_coming = str( + text_coming + ).lower() # <----- Lowering the letters as dic in lower letter for word in text_coming: for key, value in self.data_dic.items(): if word == key: @@ -127,10 +207,10 @@ def backend_work(self, todo, text_coming): text_to_return += value except ValueError: - showerror('Unknown', 'Something Went Wrong, Please Restart Application') + showerror("Unknown", "Something Went Wrong, Please Restart Application") return text_to_return - elif todo == 'Decrypt': + elif todo == "Decrypt": try: text_coming = str(text_coming).lower() for word in text_coming: @@ -139,12 +219,12 @@ def backend_work(self, todo, text_coming): text_to_return += key except ValueError: - showerror('Unknown', 'Something Went Wrong, Please Restart Application') + showerror("Unknown", "Something Went Wrong, Please Restart Application") return text_to_return else: - showerror('No Function', 'Function Could not get what to do...!') + showerror("No Function", "Function Could not get what to do...!") # ============================================================= diff --git a/numpy.py b/num-py.py similarity index 77% rename from numpy.py rename to num-py.py index 5f3953f78d2..af365bd585d 100644 --- a/numpy.py +++ b/num-py.py @@ -1,6 +1,6 @@ import numpy as np -#to check if shape are equal and find there power +# to check if shape are equal and find there power def get_array(x, y): a = np.shape(x) b = np.shape(y) @@ -13,15 +13,16 @@ def get_array(x, y): else: print("Error : Shape of the given arrays is not equal.") -#0d array + +# 0d array np_arr1 = np.array(3) np_arr2 = np.array(4) -#1d array +# 1d array np_arr3 = np.array([1, 2]) np_arr4 = np.array([3, 4]) -#2d array -np_arr5 = np.array([[1,2], [3,4]]) -np_arr6 = np.array([[5,6], [7,8]]) +# 2d array +np_arr5 = np.array([[1, 2], [3, 4]]) +np_arr6 = np.array([[5, 6], [7, 8]]) get_array(np_arr1, np_arr2) print() diff --git a/pan.py b/pan.py index 8bc494b9c17..92135935c64 100644 --- a/pan.py +++ b/pan.py @@ -14,67 +14,73 @@ s = pd.DataFrame(x2) print(s) -x3 = np.array([['Alex', 10], ['Nishit', 21], ['Aman', 22]]) -s = pd.DataFrame(x3, columns=['Name', 'Age']) +x3 = np.array([["Alex", 10], ["Nishit", 21], ["Aman", 22]]) +s = pd.DataFrame(x3, columns=["Name", "Age"]) print(s) -data = {'Name': ['Tom', 'Jack', 'Steve', 'Ricky'], 'Age': [28, 34, 29, 42]} -df = pd.DataFrame(data, index=['rank1', 'rank2', 'rank3', 'rank4']) +data = {"Name": ["Tom", "Jack", "Steve", "Ricky"], "Age": [28, 34, 29, 42]} +df = pd.DataFrame(data, index=["rank1", "rank2", "rank3", "rank4"]) print(df) -data = [{'a': 1, 'b': 2}, {'a': 3, 'b': 4, 'c': 5}] +data = [{"a": 1, "b": 2}, {"a": 3, "b": 4, "c": 5}] df = pd.DataFrame(data) print(df) -d = {'one': pd.Series([1, 2, 3], index=['a', 'b', 'c']), - 'two': pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])} +d = { + "one": pd.Series([1, 2, 3], index=["a", "b", "c"]), + "two": pd.Series([1, 2, 3, 4], index=["a", "b", "c", "d"]), +} df = pd.DataFrame(d) print(df) # ....Adding New column......# -data = {'one': pd.Series([1, 2, 3, 4], index=[1, 2, 3, 4]), - 'two': pd.Series([1, 2, 3], index=[1, 2, 3])} +data = { + "one": pd.Series([1, 2, 3, 4], index=[1, 2, 3, 4]), + "two": pd.Series([1, 2, 3], index=[1, 2, 3]), +} df = pd.DataFrame(data) print(df) -df['three'] = pd.Series([1, 2], index=[1, 2]) +df["three"] = pd.Series([1, 2], index=[1, 2]) print(df) # ......Deleting a column......# -data = {'one': pd.Series([1, 2, 3, 4], index=[1, 2, 3, 4]), - 'two': pd.Series([1, 2, 3], index=[1, 2, 3]), - 'three': pd.Series([1, 1], index=[1, 2]) - } +data = { + "one": pd.Series([1, 2, 3, 4], index=[1, 2, 3, 4]), + "two": pd.Series([1, 2, 3], index=[1, 2, 3]), + "three": pd.Series([1, 1], index=[1, 2]), +} df = pd.DataFrame(data) print(df) -del df['one'] +del df["one"] print(df) -df.pop('two') +df.pop("two") print(df) # ......Selecting a particular Row............# -data = {'one': pd.Series([1, 2, 3, 4], index=[1, 2, 3, 4]), - 'two': pd.Series([1, 2, 3], index=[1, 2, 3]), - 'three': pd.Series([1, 1], index=[1, 2]) - } +data = { + "one": pd.Series([1, 2, 3, 4], index=[1, 2, 3, 4]), + "two": pd.Series([1, 2, 3], index=[1, 2, 3]), + "three": pd.Series([1, 1], index=[1, 2]), +} df = pd.DataFrame(data) print(df.loc[2]) print(df[1:4]) # .........Addition of Row.................# -df = pd.DataFrame([[1, 2], [3, 4]], columns=['a', 'b']) -df2 = pd.DataFrame([[5, 6], [7, 8]], columns=['a', 'b']) +df = pd.DataFrame([[1, 2], [3, 4]], columns=["a", "b"]) +df2 = pd.DataFrame([[5, 6], [7, 8]], columns=["a", "b"]) df = df.append(df2) print(df.head()) # ........Deleting a Row..................# -df = pd.DataFrame([[1, 2], [3, 4]], columns=['a', 'b']) -df2 = pd.DataFrame([[5, 6], [7, 8]], columns=['a', 'b']) +df = pd.DataFrame([[1, 2], [3, 4]], columns=["a", "b"]) +df2 = pd.DataFrame([[5, 6], [7, 8]], columns=["a", "b"]) df = df.append(df2) @@ -86,9 +92,11 @@ # ..........................Functions.....................................# -d = {'Name': pd.Series(['Tom', 'James', 'Ricky', 'Vin', 'Steve', 'Smith', 'Jack']), - 'Age': pd.Series([25, 26, 25, 23, 30, 29, 23]), - 'Rating': pd.Series([4.23, 3.24, 3.98, 2.56, 3.20, 4.6, 3.8])} +d = { + "Name": pd.Series(["Tom", "James", "Ricky", "Vin", "Steve", "Smith", "Jack"]), + "Age": pd.Series([25, 26, 25, 23, 30, 29, 23]), + "Rating": pd.Series([4.23, 3.24, 3.98, 2.56, 3.20, 4.6, 3.8]), +} df = pd.DataFrame(d) print("The transpose of the data series is:") @@ -99,28 +107,66 @@ # .........................Statistics.......................................# -d = {'Name': pd.Series(['Tom', 'James', 'Ricky', 'Vin', 'Steve', 'Smith', 'Jack', - 'Lee', 'David', 'Gasper', 'Betina', 'Andres']), - 'Age': pd.Series([25, 26, 25, 23, 30, 29, 23, 34, 40, 30, 51, 46]), - 'Rating': pd.Series([4.23, 3.24, 3.98, 2.56, 3.20, 4.6, 3.8, 3.78, 2.98, 4.80, 4.10, 3.65]) - } +d = { + "Name": pd.Series( + [ + "Tom", + "James", + "Ricky", + "Vin", + "Steve", + "Smith", + "Jack", + "Lee", + "David", + "Gasper", + "Betina", + "Andres", + ] + ), + "Age": pd.Series([25, 26, 25, 23, 30, 29, 23, 34, 40, 30, 51, 46]), + "Rating": pd.Series( + [4.23, 3.24, 3.98, 2.56, 3.20, 4.6, 3.8, 3.78, 2.98, 4.80, 4.10, 3.65] + ), +} df = pd.DataFrame(d) print(df.sum()) -d = {'Name': pd.Series(['Tom', 'James', 'Ricky', 'Vin', 'Steve', 'Smith', 'Jack', - 'Lee', 'David', 'Gasper', 'Betina', 'Andres']), - 'Age': pd.Series([25, 26, 25, 23, 30, 29, 23, 34, 40, 30, 51, 46]), - 'Rating': pd.Series([4.23, 3.24, 3.98, 2.56, 3.20, 4.6, 3.8, 3.78, 2.98, 4.80, 4.10, 3.65]) - } +d = { + "Name": pd.Series( + [ + "Tom", + "James", + "Ricky", + "Vin", + "Steve", + "Smith", + "Jack", + "Lee", + "David", + "Gasper", + "Betina", + "Andres", + ] + ), + "Age": pd.Series([25, 26, 25, 23, 30, 29, 23, 34, 40, 30, 51, 46]), + "Rating": pd.Series( + [4.23, 3.24, 3.98, 2.56, 3.20, 4.6, 3.8, 3.78, 2.98, 4.80, 4.10, 3.65] + ), +} df = pd.DataFrame(d) -print(df.describe(include='all')) +print(df.describe(include="all")) # .......................Sorting..........................................# # Using the sort_index() method, by passing the axis arguments and the order of sorting, # DataFrame can be sorted. By default, sorting is done on row labels in ascending order. -unsorted_df = pd.DataFrame(np.random.randn(10, 2), index=[1, 4, 6, 2, 3, 5, 9, 8, 0, 7], columns=['col2', 'col1']) +unsorted_df = pd.DataFrame( + np.random.randn(10, 2), + index=[1, 4, 6, 2, 3, 5, 9, 8, 0, 7], + columns=["col2", "col1"], +) sorted_df = unsorted_df.sort_index() print(sorted_df) @@ -131,26 +177,33 @@ # the sorting can be done on the column labels. By default, axis=0, sort by row. # Let us consider the following example to understand the same. -unsorted_df = pd.DataFrame(np.random.randn(10, 2), index=[1, 4, 6, 2, 3, 5, 9, 8, 0, 7], columns=['col2', 'col1']) +unsorted_df = pd.DataFrame( + np.random.randn(10, 2), + index=[1, 4, 6, 2, 3, 5, 9, 8, 0, 7], + columns=["col2", "col1"], +) sorted_df = unsorted_df.sort_index(axis=1) print(sorted_df) -unsorted_df = pd.DataFrame({'col1': [2, 1, 1, 1], 'col2': [1, 3, 2, 4]}) -sorted_df = unsorted_df.sort_values(by='col1', kind='mergesort') +unsorted_df = pd.DataFrame({"col1": [2, 1, 1, 1], "col2": [1, 3, 2, 4]}) +sorted_df = unsorted_df.sort_values(by="col1", kind="mergesort") # print (sorted_df) # ...........................SLICING...............................# -df = pd.DataFrame(np.random.randn(8, 4), - index=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'], columns=['A', 'B', 'C', 'D']) +df = pd.DataFrame( + np.random.randn(8, 4), + index=["a", "b", "c", "d", "e", "f", "g", "h"], + columns=["A", "B", "C", "D"], +) # Select all rows for multiple columns, say list[] -print(df.loc[:, ['A', 'C']]) -print(df.loc[['a', 'b', 'f', 'h'], ['A', 'C']]) +print(df.loc[:, ["A", "C"]]) +print(df.loc[["a", "b", "f", "h"], ["A", "C"]]) -df = pd.DataFrame(np.random.randn(8, 4), columns=['A', 'B', 'C', 'D']) +df = pd.DataFrame(np.random.randn(8, 4), columns=["A", "B", "C", "D"]) # Index slicing -print(df.ix[:, 'A']) +print(df.ix[:, "A"]) # ............................statistics......................# @@ -160,53 +213,73 @@ df = pd.DataFrame(np.random.randn(5, 2)) print(df.pct_change()) -df = pd.DataFrame(np.random.randn(10, 4), - index=pd.date_range('1/1/2000', periods=10), - columns=['A', 'B', 'C', 'D']) +df = pd.DataFrame( + np.random.randn(10, 4), + index=pd.date_range("1/1/2000", periods=10), + columns=["A", "B", "C", "D"], +) print(df.rolling(window=3).mean()) print(df.expanding(min_periods=3).mean()) # ........................MISSING DATA............................................# -df = pd.DataFrame(np.random.randn(3, 3), index=['a', 'c', 'e'], columns=['one', - 'two', 'three']) +df = pd.DataFrame( + np.random.randn(3, 3), index=["a", "c", "e"], columns=["one", "two", "three"] +) -df = df.reindex(['a', 'b', 'c']) +df = df.reindex(["a", "b", "c"]) print(df) print("NaN replaced with '0':") print(df.fillna(0)) -df = pd.DataFrame(np.random.randn(5, 3), index=['a', 'c', 'e', 'f', - 'h'], columns=['one', 'two', 'three']) +df = pd.DataFrame( + np.random.randn(5, 3), + index=["a", "c", "e", "f", "h"], + columns=["one", "two", "three"], +) -df = df.reindex(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']) +df = df.reindex(["a", "b", "c", "d", "e", "f", "g", "h"]) print(df) -print(df.fillna(method='pad')) -print(df.fillna(method='bfill')) +print(df.fillna(method="pad")) +print(df.fillna(method="bfill")) print(df.dropna()) print(df.dropna(axis=1)) # .........................Grouping...............................................# -ipl_data = {'Team': ['Riders', 'Riders', 'Devils', 'Devils', 'Kings', - 'kings', 'Kings', 'Kings', 'Riders', 'Royals', 'Royals', 'Riders'], - 'Rank': [1, 2, 2, 3, 3, 4, 1, 1, 2, 4, 1, 2], - 'Year': [2014, 2015, 2014, 2015, 2014, 2015, 2016, 2017, 2016, 2014, 2015, 2017], - 'Points': [876, 789, 863, 673, 741, 812, 756, 788, 694, 701, 804, 690]} +ipl_data = { + "Team": [ + "Riders", + "Riders", + "Devils", + "Devils", + "Kings", + "kings", + "Kings", + "Kings", + "Riders", + "Royals", + "Royals", + "Riders", + ], + "Rank": [1, 2, 2, 3, 3, 4, 1, 1, 2, 4, 1, 2], + "Year": [2014, 2015, 2014, 2015, 2014, 2015, 2016, 2017, 2016, 2014, 2015, 2017], + "Points": [876, 789, 863, 673, 741, 812, 756, 788, 694, 701, 804, 690], +} df = pd.DataFrame(ipl_data) -grouped = df.groupby('Year') +grouped = df.groupby("Year") for name, group in grouped: print(name) print(group) print(grouped.get_group(2014)) -grouped = df.groupby('Team') -print(grouped['Points'].agg([np.sum, np.mean, np.std])) +grouped = df.groupby("Team") +print(grouped["Points"].agg([np.sum, np.mean, np.std])) # ...............................Reading a Csv File............................# diff --git a/tweeter.py b/tweeter.py index ff179140f58..73a7b3ce57a 100644 --- a/tweeter.py +++ b/tweeter.py @@ -26,7 +26,7 @@ def getStatus(): lines.append(line) else: break - status = '\n'.join(lines) + status = "\n".join(lines) return status