My simple flask website
8 |9 | This website is just a simple demo website 10 | for me to train my front-end development. 11 |
12 |
├── .gitignore ├── Algorithms └── sorting_algorithms.py ├── DesignPatterns └── Singleton.py ├── Graphical ├── PyQt5_Demo.py └── tkinter_demo.py ├── ImageManipulation ├── ImageToIcon.py └── ImageToPDF.py ├── LICENCE ├── Meta-Programming ├── Cards.py ├── CustomLoop.py ├── Custom_Context_Maneger.py ├── Factorial.py ├── Time_Period.py └── VectorArithmetic.py ├── Modules ├── BarCode.py ├── Database.py ├── Email.py ├── Geographical_Location.py ├── HowdoiScript.py ├── ISO_Creator.py ├── Instagram_ProfilePic_Download.py ├── LoadingBar.py ├── MultiThreading.py ├── MultiprocessingExample.py ├── OpenCV-Basics.py ├── PasswordHasher.py ├── QR_Generator.py ├── QrBarGenerator.py ├── Screenshot.py ├── SimAnalyzer.py ├── Terminal_Art.py ├── Translator.py ├── TurtleBasics.py ├── WebcamActivation.py ├── ZipCompression.py ├── matplotguide.py ├── mp4ToMp3.py ├── play_song.py ├── tkinter_template.py ├── web_scrape_guide.py └── windows_notification.py ├── README.md ├── Syntax ├── ExceptionHandling.py ├── Functions.py ├── List_comprehenssion-Generator_expressons.py ├── ObjectOriented.py ├── Recursion.py ├── RegularExpressions.py ├── StringSlicing.py └── print_date-Dictionaries.py └── WebDevelopment ├── OnlinePage ├── main │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-39.pyc │ │ └── routes.cpython-39.pyc │ ├── routes.py │ ├── static │ │ ├── pictures │ │ │ ├── arrow-left.svg │ │ │ ├── arrow-right.svg │ │ │ ├── big-eclipse.svg │ │ │ ├── demo_app.png │ │ │ ├── dot-full.svg │ │ │ ├── dot.svg │ │ │ ├── github.png │ │ │ ├── instagram.png │ │ │ ├── logo.png │ │ │ ├── mid-eclipse.svg │ │ │ └── small-eclipse.svg │ │ └── style.css │ └── templates │ │ ├── editor.html │ │ ├── home.html │ │ ├── layout.html │ │ ├── second.html │ │ └── test.html └── run.py ├── run.py └── templates ├── Test.html └── layout.html /.gitignore: -------------------------------------------------------------------------------- 1 | # Editors 2 | .vscode/ 3 | .idea/ 4 | 5 | # Vagrant 6 | .vagrant/ 7 | 8 | # Mac/OSX 9 | .DS_Store 10 | 11 | # Windows 12 | Thumbs.db 13 | 14 | # Source for the following rules: https://raw.githubusercontent.com/github/gitignore/master/Python.gitignore 15 | # Byte-compiled / optimized / DLL files 16 | __pycache__/ 17 | *.py[cod] 18 | *$py.class 19 | 20 | # C extensions 21 | *.so 22 | 23 | # Distribution / packaging 24 | .Python 25 | build/ 26 | develop-eggs/ 27 | dist/ 28 | downloads/ 29 | eggs/ 30 | .eggs/ 31 | lib/ 32 | lib64/ 33 | parts/ 34 | sdist/ 35 | var/ 36 | wheels/ 37 | *.egg-info/ 38 | .installed.cfg 39 | *.egg 40 | MANIFEST 41 | 42 | # PyInstaller 43 | # Usually these files are written by a python script from a template 44 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 45 | *.manifest 46 | *.spec 47 | 48 | # Installer logs 49 | pip-log.txt 50 | pip-delete-this-directory.txt 51 | 52 | # Unit test / coverage reports 53 | htmlcov/ 54 | .tox/ 55 | .nox/ 56 | .coverage 57 | .coverage.* 58 | .cache 59 | nosetests.xml 60 | coverage.xml 61 | *.cover 62 | .hypothesis/ 63 | .pytest_cache/ 64 | 65 | # Translations 66 | *.mo 67 | *.pot 68 | 69 | # Django stuff: 70 | *.log 71 | local_settings.py 72 | db.sqlite3 73 | 74 | # Flask stuff: 75 | instance/ 76 | .webassets-cache 77 | 78 | # Scrapy stuff: 79 | .scrapy 80 | 81 | # Sphinx documentation 82 | docs/_build/ 83 | 84 | # PyBuilder 85 | target/ 86 | 87 | # Jupyter Notebook 88 | .ipynb_checkpoints 89 | 90 | # IPython 91 | profile_default/ 92 | ipython_config.py 93 | 94 | # pyenv 95 | .python-version 96 | 97 | # celery beat schedule file 98 | celerybeat-schedule 99 | 100 | # SageMath parsed files 101 | *.sage.py 102 | 103 | # Environments 104 | .env 105 | .venv 106 | env/ 107 | venv/ 108 | ENV/ 109 | env.bak/ 110 | venv.bak/ 111 | 112 | # Spyder project settings 113 | .spyderproject 114 | .spyproject 115 | 116 | # Rope project settings 117 | .ropeproject 118 | 119 | # mkdocs documentation 120 | /site 121 | 122 | # mypy 123 | .mypy_cache/ 124 | .dmypy.json 125 | dmypy.json -------------------------------------------------------------------------------- /Algorithms/sorting_algorithms.py: -------------------------------------------------------------------------------- 1 | class Sort_Algorithms(object): 2 | def __init__(self): 3 | self.sort_me = [9, 2, 1, 4, 7, 6, 5, 3, 8] 4 | 5 | def __str__(self): 6 | return str(f"\t[ Sorting Algorithm Demo ]\n" 7 | f"Unsorted List: {self.sort_me}\n" 8 | f"Bubble Sort: {self.bubble_sort(self.sort_me)}\tBig-O: O(n^2)\n" 9 | f"Selection Sort: {self.selection_sort(self.sort_me)}\tBig-O: O(n^2)\n" 10 | f"Insertion Sort: {self.insertion_sort(self.sort_me)}\tBig-O: O(n^2)\n" 11 | f"Heap Sort: {self.heap_sort(self.sort_me)}\tBig-O: O(nlog(n))\n" 12 | f"Merge Sort: {self.merge_sort(self.sort_me)}\tBig-O: O(nlog(n))\n" 13 | f"Quick Sort: {self.quick_sort(self.sort_me)}\tBig-O: O(n)") 14 | 15 | def bubble_sort(self, nums): 16 | swapped = True 17 | while swapped: 18 | swapped = False 19 | for i in range(len(nums) - 1): 20 | if nums[i] > nums[i + 1]: 21 | nums[i], nums[i + 1] = nums[i + 1], nums[i] 22 | swapped = True 23 | return nums 24 | 25 | def selection_sort(self, nums): 26 | for i in range(len(nums)): 27 | lowest_value_index = i 28 | for j in range(i + 1, len(nums)): 29 | if nums[j] < nums[lowest_value_index]: 30 | lowest_value_index = j 31 | nums[i], nums[lowest_value_index] = nums[lowest_value_index], nums[i] 32 | return nums 33 | 34 | def insertion_sort(self, nums): 35 | for i in range(1, len(nums)): 36 | item_to_insert = nums[i] 37 | j = i - 1 38 | while j >= 0 and nums[j] > item_to_insert: 39 | nums[j + 1] = nums[j] 40 | j -= 1 41 | nums[j + 1] = item_to_insert 42 | return nums 43 | 44 | def heap_sort(self, nums): 45 | def heapify(nums, heap_size, root_index): 46 | largest = root_index 47 | left_child = (2 * root_index) + 1 48 | right_child = (2 * root_index) + 2 49 | if left_child < heap_size and nums[left_child] > nums[largest]: 50 | largest = left_child 51 | if right_child < heap_size and nums[right_child] > nums[largest]: 52 | largest = right_child 53 | if largest != root_index: 54 | nums[root_index], nums[largest] = nums[largest], nums[root_index] 55 | heapify(nums, heap_size, largest) 56 | 57 | def heap_sorter(nums): 58 | n = len(nums) 59 | for i in range(n, -1, -1): 60 | heapify(nums, n, i) 61 | for i in range(n - 1, 0, -1): 62 | nums[i], nums[0] = nums[0], nums[i] 63 | heapify(nums, i, 0) 64 | heap_sorter(nums) 65 | return nums 66 | 67 | def merge_sort(self, nums): 68 | def merge(left_list, right_list): 69 | sorted_list = [] 70 | left_list_index = right_list_index = 0 71 | left_list_length, right_list_length = len(left_list), len(right_list) 72 | for _ in range(left_list_length + right_list_length): 73 | if left_list_index < left_list_length and right_list_index < right_list_length: 74 | if left_list[left_list_index] <= right_list[right_list_index]: 75 | sorted_list.append(left_list[left_list_index]) 76 | left_list_index += 1 77 | else: 78 | sorted_list.append(right_list[right_list_index]) 79 | right_list_index += 1 80 | elif left_list_index == left_list_length: 81 | sorted_list.append(right_list[right_list_index]) 82 | right_list_index += 1 83 | elif right_list_index == right_list_length: 84 | sorted_list.append(left_list[left_list_index]) 85 | left_list_index += 1 86 | return sorted_list 87 | 88 | def merge_sorter(nums): 89 | if len(nums) <= 1: 90 | return nums 91 | mid = len(nums) // 2 92 | left_list = merge_sorter(nums[:mid]) 93 | right_list = merge_sorter(nums[mid:]) 94 | return merge(left_list, right_list) 95 | merge_sorter(nums) 96 | return nums 97 | 98 | def quick_sort(self, nums): 99 | def partition(nums, low, high): 100 | pivot = nums[(low + high) // 2] 101 | i = low - 1 102 | j = high + 1 103 | while True: 104 | i += 1 105 | while nums[i] < pivot: 106 | i += 1 107 | j -= 1 108 | while nums[j] > pivot: 109 | j -= 1 110 | if i >= j: 111 | return j 112 | nums[i], nums[j] = nums[j], nums[i] 113 | 114 | def quick_sorter(nums): 115 | def _quick_sorter(items, low, high): 116 | if low < high: 117 | split_index = partition(items, low, high) 118 | _quick_sorter(items, low, split_index) 119 | _quick_sorter(items, split_index + 1, high) 120 | _quick_sorter(nums, 0, len(nums) - 1) 121 | quick_sorter(nums) 122 | return nums 123 | 124 | if __name__ == "__main__": 125 | print(Sort_Algorithms()) 126 | -------------------------------------------------------------------------------- /DesignPatterns/Singleton.py: -------------------------------------------------------------------------------- 1 | """ Singleton Design Pattern: 2 | Restricts the instantiation of a class to one 'single' instance. 3 | Example: We have a database, and want to ensure only a single instance is making changes at a time, 4 | this ensures that the data doesn't get currupted by multiple instances changing the value simultaneously. 5 | """ 6 | 7 | import sqlite3 8 | 9 | class Singleton(type): 10 | _instances = {} 11 | def __call__(cls, *args, **kwargs): 12 | if cls not in cls._instances: 13 | cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs) 14 | return cls._instances[cls] 15 | 16 | class TrueDesignPattern(metaclass=Singleton): 17 | connection = None 18 | def __init__(self): 19 | self.cursor, self.connection = self.connect() 20 | self.cursor.execute(f"CREATE TABLE IF NOT EXISTS TableName (time TEXT, day INT, comment TEXT)") 21 | 22 | def connect(self): 23 | if self.connection is None: 24 | self.connection = sqlite3.connect("Database.db") 25 | self.cursor = self.connection.cursor() 26 | return self.connection, self.cursor 27 | 28 | class FalseDesignPattern(object): 29 | connection = None 30 | def __init__(self): 31 | self.cursor, self.connection = self.connect() 32 | self.cursor.execute(f"CREATE TABLE IF NOT EXISTS TableName (time TEXT, day INT, comment TEXT)") 33 | 34 | def connect(self): 35 | if self.connection is None: 36 | self.connection = sqlite3.connect("Database.db") 37 | self.cursor = self.connection.cursor() 38 | return self.connection, self.cursor 39 | 40 | if __name__ == "__main__": 41 | false_instance_0 = FalseDesignPattern() 42 | false_instance_1 = FalseDesignPattern() 43 | true_instance_0 = TrueDesignPattern() 44 | true_instance_1 = TrueDesignPattern() 45 | print(f"Without Singleton: {false_instance_0 == false_instance_1}") 46 | print(f"With Singleton: {true_instance_0 == true_instance_1}") 47 | 48 | -------------------------------------------------------------------------------- /Graphical/PyQt5_Demo.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from PyQt5 import QtCore, QtGui, QtWidgets 3 | from PyQt5.QtWidgets import QApplication, QMainWindow, QLCDNumber 4 | from PyQt5.QtCore import QCoreApplication, QObject, QRunnable, pyqtSignal 5 | 6 | 7 | class MainWindow(QMainWindow): 8 | def __init__(self): 9 | super(MainWindow, self).__init__() 10 | self.setGeometry(200, 200, 573, 240) 11 | self.setWindowTitle("PyQt5 Demonstration") 12 | self.initUI() 13 | 14 | self.count = 0 15 | 16 | def initUI(self): 17 | self.top_label = QtWidgets.QLabel(self) 18 | self.top_label.setGeometry(QtCore.QRect(10, 10, 551, 51)) 19 | font = QtGui.QFont(); font.setFamily("Courier New") 20 | font.setPointSize(36); font.setBold(True) 21 | font.setWeight(75); self.top_label.setFont(font) 22 | self.top_label.setObjectName("top_label") 23 | self.top_label.setText("PyQt5 Demonstration") 24 | 25 | self.change_label = QtWidgets.QLabel(self) 26 | self.change_label.setGeometry(QtCore.QRect(210, 90, 131, 31)) 27 | font = QtGui.QFont(); font.setPointSize(16) 28 | font.setBold(True); font.setWeight(75) 29 | self.change_label.setFont(font) 30 | self.change_label.setObjectName("change_label") 31 | self.change_label.setText("Change Me!") 32 | 33 | self.button = QtWidgets.QPushButton(self) 34 | self.button.setGeometry(QtCore.QRect(210, 140, 131, 41)) 35 | font = QtGui.QFont(); font.setPointSize(14) 36 | font.setBold(True); font.setWeight(75) 37 | self.button.setFont(font) 38 | self.button.setObjectName("button") 39 | self.button.setText("Press Here!") 40 | self.button.clicked.connect(self.pressed) 41 | 42 | self.lcd_counter = QtWidgets.QLCDNumber(self) 43 | self.lcd_counter.setGeometry(QtCore.QRect(440, 100, 80, 35)) 44 | self.lcd_counter.setObjectName("lcd_counter") 45 | 46 | self.count_label = QtWidgets.QLabel(self) 47 | self.count_label.setGeometry(QtCore.QRect(410, 70, 141, 31)) 48 | font = QtGui.QFont(); font.setPointSize(12) 49 | font.setBold(True); font.setWeight(75) 50 | self.count_label.setFont(font) 51 | self.count_label.setObjectName("count_label") 52 | self.count_label.setText("Pressed Counter:") 53 | 54 | self.raise_amount = QtWidgets.QSpinBox(self) 55 | self.raise_amount.setGeometry(QtCore.QRect(50, 100, 42, 22)) 56 | self.raise_amount.setObjectName("raise_amount") 57 | 58 | self.raise_label = QtWidgets.QLabel(self) 59 | self.raise_label.setGeometry(QtCore.QRect(10, 70, 131, 31)) 60 | font = QtGui.QFont(); font.setPointSize(12) 61 | font.setBold(True); font.setWeight(75) 62 | self.raise_label.setFont(font) 63 | self.raise_label.setObjectName("raise_label") 64 | self.raise_label.setText("Raise Amount:") 65 | 66 | 67 | def pressed(self): 68 | raise_amount = self.raise_amount.value() 69 | self.count += raise_amount 70 | self.lcd_counter.display(self.count) 71 | self.change_label.setText(f"Count: {self.count}") 72 | 73 | 74 | if __name__ == "__main__": 75 | app = QApplication(sys.argv) 76 | window = MainWindow() 77 | window.show() 78 | sys.exit(app.exec_()) 79 | -------------------------------------------------------------------------------- /Graphical/tkinter_demo.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | from tkinter.ttk import * 3 | from tkinter import ttk 4 | 5 | class Demo(object): 6 | def __init__(self, master): 7 | frame = Frame(master) 8 | frame.grid() 9 | tabControl = ttk.Notebook(root) 10 | tabControl.configure(width=450, height=250) 11 | 12 | self.option = StringVar() 13 | self.options = ["Option Menu", "Combo Box"] 14 | self.option.set(0) 15 | 16 | self.first_tab = ttk.Frame(tabControl) 17 | tabControl.add(self.first_tab, text="Tab 1") 18 | tabControl.grid() 19 | 20 | self.second_tab = ttk.Frame(tabControl) 21 | tabControl.add(self.second_tab, text="Tab 2") 22 | tabControl.grid() 23 | 24 | self.widgets() 25 | 26 | 27 | def widgets(self): 28 | label_frame = LabelFrame(self.first_tab, text="Label Frame", width=450, height=250) 29 | label_frame.grid(column=0, row=0) 30 | label_frame.grid_propagate(0) 31 | 32 | label = Label(label_frame, text="Label") 33 | label.grid(column=1, row=0) 34 | 35 | entry = Entry(label_frame, width=45) 36 | entry.grid(column=0, row=1, columnspan=3) 37 | entry.insert(0, "Entry field") 38 | 39 | radiobutton_1 = Radiobutton(label_frame, text="Radio 1", value=0) 40 | radiobutton_1.grid(column=0, row=2) 41 | radiobutton_2 = Radiobutton(label_frame, text="Radio 2", value=1) 42 | radiobutton_2.grid(column=1, row=2) 43 | checkbutton = Checkbutton(label_frame, text="Check") 44 | checkbutton.grid(column=2, row=2) 45 | 46 | button = Button(label_frame, text="Button") 47 | button.grid(column=0, row=3) 48 | 49 | menubutton = Menubutton(label_frame, text="Menu Button") 50 | menubutton.grid(column=1, row=3) 51 | menubutton.menu = Menu(menubutton, tearoff=0) 52 | menubutton["menu"] = menubutton.menu 53 | menubutton.menu.add_checkbutton(label="first", variable=None) 54 | menubutton.menu.add_checkbutton(label="last", variable=None) 55 | 56 | scale = Scale(label_frame, from_=0, to=100, orient=HORIZONTAL) 57 | scale.grid(column=0, row=4) 58 | 59 | scrollbar = Scrollbar(label_frame) 60 | scrollbar.grid(column=2, row=4) 61 | 62 | list = Listbox(label_frame, yscrollcommand=scrollbar.set, height=5) 63 | for line in range(5): 64 | list.insert(END, "Listbox Element " + str(line)) 65 | list.grid(column=2, row=4) 66 | scrollbar.config(command=list.yview) 67 | 68 | optionmenu = OptionMenu(label_frame, self.option, *self.options) 69 | optionmenu.grid(column=0, row=5) 70 | 71 | combobox = ttk.Combobox(label_frame, values=self.options) 72 | combobox.grid(column=1, row=5) 73 | combobox.current(0) 74 | 75 | progress = Progressbar(label_frame, orient=HORIZONTAL, length=100, mode='determinate') 76 | progress["value"] = 25 77 | progress.grid(column=2, row=5) 78 | 79 | treeview = ttk.Treeview(self.second_tab) 80 | treeview["columns"] = ("1","2","3") 81 | treeview.column("1", width=25) 82 | treeview.column("2", width=25) 83 | treeview.column("3", width=25) 84 | treeview.heading("1", text ="first") 85 | treeview.heading("2", text ="second") 86 | treeview.heading("3", text ="third") 87 | treeview.insert("", 'end', text ="Row 1", values=("Tree", "_", "View")) 88 | treeview.insert("", 'end', text ="Row 2", values=("Tree", "_", "View")) 89 | treeview.insert("", 'end', text ="Row 3", values=("Tree", "_", "View")) 90 | treeview.grid(column=0, row=0) 91 | treeview.grid_propagate(0) 92 | 93 | if __name__ == '__main__': 94 | root = Tk() 95 | root.title("Tkinter Demo") 96 | Demo(root) 97 | root.mainloop() 98 | -------------------------------------------------------------------------------- /ImageManipulation/ImageToIcon.py: -------------------------------------------------------------------------------- 1 | import PIL.Image 2 | 3 | 4 | def icon_maker(image, size=(32, 32)): 5 | file_ext = image.split(".")[-1] 6 | img = PIL.Image.open(image) 7 | img.save(f"{image.strip(f'.{file_ext}')}.ico", sizes=size) 8 | print(f"{image} have been convertet into an icon!") 9 | 10 | 11 | if __name__ == "__main__": 12 | print("Drag image here:\n") 13 | image = input(r" >> ") 14 | icon_maker(image) 15 | -------------------------------------------------------------------------------- /ImageManipulation/ImageToPDF.py: -------------------------------------------------------------------------------- 1 | import os 2 | from PIL import Image 3 | 4 | 5 | class ImageToPDF(object): 6 | def __init__(self, image_path): 7 | self.image_path = image_path 8 | # Gets the last part of the path given, I.E. picture.png 9 | self.file_name = str(image_path.split("\\")[-1]) 10 | 11 | def convert(self): 12 | try: 13 | # Replaces the image format extension to pdf 14 | new_file = os.path.join(self.image_path.replace(self.file_name.split(".")[-1], "pdf")) 15 | # Pillow instance of desired picture 16 | image_file = Image.open(self.image_path) 17 | result = image_file.convert("RGB") 18 | result.save(new_file) 19 | print("Convertion Successful..") 20 | except: 21 | print("Convertion Unsuccessful..") 22 | 23 | 24 | if __name__ == "__main__": 25 | image = input(r"Drag picture here >> ") 26 | ImageToPDF(image).convert() 27 | 28 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | Mozilla Public License Version 2.0 2 | ================================== 3 | 4 | 1. Definitions 5 | -------------- 6 | 7 | 1.1. "Contributor" 8 | means each individual or legal entity that creates, contributes to 9 | the creation of, or owns Covered Software. 10 | 11 | 1.2. "Contributor Version" 12 | means the combination of the Contributions of others (if any) used 13 | by a Contributor and that particular Contributor's Contribution. 14 | 15 | 1.3. "Contribution" 16 | means Covered Software of a particular Contributor. 17 | 18 | 1.4. "Covered Software" 19 | means Source Code Form to which the initial Contributor has attached 20 | the notice in Exhibit A, the Executable Form of such Source Code 21 | Form, and Modifications of such Source Code Form, in each case 22 | including portions thereof. 23 | 24 | 1.5. "Incompatible With Secondary Licenses" 25 | means 26 | 27 | (a) that the initial Contributor has attached the notice described 28 | in Exhibit B to the Covered Software; or 29 | 30 | (b) that the Covered Software was made available under the terms of 31 | version 1.1 or earlier of the License, but not also under the 32 | terms of a Secondary License. 33 | 34 | 1.6. "Executable Form" 35 | means any form of the work other than Source Code Form. 36 | 37 | 1.7. "Larger Work" 38 | means a work that combines Covered Software with other material, in 39 | a separate file or files, that is not Covered Software. 40 | 41 | 1.8. "License" 42 | means this document. 43 | 44 | 1.9. "Licensable" 45 | means having the right to grant, to the maximum extent possible, 46 | whether at the time of the initial grant or subsequently, any and 47 | all of the rights conveyed by this License. 48 | 49 | 1.10. "Modifications" 50 | means any of the following: 51 | 52 | (a) any file in Source Code Form that results from an addition to, 53 | deletion from, or modification of the contents of Covered 54 | Software; or 55 | 56 | (b) any new file in Source Code Form that contains any Covered 57 | Software. 58 | 59 | 1.11. "Patent Claims" of a Contributor 60 | means any patent claim(s), including without limitation, method, 61 | process, and apparatus claims, in any patent Licensable by such 62 | Contributor that would be infringed, but for the grant of the 63 | License, by the making, using, selling, offering for sale, having 64 | made, import, or transfer of either its Contributions or its 65 | Contributor Version. 66 | 67 | 1.12. "Secondary License" 68 | means either the GNU General Public License, Version 2.0, the GNU 69 | Lesser General Public License, Version 2.1, the GNU Affero General 70 | Public License, Version 3.0, or any later versions of those 71 | licenses. 72 | 73 | 1.13. "Source Code Form" 74 | means the form of the work preferred for making modifications. 75 | 76 | 1.14. "You" (or "Your") 77 | means an individual or a legal entity exercising rights under this 78 | License. For legal entities, "You" includes any entity that 79 | controls, is controlled by, or is under common control with You. For 80 | purposes of this definition, "control" means (a) the power, direct 81 | or indirect, to cause the direction or management of such entity, 82 | whether by contract or otherwise, or (b) ownership of more than 83 | fifty percent (50%) of the outstanding shares or beneficial 84 | ownership of such entity. 85 | 86 | 2. License Grants and Conditions 87 | -------------------------------- 88 | 89 | 2.1. Grants 90 | 91 | Each Contributor hereby grants You a world-wide, royalty-free, 92 | non-exclusive license: 93 | 94 | (a) under intellectual property rights (other than patent or trademark) 95 | Licensable by such Contributor to use, reproduce, make available, 96 | modify, display, perform, distribute, and otherwise exploit its 97 | Contributions, either on an unmodified basis, with Modifications, or 98 | as part of a Larger Work; and 99 | 100 | (b) under Patent Claims of such Contributor to make, use, sell, offer 101 | for sale, have made, import, and otherwise transfer either its 102 | Contributions or its Contributor Version. 103 | 104 | 2.2. Effective Date 105 | 106 | The licenses granted in Section 2.1 with respect to any Contribution 107 | become effective for each Contribution on the date the Contributor first 108 | distributes such Contribution. 109 | 110 | 2.3. Limitations on Grant Scope 111 | 112 | The licenses granted in this Section 2 are the only rights granted under 113 | this License. No additional rights or licenses will be implied from the 114 | distribution or licensing of Covered Software under this License. 115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 116 | Contributor: 117 | 118 | (a) for any code that a Contributor has removed from Covered Software; 119 | or 120 | 121 | (b) for infringements caused by: (i) Your and any other third party's 122 | modifications of Covered Software, or (ii) the combination of its 123 | Contributions with other software (except as part of its Contributor 124 | Version); or 125 | 126 | (c) under Patent Claims infringed by Covered Software in the absence of 127 | its Contributions. 128 | 129 | This License does not grant any rights in the trademarks, service marks, 130 | or logos of any Contributor (except as may be necessary to comply with 131 | the notice requirements in Section 3.4). 132 | 133 | 2.4. Subsequent Licenses 134 | 135 | No Contributor makes additional grants as a result of Your choice to 136 | distribute the Covered Software under a subsequent version of this 137 | License (see Section 10.2) or under the terms of a Secondary License (if 138 | permitted under the terms of Section 3.3). 139 | 140 | 2.5. Representation 141 | 142 | Each Contributor represents that the Contributor believes its 143 | Contributions are its original creation(s) or it has sufficient rights 144 | to grant the rights to its Contributions conveyed by this License. 145 | 146 | 2.6. Fair Use 147 | 148 | This License is not intended to limit any rights You have under 149 | applicable copyright doctrines of fair use, fair dealing, or other 150 | equivalents. 151 | 152 | 2.7. Conditions 153 | 154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted 155 | in Section 2.1. 156 | 157 | 3. Responsibilities 158 | ------------------- 159 | 160 | 3.1. Distribution of Source Form 161 | 162 | All distribution of Covered Software in Source Code Form, including any 163 | Modifications that You create or to which You contribute, must be under 164 | the terms of this License. You must inform recipients that the Source 165 | Code Form of the Covered Software is governed by the terms of this 166 | License, and how they can obtain a copy of this License. You may not 167 | attempt to alter or restrict the recipients' rights in the Source Code 168 | Form. 169 | 170 | 3.2. Distribution of Executable Form 171 | 172 | If You distribute Covered Software in Executable Form then: 173 | 174 | (a) such Covered Software must also be made available in Source Code 175 | Form, as described in Section 3.1, and You must inform recipients of 176 | the Executable Form how they can obtain a copy of such Source Code 177 | Form by reasonable means in a timely manner, at a charge no more 178 | than the cost of distribution to the recipient; and 179 | 180 | (b) You may distribute such Executable Form under the terms of this 181 | License, or sublicense it under different terms, provided that the 182 | license for the Executable Form does not attempt to limit or alter 183 | the recipients' rights in the Source Code Form under this License. 184 | 185 | 3.3. Distribution of a Larger Work 186 | 187 | You may create and distribute a Larger Work under terms of Your choice, 188 | provided that You also comply with the requirements of this License for 189 | the Covered Software. If the Larger Work is a combination of Covered 190 | Software with a work governed by one or more Secondary Licenses, and the 191 | Covered Software is not Incompatible With Secondary Licenses, this 192 | License permits You to additionally distribute such Covered Software 193 | under the terms of such Secondary License(s), so that the recipient of 194 | the Larger Work may, at their option, further distribute the Covered 195 | Software under the terms of either this License or such Secondary 196 | License(s). 197 | 198 | 3.4. Notices 199 | 200 | You may not remove or alter the substance of any license notices 201 | (including copyright notices, patent notices, disclaimers of warranty, 202 | or limitations of liability) contained within the Source Code Form of 203 | the Covered Software, except that You may alter any license notices to 204 | the extent required to remedy known factual inaccuracies. 205 | 206 | 3.5. Application of Additional Terms 207 | 208 | You may choose to offer, and to charge a fee for, warranty, support, 209 | indemnity or liability obligations to one or more recipients of Covered 210 | Software. However, You may do so only on Your own behalf, and not on 211 | behalf of any Contributor. You must make it absolutely clear that any 212 | such warranty, support, indemnity, or liability obligation is offered by 213 | You alone, and You hereby agree to indemnify every Contributor for any 214 | liability incurred by such Contributor as a result of warranty, support, 215 | indemnity or liability terms You offer. You may include additional 216 | disclaimers of warranty and limitations of liability specific to any 217 | jurisdiction. 218 | 219 | 4. Inability to Comply Due to Statute or Regulation 220 | --------------------------------------------------- 221 | 222 | If it is impossible for You to comply with any of the terms of this 223 | License with respect to some or all of the Covered Software due to 224 | statute, judicial order, or regulation then You must: (a) comply with 225 | the terms of this License to the maximum extent possible; and (b) 226 | describe the limitations and the code they affect. Such description must 227 | be placed in a text file included with all distributions of the Covered 228 | Software under this License. Except to the extent prohibited by statute 229 | or regulation, such description must be sufficiently detailed for a 230 | recipient of ordinary skill to be able to understand it. 231 | 232 | 5. Termination 233 | -------------- 234 | 235 | 5.1. The rights granted under this License will terminate automatically 236 | if You fail to comply with any of its terms. However, if You become 237 | compliant, then the rights granted under this License from a particular 238 | Contributor are reinstated (a) provisionally, unless and until such 239 | Contributor explicitly and finally terminates Your grants, and (b) on an 240 | ongoing basis, if such Contributor fails to notify You of the 241 | non-compliance by some reasonable means prior to 60 days after You have 242 | come back into compliance. Moreover, Your grants from a particular 243 | Contributor are reinstated on an ongoing basis if such Contributor 244 | notifies You of the non-compliance by some reasonable means, this is the 245 | first time You have received notice of non-compliance with this License 246 | from such Contributor, and You become compliant prior to 30 days after 247 | Your receipt of the notice. 248 | 249 | 5.2. If You initiate litigation against any entity by asserting a patent 250 | infringement claim (excluding declaratory judgment actions, 251 | counter-claims, and cross-claims) alleging that a Contributor Version 252 | directly or indirectly infringes any patent, then the rights granted to 253 | You by any and all Contributors for the Covered Software under Section 254 | 2.1 of this License shall terminate. 255 | 256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all 257 | end user license agreements (excluding distributors and resellers) which 258 | have been validly granted by You or Your distributors under this License 259 | prior to termination shall survive termination. 260 | 261 | ************************************************************************ 262 | * * 263 | * 6. Disclaimer of Warranty * 264 | * ------------------------- * 265 | * * 266 | * Covered Software is provided under this License on an "as is" * 267 | * basis, without warranty of any kind, either expressed, implied, or * 268 | * statutory, including, without limitation, warranties that the * 269 | * Covered Software is free of defects, merchantable, fit for a * 270 | * particular purpose or non-infringing. The entire risk as to the * 271 | * quality and performance of the Covered Software is with You. * 272 | * Should any Covered Software prove defective in any respect, You * 273 | * (not any Contributor) assume the cost of any necessary servicing, * 274 | * repair, or correction. This disclaimer of warranty constitutes an * 275 | * essential part of this License. No use of any Covered Software is * 276 | * authorized under this License except under this disclaimer. * 277 | * * 278 | ************************************************************************ 279 | 280 | ************************************************************************ 281 | * * 282 | * 7. Limitation of Liability * 283 | * -------------------------- * 284 | * * 285 | * Under no circumstances and under no legal theory, whether tort * 286 | * (including negligence), contract, or otherwise, shall any * 287 | * Contributor, or anyone who distributes Covered Software as * 288 | * permitted above, be liable to You for any direct, indirect, * 289 | * special, incidental, or consequential damages of any character * 290 | * including, without limitation, damages for lost profits, loss of * 291 | * goodwill, work stoppage, computer failure or malfunction, or any * 292 | * and all other commercial damages or losses, even if such party * 293 | * shall have been informed of the possibility of such damages. This * 294 | * limitation of liability shall not apply to liability for death or * 295 | * personal injury resulting from such party's negligence to the * 296 | * extent applicable law prohibits such limitation. Some * 297 | * jurisdictions do not allow the exclusion or limitation of * 298 | * incidental or consequential damages, so this exclusion and * 299 | * limitation may not apply to You. * 300 | * * 301 | ************************************************************************ 302 | 303 | 8. Litigation 304 | ------------- 305 | 306 | Any litigation relating to this License may be brought only in the 307 | courts of a jurisdiction where the defendant maintains its principal 308 | place of business and such litigation shall be governed by laws of that 309 | jurisdiction, without reference to its conflict-of-law provisions. 310 | Nothing in this Section shall prevent a party's ability to bring 311 | cross-claims or counter-claims. 312 | 313 | 9. Miscellaneous 314 | ---------------- 315 | 316 | This License represents the complete agreement concerning the subject 317 | matter hereof. If any provision of this License is held to be 318 | unenforceable, such provision shall be reformed only to the extent 319 | necessary to make it enforceable. Any law or regulation which provides 320 | that the language of a contract shall be construed against the drafter 321 | shall not be used to construe this License against a Contributor. 322 | 323 | 10. Versions of the License 324 | --------------------------- 325 | 326 | 10.1. New Versions 327 | 328 | Mozilla Foundation is the license steward. Except as provided in Section 329 | 10.3, no one other than the license steward has the right to modify or 330 | publish new versions of this License. Each version will be given a 331 | distinguishing version number. 332 | 333 | 10.2. Effect of New Versions 334 | 335 | You may distribute the Covered Software under the terms of the version 336 | of the License under which You originally received the Covered Software, 337 | or under the terms of any subsequent version published by the license 338 | steward. 339 | 340 | 10.3. Modified Versions 341 | 342 | If you create software not governed by this License, and you want to 343 | create a new license for such software, you may create and use a 344 | modified version of this License if you rename the license and remove 345 | any references to the name of the license steward (except to note that 346 | such modified license differs from this License). 347 | 348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 349 | Licenses 350 | 351 | If You choose to distribute Source Code Form that is Incompatible With 352 | Secondary Licenses under the terms of this version of the License, the 353 | notice described in Exhibit B of this License must be attached. 354 | 355 | Exhibit A - Source Code Form License Notice 356 | ------------------------------------------- 357 | 358 | This Source Code Form is subject to the terms of the Mozilla Public 359 | License, v. 2.0. If a copy of the MPL was not distributed with this 360 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 361 | 362 | If it is not possible or desirable to put the notice in a particular 363 | file, then You may include the notice in a location (such as a LICENSE 364 | file in a relevant directory) where a recipient would be likely to look 365 | for such a notice. 366 | 367 | You may add additional accurate notices of copyright ownership. 368 | 369 | Exhibit B - "Incompatible With Secondary Licenses" Notice 370 | --------------------------------------------------------- 371 | 372 | This Source Code Form is "Incompatible With Secondary Licenses", as 373 | defined by the Mozilla Public License, v. 2.0. -------------------------------------------------------------------------------- /Meta-Programming/Cards.py: -------------------------------------------------------------------------------- 1 | import collections 2 | from random import choice 3 | 4 | Card = collections.namedtuple("Card", ["rank", "suit"]) # Constructs a simple class to represent individual cards. 5 | # namedtuple can be used to build classes of objects that are just bundles of attrubutes with no custom methods, 6 | # like a database record. 7 | 8 | class DeckOfCards(object): 9 | ranks = [str(n) for n in range(2, 11)] + list("JQKA") # Using list comprehenssion to create each card 10 | suits = "spades diamonds clubs hearts".split() # Splits string into an array of card suits 11 | 12 | def __init__(self): 13 | """ Initializes a deck of cards, using a list comprehenssion """ 14 | self._cards = [Card(rank, suit) for suit in self.suits 15 | for rank in self.ranks] 16 | 17 | 18 | def __len__(self): 19 | """ Allows the len() call to work on the class. The len() function will attempt to call this 20 | 'dunder method' on the class """ 21 | return len(self._cards) 22 | 23 | 24 | def __getitem__(self, position): 25 | """ Delegates to the [] operator of self._cards, making our deck automatically suports slicing """ 26 | return self._cards[position] 27 | 28 | 29 | def get_random(self, card): 30 | """ Picks a random card from the initialized deck of cards. """ 31 | return choice(self._cards) 32 | 33 | 34 | def __str__(self): 35 | """ Returns a string representation of the methods of this class. """ 36 | deck_length = len(self._cards) 37 | random_card = self.get_random(self._cards) 38 | return str(f"Length:\t\t{deck_length}\nRandom Card:\t{random_card}") 39 | 40 | 41 | if __name__ == "__main__": 42 | print(DeckOfCards()) 43 | 44 | -------------------------------------------------------------------------------- /Meta-Programming/CustomLoop.py: -------------------------------------------------------------------------------- 1 | class CustomIterable(object): 2 | def __init__(self, string): 3 | self.string = string 4 | 5 | def __iter__(self): 6 | # Makes the class iterable (Able to loop through) 7 | return CustomLoop(self.string) 8 | 9 | 10 | class CustomLoop(object): 11 | def __init__(self, string): 12 | # Converts string to a list of words 13 | self.words = [word for word in string.split()] 14 | self.index = 0 15 | 16 | def __next__(self): 17 | # Will select the next item in the iterable for each call to the next method. 18 | if self.index == len(self.words): 19 | # Will stop the iteration when the list of words ends 20 | raise StopIteration() 21 | word = self.words[self.index] 22 | self.index += 1 23 | # Returns a single word for each call. 24 | return word 25 | 26 | def __iter__(self): 27 | # Treats the class as an iterable itself, makes us able to loop through. 28 | return self 29 | 30 | 31 | if __name__ == '__main__': 32 | iterable = CustomIterable("Want to learn Python? Follow python_genius today!") 33 | iterator = iter(iterable) 34 | while True: 35 | try: 36 | print(next(iterator)) 37 | except StopIteration: 38 | break 39 | 40 | -------------------------------------------------------------------------------- /Meta-Programming/Custom_Context_Maneger.py: -------------------------------------------------------------------------------- 1 | class Runner: 2 | def __init__(self, who): 3 | print(f'Getting ready to go for a run with {who}') 4 | self.who = who 5 | 6 | 7 | def __enter__(self): 8 | print(f"Putting {self.who}'s shoes on.") 9 | return self.who 10 | 11 | 12 | def __exit__(self, exc_type, exc_value, exc_traceback): 13 | print(f"Taking {self.who}'s shoes off") 14 | 15 | 16 | with Runner(who='Nike') as shoe: 17 | print(f'running with {shoe}') 18 | 19 | -------------------------------------------------------------------------------- /Meta-Programming/Factorial.py: -------------------------------------------------------------------------------- 1 | class Factorial(object): 2 | def __init__(self, num): 3 | self.value = 1 4 | # Multiplies each number in num range with __mul__ method 5 | for i in range(1, num + 1): 6 | self *= i 7 | 8 | def __mul__(self, other): 9 | # Returns a new instance of the Factorial class with updated values 10 | self.value *= other 11 | return self 12 | 13 | def __repr__(self): 14 | # Provices a string representation of the object 15 | return str(self.value) 16 | 17 | if __name__ == "__main__": 18 | factorial = Factorial(5) 19 | print(f"Factorial of 5: {factorial}") 20 | 21 | -------------------------------------------------------------------------------- /Meta-Programming/Time_Period.py: -------------------------------------------------------------------------------- 1 | class TimePeriod: 2 | 3 | def __init__(self, hours=0, minutes=0): 4 | self.hours = hours 5 | self.minutes = minutes 6 | 7 | 8 | def __add__(self, other): 9 | minutes = self.minutes + other.minutes 10 | hours = self.hours + other.hours 11 | if minutes >= 60: 12 | minutes -= 60 13 | hours += 1 14 | return TimePeriod(hours, minutes) 15 | 16 | 17 | def __gt__(self, other): 18 | if self.hours > other.hours: 19 | return True 20 | elif self.hours < other.hours: 21 | return False 22 | elif self.minutes > other.minutes: 23 | return True 24 | else: 25 | return False 26 | 27 | 28 | def __eq__(self, other): 29 | return self.hours == other.hours and self.minutes == other.minutes 30 | 31 | 32 | def __str__(self): 33 | return f"{self.hours} hours, {self.minutes} minutes" 34 | 35 | 36 | def __getitem__(self, item): 37 | if item == 'hours': 38 | return self.hours 39 | elif item == 'minutes': 40 | return self.minutes 41 | else: 42 | raise KeyError() 43 | 44 | 45 | if __name__ == "__main__": 46 | print(TimePeriod(2, 30)) 47 | 48 | 49 | """ Result: 50 | ----------- 51 | 2 hours, 30 minutes 52 | """ -------------------------------------------------------------------------------- /Meta-Programming/VectorArithmetic.py: -------------------------------------------------------------------------------- 1 | import inspect 2 | from math import hypot, sqrt 3 | 4 | class VectorArithmetic(object): 5 | def __init__(self, x=0, y=0): 6 | self.x = x 7 | self.y = y 8 | # Parameter count; self, x & y 9 | self.p_count = len(inspect.signature(VectorArithmetic.__init__).parameters.values()) - 1 10 | 11 | def __repr__(self): 12 | # Representation of the Vector class. 13 | return f"Vector{self.x, self.y}" 14 | 15 | def __abs__(self): 16 | # Magnitude/Length of the vector ||v|| 17 | return round(hypot(self.x, self.y), 2) 18 | 19 | def __add__(self, other): 20 | # Addition of vectors(Add 2 objects together). 21 | x = self.x + other.x 22 | y = self.y + other.y 23 | return VectorArithmetic(x, y) 24 | 25 | def __sub__(self, other): 26 | # Subtraction of vectors. 27 | x = self.x - other.x 28 | y = self.y - other.y 29 | return VectorArithmetic(x, y) 30 | 31 | def __mul__(self, scalar=1): 32 | # Scalar multiplication(Multiply each value in the vector by a scalar). 33 | return VectorArithmetic(self.x * scalar, self.y * scalar) 34 | 35 | def __call__(self): 36 | # Describes the instance of the class if called directly. 37 | print(f"Vector Instance: {VectorArithmetic(self.x, self.y)}") 38 | 39 | def triangle_inequality(self, other): 40 | # The magnitude of the sum of vectors is always less than or equal to the 41 | # sum of the magnitudes of the vectors: ||v + u|| <= ||v|| + ||u|| 42 | vector_0, vector_1 = VectorArithmetic(self.x, self.y), VectorArithmetic(other.x, other.y) 43 | vector_0_mag, vector_1_mag = vector_0.__abs__(), vector_1.__abs__() 44 | mag_of_sum = vector_0.__add__(vector_1).__abs__() 45 | return mag_of_sum <= vector_0_mag + vector_1_mag 46 | 47 | def arithmetic_mean(self): 48 | # Sum of values divided by the amount of values. 49 | return abs((self.x + self.y) / self.p_count) 50 | 51 | def geometric_mean(self): 52 | # Sum of values multiplied together, then take a square root 53 | # (for two numbers), cube root (for three numbers) etc. 54 | return round(sqrt(self.x * self.y), 2) 55 | 56 | if __name__ == "__main__": 57 | vector_0 = VectorArithmetic(7, 10) 58 | vector_1 = VectorArithmetic(3, 7) 59 | methods = { 60 | "added": vector_0.__add__(vector_1), 61 | "subtracted": vector_0.__sub__(vector_1), 62 | "scaled": vector_0.__mul__(5), 63 | "magnitude": vector_0.__abs__(), 64 | "arit_mean": vector_0.arithmetic_mean(), 65 | "geo_mean": vector_0.geometric_mean(), 66 | "inequality": vector_0.triangle_inequality(vector_1) 67 | } 68 | for key in methods: 69 | print(f"{key}: \t {str(methods[key])}") 70 | 71 | -------------------------------------------------------------------------------- /Modules/BarCode.py: -------------------------------------------------------------------------------- 1 | import io 2 | from barcode import EAN13 3 | from barcode.writer import ImageWriter 4 | from PIL import Image 5 | 6 | class Bar_Gen(object): 7 | def __init__(self, digits): 8 | self.bar_image = self.bar_generator(digits) 9 | 10 | @staticmethod 11 | def bar_generator(digits): 12 | temp = io.BytesIO() 13 | EAN13(str(digits), writer=ImageWriter()).write(temp) 14 | image = Image.open(temp) 15 | image = image.resize((400,400), Image.ANTIALIAS) 16 | image.show() 17 | 18 | 19 | if __name__ == "__main__": 20 | while True: 21 | try: 22 | Bar_Gen(int(input("[BAR] Enter 12 digits: "))) 23 | break 24 | except KeyboardInterrupt: 25 | break 26 | except ValueError: 27 | print("Need numeric values.") 28 | continue 29 | 30 | -------------------------------------------------------------------------------- /Modules/Database.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sqlite3 3 | 4 | class MetaSingleton(type): 5 | """ Ensures only a single database connection exists at a time. """ 6 | _instances = {} 7 | 8 | def __call__(cls, *args, **kwargs): 9 | if cls not in cls._instances: 10 | cls._instances[cls] = super(MetaSingleton, cls).__call__(*args, **kwargs) 11 | return cls._instances[cls] 12 | 13 | 14 | class Database(metaclass=MetaSingleton): 15 | """ Singleton Class to Manage SQLite3 Database Operations """ 16 | connection = None 17 | 18 | def __init__(self): 19 | """ Initializes the database, ensures the 'Table_1' exists. """ 20 | self.db_name = "Database_file.db" 21 | self.table_name = "Table_1" 22 | self._setup() 23 | 24 | def _setup(self): 25 | """ Setup database connection and table creation """ 26 | os.chdir(os.path.dirname(os.path.realpath(__file__))) # Ensure directory consistency 27 | self.connect() 28 | self.create_table() 29 | 30 | def connect(self): 31 | """ Establishes a single database connection """ 32 | if self.connection is None: 33 | self.connection = sqlite3.connect(self.db_name) 34 | self.cursor = self.connection.cursor() 35 | return self.cursor 36 | 37 | def create_table(self): 38 | """ Creates 'Table_1' if it doesn't already exist """ 39 | self.cursor.execute(f""" 40 | CREATE TABLE IF NOT EXISTS {self.table_name} ( 41 | column_1 TEXT, 42 | column_2 INTEGER, 43 | column_3 REAL 44 | ) 45 | """) 46 | self.connection.commit() 47 | 48 | def insert_data(self, column_1="First Column", column_2=45, column_3=45.77): 49 | """ Inserts sample data into the table """ 50 | self.cursor.execute(f"INSERT INTO {self.table_name} VALUES (?, ?, ?)", (column_1, column_2, column_3)) 51 | self.connection.commit() 52 | 53 | def read_data(self): 54 | """ Reads and displays data from the table """ 55 | self.cursor.execute(f"SELECT * FROM {self.table_name}") 56 | rows = self.cursor.fetchall() 57 | for row in rows: 58 | print(row) 59 | 60 | def close(self): 61 | """ Closes the database connection """ 62 | self.cursor.close() 63 | self.connection.close() 64 | 65 | 66 | if __name__ == "__main__": 67 | print("=== Without Singleton Pattern ===") 68 | conn1 = sqlite3.connect("Database_file.db") 69 | conn2 = sqlite3.connect("Database_file.db") 70 | 71 | print(f"Connection 1 ID: {id(conn1)}") 72 | print(f"Connection 2 ID: {id(conn2)}") 73 | print("\nResult: Two different connections are created.") 74 | 75 | conn1.close() 76 | conn2.close() 77 | 78 | print("\n=== Demonstrating Singleton Behavior ===") 79 | db1 = Database() 80 | db2 = Database() 81 | 82 | print(f"Database 1 Connection ID: {id(db1.connection)}") 83 | print(f"Database 2 Connection ID: {id(db2.connection)}") 84 | print("\nResult: Both instances share the same connection.") 85 | 86 | print("\n=== Demonstrating Database Operations ===") 87 | db1.insert_data() 88 | print("Data in the database:") 89 | db1.read_data() 90 | 91 | db1.close() 92 | -------------------------------------------------------------------------------- /Modules/Email.py: -------------------------------------------------------------------------------- 1 | import smtplib, ssl, getpass 2 | 3 | class Email(object): 4 | def __init__(self): 5 | self.port = 465 # SSL port 6 | self.smtp_server = "smtp.gmail.com" # smtp server address 7 | creds = self.login_credentials() # Sender credentials 8 | self.sender_email = creds["email"] # Senders email 9 | self.password = creds["pass"] # Senders password 10 | self.context = ssl.create_default_context() # Create a secure SSL context 11 | 12 | def login_credentials(self): 13 | """ The senders login credentials - password is hidden. """ 14 | sender_email = str(input(r"Enter your email: ")) 15 | password = getpass.getpass("Enter your password: ") 16 | return {"email":sender_email, "pass":password} 17 | 18 | def message(self): 19 | """ Subject and message content """ 20 | subject = str(input(r"Subject: ")) 21 | message = str(input(r"Message: ")) 22 | return str(f"Subject: {subject}\n{message}") 23 | 24 | def send_mail(self): 25 | """ Email control and forwarding """ 26 | receiver_email = str(input(r"Enter receivers email here: ")) 27 | message = self.message() 28 | try: 29 | with smtplib.SMTP_SSL(self.smtp_server, self.port, context=self.context) as server: 30 | server.login(self.sender_email, self.password) 31 | server.sendmail(self.sender_email, receiver_email, message) 32 | print("\nEmail successfully sent!") 33 | except: 34 | print("\nError occurred while trying to send the email.. Please try again.") 35 | 36 | if __name__ == "__main__": 37 | Email().send_mail() 38 | 39 | -------------------------------------------------------------------------------- /Modules/Geographical_Location.py: -------------------------------------------------------------------------------- 1 | import geocoder 2 | import reverse_geocoder as rg 3 | 4 | class IpLocator(object): 5 | def __init__(self, target=geocoder.ip("me")): 6 | self.data = self.locate(target) 7 | 8 | def __str__(self): 9 | return str(f"\t[ IP Locator ]\n" 10 | f"IP: {self.data[0]}\n" 11 | f"City: {self.data[1]}\n" 12 | f"Country: {self.data[2]}\n" 13 | f"Location: {self.data[3]}") 14 | 15 | def locate(self, target): 16 | latitude, longitude = [*target.latlng] 17 | city = rg.search((latitude, longitude), verbose=False) 18 | return [target.ip, city[0]["name"], target.country, [latitude, longitude]] 19 | 20 | if __name__ == "__main__": 21 | custom_ip = geocoder.ip("8.8.8.8") 22 | locate = IpLocator(custom_ip) 23 | print(locate) 24 | 25 | -------------------------------------------------------------------------------- /Modules/HowdoiScript.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | def configure(): 4 | flags = { 5 | 'Default': '', 6 | 'Read entire query': '-a', 7 | 'Retrieve n number of results': '-n', 8 | 'Display only a link to where the answer is from': '-l', 9 | 'Display the answer in color': '-c', 10 | 'Specify search engine': '-e' 11 | } 12 | for index, flag in enumerate(flags.keys()): 13 | print(f"[{index}] {flag}") 14 | 15 | answer = int(input("\nSelect a flag: ")) 16 | if answer > len(flags.keys()) or answer < 0: 17 | print("Invalid input") 18 | return configure() 19 | else: 20 | flag = flags[list(flags)[answer]] 21 | return flag 22 | 23 | def question_constructor(): 24 | # flag = configure() 25 | while True: 26 | print("\nType your question or type 'exit' to exit") 27 | question = input("\nEnter your question: ") 28 | if question == "exit": 29 | break 30 | print('\n') 31 | question = f"howdoi {question}" 32 | os.system(question) 33 | 34 | 35 | if __name__ == "__main__": 36 | os.system("cls") 37 | while True: 38 | print("\nType your question or type 'exit' to exit") 39 | question = input("\nEnter your question: ") 40 | if question != "exit": 41 | print('\n') 42 | question = f"howdoi {question}" 43 | os.system(question) 44 | continue 45 | break 46 | 47 | -------------------------------------------------------------------------------- /Modules/ISO_Creator.py: -------------------------------------------------------------------------------- 1 | import os, io 2 | import pycdlib 3 | 4 | try: 5 | from cStringIO import StringIO as BytesIO 6 | except ImportError: 7 | from io import BytesIO 8 | 9 | file_path = input(r"Enter path to file >> ") 10 | file_name = file_path.split("\\")[-1].split(".")[0] 11 | 12 | iso = pycdlib.PyCdlib() 13 | iso.new() 14 | 15 | for folders, _, files in os.walk(file_path): 16 | for file in files: 17 | absolute_path = os.path.join(folders, file) 18 | iso.add_fp(BytesIO(absolute_path), len(absolute_path), f"/{absolute_path}.;1") 19 | iso.write(f"{file_name}.iso") 20 | iso.close() 21 | 22 | -------------------------------------------------------------------------------- /Modules/Instagram_ProfilePic_Download.py: -------------------------------------------------------------------------------- 1 | import os 2 | import instaloader 3 | 4 | def download(username): 5 | instance = instaloader.Instaloader() 6 | os.chdir(os.path.join(os.path.expanduser("~"), "Desktop")) 7 | return instance.download_profile(username, profile_pic_only=True) 8 | 9 | if __name__ == "__main__": 10 | download("python_genius") 11 | 12 | -------------------------------------------------------------------------------- /Modules/LoadingBar.py: -------------------------------------------------------------------------------- 1 | import time 2 | from tqdm import tqdm 3 | 4 | 5 | def loading(): 6 | for _ in tqdm(range(100), desc="Loading...", ascii=False, ncols=75, unit="%"): 7 | time.sleep(0.01) 8 | print("Loading Done!") 9 | 10 | 11 | if __name__ == "__main__": 12 | loading() 13 | 14 | -------------------------------------------------------------------------------- /Modules/MultiThreading.py: -------------------------------------------------------------------------------- 1 | import time 2 | import threading 3 | 4 | def function_0(): 5 | print("Thread 1: Is starting...") 6 | time.sleep(.4) 7 | print("Thread 1: Is done!") 8 | 9 | 10 | def function_1(arg=5): 11 | print("Thread 2: Is starting...") 12 | time.sleep(.1) 13 | for num in range(arg): 14 | print(f"Thread 2: {num}") 15 | time.sleep(.1) 16 | print("Thread 2: Is done!") 17 | 18 | 19 | def function_2(): 20 | print("Thread 3: Is starting...") 21 | while True: 22 | print("Thread 3: Daemon process running...") 23 | time.sleep(.1) 24 | 25 | 26 | if __name__ == "__main__": 27 | # Normal thread without any arguments. 28 | thread_0 = threading.Thread(target=function_0) 29 | # Thread with a single argument passed. 30 | thread_1 = threading.Thread(target=function_1, args=(3,)) 31 | # Deamon thread: This thread will terminate when the program stops. 32 | thread_2 = threading.Thread(target=function_2, daemon=True) 33 | # Run the threads. 34 | thread_0.start() 35 | thread_1.start() 36 | thread_2.start() 37 | 38 | -------------------------------------------------------------------------------- /Modules/MultiprocessingExample.py: -------------------------------------------------------------------------------- 1 | import sys , time 2 | import multiprocessing 3 | 4 | 5 | DELAY = 0.1 6 | DISPLAY = ["|", "/", "-", "\\"] 7 | 8 | 9 | def spinner_func(before="", after="" ): 10 | write, flush = sys.stdout.write, sys.stdout.flush 11 | pos = - 1 12 | while True: 13 | pos = (pos + 1 ) % len(DISPLAY) 14 | msg = before + DISPLAY[pos] + after 15 | write(msg); flush() 16 | write("\x08" * len(msg)) 17 | print("\n") 18 | time.sleep(DELAY) 19 | 20 | 21 | def long_computation(): 22 | """ emulate a long computation """ 23 | time.sleep(3) 24 | 25 | 26 | if __name__ == "__main__": 27 | spinner = multiprocessing.Process(None, spinner_func, args=("Please wait...", "")) 28 | spinner.start() 29 | try: 30 | long_computation() 31 | print("Computation done") 32 | finally: 33 | spinner.terminate() 34 | 35 | 36 | -------------------------------------------------------------------------------- /Modules/OpenCV-Basics.py: -------------------------------------------------------------------------------- 1 | import os 2 | import cv2 3 | import random 4 | import datetime 5 | 6 | class ImageRotate(object): 7 | def __init__(self, image): 8 | # Load the image into OpenCV and converts it into a numpy array. 9 | self.image_name = image.split("/")[-1] 10 | self.image = cv2.imread(image, 1) 11 | # Timestamp for image_name 12 | self.timestamp = datetime.datetime.now().strftime("%d%m%H%M%S") 13 | # Creates a folder for manipulated pictures. 14 | if not os.path.exists("Results/"): 15 | os.mkdir("Results") 16 | 17 | def save_image(self): 18 | # Save the image to the Results folder. 19 | cv2.imwrite(f"Results/{self.image_name}_{self.timestamp}", self.image) 20 | 21 | def show_image(self): 22 | # Shows the image until a key is pressed. 23 | cv2.imshow("Manipulated Image", self.image) 24 | cv2.waitKey(0) 25 | cv2.destroyAllWindows() 26 | 27 | def rotation(self): 28 | # Resize the image. 29 | self.image = cv2.resize(self.image, (0, 0), fx=.5, fy=.5) 30 | # Rotates the image. 31 | self.image = cv2.rotate(self.image, cv2.cv2.ROTATE_90_CLOCKWISE) 32 | self.show_image() 33 | 34 | def scramble(self): 35 | # Fills first 100 rows of the picture array with random colors 36 | for i in range(100): 37 | for j in range(self.image.shape[1]): 38 | # Color-code: Blue, Green, Red 39 | self.image[i][j] = [random.randrange(255), 40 | random.randrange(255), 41 | random.randrange(255)] 42 | self.show_image() 43 | 44 | def slice(self): 45 | # copies the pixels from row 500 to 700 and column 600 to 900 46 | cut = self.image[500:700, 600:900] 47 | # Replaces pixels with the copied pixels 48 | self.image[100:300, 650:950] = cut 49 | self.show_image() 50 | 51 | if __name__ == "__main__": 52 | # img = input(r"Enter path to picture >> ") 53 | img = "image.jpg" 54 | image = ImageRotate(img) 55 | image.slice() 56 | 57 | -------------------------------------------------------------------------------- /Modules/PasswordHasher.py: -------------------------------------------------------------------------------- 1 | from argon2 import PasswordHasher # pip install argon2-cffi 2 | 3 | class HashingDemo(object): 4 | def __init__(self, password, comparer): 5 | self.password = password 6 | self.comparer = comparer 7 | self.hasher = PasswordHasher() 8 | self.hashed_password = self.hasher.hash(password) 9 | 10 | def hash_password(self, password): 11 | return self.hasher.hash(password) 12 | 13 | def verify_password(self, hashed_pass, password): 14 | try: 15 | if self.hasher.verify(hashed_pass, password): 16 | return True 17 | except: 18 | return False 19 | 20 | def __repr__(self): 21 | return str(self.verify_password(self.hashed_password, self.comparer)) 22 | 23 | if __name__ == "__main__": 24 | pass_0 = "P4ssw0rd" 25 | pass_1 = "12345678" 26 | check_against = "P4ssw0rd" 27 | true_ins = HashingDemo(pass_0, check_against) 28 | false_ins = HashingDemo(pass_1, check_against) 29 | true_hash = true_ins.hashed_password.split(',p=')[-1] 30 | false_hash = false_ins.hashed_password.split(',p=')[-1] 31 | print(f"Instance_0: Password = {pass_0} | Hash = {true_hash} | {pass_0} = {check_against} == {true_ins}") 32 | print(f"Instance_1: Password = {pass_1} | Hash = {false_hash} | {pass_1} = {check_against} == {false_ins}") 33 | 34 | 35 | -------------------------------------------------------------------------------- /Modules/QR_Generator.py: -------------------------------------------------------------------------------- 1 | import os 2 | import pyqrcode 3 | from PIL import Image 4 | 5 | class QR_Gen(object): 6 | def __init__(self, text): 7 | self.qr_image = self.qr_generator(text) 8 | 9 | @staticmethod 10 | def qr_generator(text): 11 | pyqrcode.create(text).png("temp.png", scale=10) 12 | image = Image.open("temp.png").resize((400,400),Image.ANTIALIAS) 13 | image.show() 14 | if os.path.exists("temp.png"): 15 | os.remove("temp.png") 16 | 17 | if __name__ == "__main__": 18 | QR_Gen(input("[QR] Enter text or link: ")) 19 | -------------------------------------------------------------------------------- /Modules/QrBarGenerator.py: -------------------------------------------------------------------------------- 1 | import os 2 | import io 3 | import pyqrcode 4 | from barcode import EAN13 5 | from barcode.writer import ImageWriter 6 | from PIL import Image 7 | 8 | class BarCode(object): 9 | def __init__(self, data): 10 | if len(data) == 12 and data.isdigit(): 11 | self.data = str(data) 12 | else: 13 | self.data = "123456789012" 14 | 15 | def generate(self): 16 | temp = io.BytesIO() 17 | EAN13(self.data, writer=ImageWriter()).write(temp) 18 | image = Image.open(temp).resize((400,400), Image.ANTIALIAS) 19 | image.show() 20 | 21 | class QrCode(object): 22 | def __init__(self, data): 23 | self.data = data 24 | 25 | def generate(self): 26 | pyqrcode.create(self.data).png("temp.png", scale=10) 27 | image = Image.open("temp.png").resize((400,400), Image.ANTIALIAS) 28 | image.show() 29 | if os.path.exists("temp.png"): 30 | os.remove("temp.png") 31 | 32 | if __name__ == "__main__": 33 | BarCode("123456789012").generate() 34 | QrCode("123456789012").generate() 35 | 36 | -------------------------------------------------------------------------------- /Modules/Screenshot.py: -------------------------------------------------------------------------------- 1 | import os 2 | import pyautogui 3 | 4 | 5 | def screenshot(): 6 | # Save screenshot to picture folder inside your home folder 7 | save_path = os.path.join(os.path.expanduser("~"), "Pictures") 8 | shot = pyautogui.screenshot() 9 | # Save screenshot in set save_path 10 | shot.save(f"{save_path}\\python_screenshot.png") 11 | return print(f"\nScreenshot taken, and saved to {save_path}") 12 | 13 | 14 | if __name__ == "__main__": 15 | screenshot() 16 | 17 | -------------------------------------------------------------------------------- /Modules/SimAnalyzer.py: -------------------------------------------------------------------------------- 1 | import os 2 | import json 3 | import phonenumbers 4 | from phonenumbers import carrier 5 | from phonenumbers import geocoder 6 | from tabulate import tabulate 7 | from urllib.request import urlopen 8 | 9 | class NumberAnalyzer(object): 10 | def __init__(self, number): 11 | self.number = phonenumbers.parse(number) 12 | self.url = "https://ipinfo.io/" 13 | 14 | def analyze(self): 15 | description = geocoder.description_for_number(self.number, "en") 16 | supplier = carrier.name_for_number(self.number, "en") 17 | response = urlopen(self.url) 18 | data = json.load(response) 19 | return [description, supplier, data] 20 | 21 | @property 22 | def parse_data(self): 23 | country, supplier, device = self.analyze() 24 | region = device["region"] 25 | city = device["city"] 26 | lat, lon = str(device["loc"]).split(",") 27 | location = f"Latitude: {lat}, Longtitude: {lon}" 28 | postal = device["postal"] 29 | timezone = device["timezone"] 30 | server = device["org"] 31 | hostname = device["hostname"] 32 | ip = device["ip"] 33 | return [["Country", country], ["Region", region], ["City", city], ["Location", location], 34 | ["Postal", postal], ["Timezone", timezone], ["Server", server], ["Hostname", hostname], 35 | ["Supplier", supplier], ["IP", ip]] 36 | 37 | def __str__(self): 38 | return str(f"\n{tabulate(self.parse_data)}") 39 | 40 | if __name__ == "__main__": 41 | os.system("cls") 42 | print("[ Simcard Analyzer - python_genius ]\n") 43 | number = input("Enter Number: ") 44 | analyze = NumberAnalyzer(number) 45 | print(analyze) 46 | -------------------------------------------------------------------------------- /Modules/Terminal_Art.py: -------------------------------------------------------------------------------- 1 | import os 2 | from pyfiglet import Figlet 3 | 4 | def print_cool(text): 5 | # Instance of Figlet with font setting at slant 6 | cool_text = Figlet(font="slant") 7 | # Clear the terminal window 8 | os.system("cls") 9 | # Set terminal window to a fixed size 10 | os.system('mode con: cols=75 lines=30') 11 | return str(cool_text.renderText(text)) 12 | 13 | if __name__ == "__main__": 14 | print(print_cool("Byte Sensei")) 15 | 16 | -------------------------------------------------------------------------------- /Modules/Translator.py: -------------------------------------------------------------------------------- 1 | import goslate 2 | 3 | 4 | def translator(sentance, language="en"): 5 | return goslate.Goslate().translate(sentance, language) 6 | 7 | 8 | if __name__ == "__main__": 9 | translation = translator("Follow bytesenseidk on Instagram!", "hi") 10 | print(translation) 11 | 12 | -------------------------------------------------------------------------------- /Modules/TurtleBasics.py: -------------------------------------------------------------------------------- 1 | import turtle 2 | import colorsys 3 | 4 | draw = turtle.Turtle() 5 | draw.speed(0.5) 6 | screen = turtle.Screen() 7 | screen.bgcolor('black') 8 | color_change = 256 9 | pos = 0 10 | 11 | for i in range(512): 12 | color = colorsys.hsv_to_rgb(pos, 1, 1) 13 | pos = pos + 1 / color_change 14 | draw.color(color) 15 | draw.forward(i ** 1.5) 16 | draw.left(145) 17 | 18 | -------------------------------------------------------------------------------- /Modules/WebcamActivation.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | camera = cv2.VideoCapture(0) # Selection of camera 5 | # video = cv2.VideoCapture("test_video.mp4") # Selection of video 6 | 7 | while True: 8 | # val: Validation of camera or video is available. 9 | # frame: The actual video or camera display in a numpy array. 10 | val, frame = camera.read() 11 | cv2.imshow("frame", frame) # Shows movie or video capture 12 | # Exit the video by pressing 'e' 13 | if cv2.waitKey(1) == ord("e"): 14 | break 15 | 16 | # Release the device from the program, making it available to the os again. 17 | camera.release() 18 | cv2.destroyAllWindows() # Terminates the video display 19 | -------------------------------------------------------------------------------- /Modules/ZipCompression.py: -------------------------------------------------------------------------------- 1 | import os 2 | from zipfile import ZipFile 3 | 4 | def zip_me(path): 5 | folder_name = path.split("\\")[-1] 6 | rel_path = path.strip(folder_name) 7 | # Change current working directory to folder 8 | os.chdir(rel_path) 9 | zip_file = ZipFile(f"{folder_name}.zip", "w") 10 | 11 | # Iterate through each file in each folder 12 | for root, dirs, files in os.walk(folder_name, topdown=False): 13 | # Files in sub-folders 14 | for name in files: 15 | file = os.path.join(root, name) 16 | zip_file.write(file) 17 | # Sub-folders in target folder 18 | for name in dirs: 19 | folders = os.path.join(root, name) 20 | zip_file.write(folders) 21 | 22 | zip_file.close() 23 | 24 | if __name__ == "__main__": 25 | path = input(r"Path to target folder: ") 26 | zip_me(path) 27 | 28 | -------------------------------------------------------------------------------- /Modules/matplotguide.py: -------------------------------------------------------------------------------- 1 | # Average temperature rise each month since 1880 2 | import numpy as np 3 | from matplotlib import pyplot as plt 4 | plt.style.use("ggplot") 5 | 6 | months = ["January", "February", "March", "April", "May", "June", "July", 7 | "August", "September", "October", "November", "December"] 8 | 9 | year_2016 = [1.17, 1.35, 1.3, 1.09, 0.93, 0.76, 0.83, 0.98, 0.87, 0.89, 0.93, 0.81] 10 | year_2015 = [0.81, 0.86, 0.9, 0.74, 0.78, 0.78, 0.71, 0.78 , 0.81, 1.06, 1.04, 1.1] 11 | year_2014 = [0.73, 0.51, 0.77, 0.78, 0.87, 0.66, 0.57, 0.82, 0.9, 0.85, 0.67, 0.79] 12 | year_2013 = [0.68, 0.55, 0.66, 0.52, 0.61, 0.65, 0.59, 0.66, 0.78, 0.69, 0.81, 0.67] 13 | 14 | for i, year in enumerate([year_2016, year_2015, year_2014, year_2013]): 15 | plt.plot(months, year, color=np.random.rand(3,), linestyle="-", label=str(int(2016 - i))) 16 | 17 | plt.xlabel("Months") 18 | plt.ylabel("Mean Temperature Rise") 19 | plt.title("Matplotlib Mean Temperature Illustration") 20 | plt.grid(True) 21 | plt.legend() 22 | plt.show() 23 | 24 | -------------------------------------------------------------------------------- /Modules/mp4ToMp3.py: -------------------------------------------------------------------------------- 1 | import os 2 | from moviepy.editor import * 3 | 4 | def video_to_sound(video_path): 5 | name = video_path.split("/")[-1] 6 | song_path = movie_path.strip(name) 7 | name = name.split(".")[0] 8 | video = VideoFileClip(os.path.join(movie_path)) 9 | video.audio.write_audiofile(os.path.join(f"{song_path}{name}.mp3")) 10 | 11 | if __name__ == "__main__": 12 | print("Drag 'n Drop Video Here:") 13 | movie_path = input(r" >> ").strip('"') 14 | video_to_sound(movie_path) 15 | 16 | -------------------------------------------------------------------------------- /Modules/play_song.py: -------------------------------------------------------------------------------- 1 | import os 2 | import pygame 3 | 4 | def play(song_path): 5 | song = song_path.split("/")[-1] 6 | rel_path = os.path.join(song_path.strip(song)) 7 | os.chdir(rel_path) 8 | print(rel_path) 9 | pygame.init() 10 | pygame.mixer.init() 11 | pygame.mixer.music.load(song) 12 | pygame.mixer.music.play() 13 | 14 | def stop(): 15 | pygame.mixer.music.stop() 16 | 17 | if __name__ == "__main__": 18 | print("Drag Song Here:") 19 | song = input(" >> ") 20 | play(song) 21 | 22 | -------------------------------------------------------------------------------- /Modules/tkinter_template.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | 3 | class Tkinter_Template(object): 4 | def __init__(self, master): 5 | frame = Frame(master) 6 | frame.grid() 7 | hello = Label(master, 8 | text="Follow python_genius on Instagram!", 9 | font=("Helvetica", 16)) 10 | hello.grid() 11 | 12 | if __name__ == '__main__': 13 | root = Tk() 14 | root.title("Tkinter Starter Template") 15 | root.geometry("350x50") 16 | Tkinter_Template(root) 17 | root.mainloop() 18 | 19 | -------------------------------------------------------------------------------- /Modules/web_scrape_guide.py: -------------------------------------------------------------------------------- 1 | # """ Web Scrape """ 2 | 3 | # import requests 4 | # from bs4 import BeautifulSoup 5 | 6 | 7 | # url = "https://www.google.com/search?q=bitcoin+price" 8 | 9 | # def print_website_code(url): 10 | # source = requests.get(url).text 11 | # soup = BeautifulSoup(source, "html.parser") 12 | # # part = soup.find("div", attrs={"class": "dDoNo ikb4Bb gsrt gzfeS"}).find("div", 13 | # # attrs={"class": "DFlfde SwHCTb"}).text 14 | # part = soup.find("div", class_="dDoNo ikb4Bb gsrt gzfeS").text 15 | # return part 16 | 17 | 18 | 19 | # # def print_website_part(url): 20 | # # source = requests.get(url).text 21 | # # soup = BeautifulSoup(source, "html.parser") 22 | # # print(soup.prettify()) 23 | # # """ Find the class of the part you wish """ 24 | # # part = soup.find("div", attrs={"class": "BNeawe s3v9rd AP7Wnd"}).find("div", 25 | # # attrs={"class": "BNeawe s3v9rd AP7Wnd"}).text 26 | # # print(part) 27 | 28 | # # print_website_part(url) 29 | 30 | # print(print_website_code(url)) 31 | 32 | # #
Your Browser: {useragent}
" 22 | 23 | @app.route("/cookie") 24 | def cookie(): 25 | response = make_response("9 | This website is just a simple demo website 10 | for me to train my front-end development. 11 |
12 |