├── .gitignore ├── README.md ├── _config.yml ├── section-01-introduction-the-course └── README.md ├── section-02-basic-python-concepts ├── README.md ├── add-to-path.png ├── open-idle.png └── run-idle.png ├── section-03-control-structures-in-python ├── README.md ├── coding-challenge-2.py └── coding-challenge-3.py ├── section-04-functions-and-modules-in-python ├── README.md └── coding-challenge-4.py ├── section-05-exception-handling-&-file-handling-in-python ├── README.md ├── coding-challenge-5.py ├── coding-challenge-6.py └── khoa.txt ├── section-06-some-more-types-in-python ├── README.md ├── coding-challenge-7.py └── coding-challenge-8.py ├── section-07-functional-programming-in-python ├── README.md ├── coding-challenge-10.py ├── coding-challenge-11.py └── coding-challenge-9.py ├── section-08-object-oriented-programming-in-python ├── README.md ├── biniary-operator.png ├── coding-challenge-12.py ├── coding-challenge-13.py └── comparsion-operator.png ├── section-09-regular-expressions-in-python └── README.md ├── section-10-create-gui-apps-in-python-using-tkinter ├── README.md ├── demo-1.png ├── demo-1.py ├── demo-10.png ├── demo-10.py ├── demo-11.png ├── demo-11.py ├── demo-12.png ├── demo-12.py ├── demo-2.png ├── demo-2.py ├── demo-3.png ├── demo-3.py ├── demo-4.png ├── demo-4.py ├── demo-5(2).png ├── demo-5.png ├── demo-5.py ├── demo-6.png ├── demo-6.py ├── demo-7.png ├── demo-7.py ├── demo-8.png ├── demo-8.py ├── demo-9.png └── demo-9.py ├── section-11-build-calculator-app-using-tkinter ├── README.md ├── my-app.py ├── result-1.png ├── result-2.png ├── result-3.png ├── result-4.png ├── solution.py ├── test-1.png ├── test-2.png ├── test-3.png └── test-4.png ├── section-12-building-database-apps-with-postgreSQL-and-python ├── .gitignore ├── README.md ├── app.py ├── config.py ├── create-table.py ├── database.ini ├── image │ ├── step-1.png │ ├── step-10.png │ ├── step-11.png │ ├── step-12.png │ ├── step-13.png │ ├── step-14.png │ ├── step-15.png │ ├── step-16.png │ ├── step-17.png │ ├── step-18.png │ ├── step-19.png │ ├── step-2.png │ ├── step-20.png │ ├── step-21.png │ ├── step-22.png │ ├── step-23.png │ ├── step-24.png │ ├── step-25.png │ ├── step-26.png │ ├── step-27.png │ ├── step-28.png │ ├── step-29.png │ ├── step-3.png │ ├── step-30.png │ ├── step-31.png │ ├── step-32.png │ ├── step-4.png │ ├── step-5.png │ ├── step-6.png │ ├── step-7.png │ ├── step-8.png │ └── step-9.png ├── insert.py └── python-postgresql.py ├── section-13-data-analysis-using-python ├── README.md ├── image │ ├── image-1.png │ ├── image-10.png │ ├── image-11.png │ ├── image-12.png │ ├── image-13.png │ ├── image-14.png │ ├── image-15.png │ ├── image-16.png │ ├── image-17.png │ ├── image-18.png │ ├── image-19.png │ ├── image-2.png │ ├── image-20.png │ ├── image-21.png │ ├── image-22.png │ ├── image-23.png │ ├── image-24.png │ ├── image-25.png │ ├── image-26.png │ ├── image-27.png │ ├── image-28.png │ ├── image-29.png │ ├── image-3.png │ ├── image-30.png │ ├── image-31.png │ ├── image-32.png │ ├── image-33.png │ ├── image-34.png │ ├── image-35.png │ ├── image-36.png │ ├── image-37.png │ ├── image-38.png │ ├── image-39.png │ ├── image-4.png │ ├── image-40.png │ ├── image-41.png │ ├── image-42.png │ ├── image-43.png │ ├── image-44.png │ ├── image-45.png │ ├── image-46.png │ ├── image-47.png │ ├── image-48.png │ ├── image-49.png │ ├── image-5.png │ ├── image-50.png │ ├── image-51.png │ ├── image-52.png │ ├── image-53.png │ ├── image-54.png │ ├── image-55.png │ ├── image-56.png │ ├── image-57.png │ ├── image-58.png │ ├── image-59.png │ ├── image-6.png │ ├── image-60.png │ ├── image-61.png │ ├── image-62.png │ ├── image-63.png │ ├── image-64.png │ ├── image-65.png │ ├── image-66.png │ ├── image-67.png │ ├── image-68.png │ ├── image-69.png │ ├── image-7.png │ ├── image-70.png │ ├── image-71.png │ ├── image-72.png │ ├── image-73.png │ ├── image-74.png │ ├── image-75.png │ ├── image-76.png │ ├── image-77.png │ ├── image-78.png │ ├── image-79.png │ ├── image-8.png │ └── image-9.png └── sales.csv ├── section-14-make-web-applications-in-python-using-django ├── README.md ├── image │ ├── step-1.png │ ├── step-10.png │ ├── step-11.png │ ├── step-12.png │ ├── step-13.png │ ├── step-14.png │ ├── step-15.png │ ├── step-16.png │ ├── step-17.png │ ├── step-18.png │ ├── step-19.png │ ├── step-2.png │ ├── step-20.png │ ├── step-21.png │ ├── step-22.png │ ├── step-3.png │ ├── step-4.png │ ├── step-5.png │ ├── step-6.png │ ├── step-7.png │ ├── step-8.png │ └── step-9.png ├── source.txt └── web-section-14 │ ├── .gitignore │ └── mysite │ ├── books │ ├── __init__.py │ ├── admin.py │ ├── apps.py │ ├── models.py │ ├── tests.py │ ├── urls.py │ └── views.py │ ├── manage.py │ ├── mysite │ ├── __init__.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py │ ├── static │ └── books │ │ ├── back.jpg │ │ ├── khoa.png │ │ ├── purple.png │ │ ├── style.css │ │ └── yellow.jpg │ └── templates │ └── books │ ├── base.html │ ├── book_form.html │ ├── detail.html │ ├── form-template.html │ └── index.html ├── section-15-make-web-applications-with-python-using-django-2.0 ├── .gitignore ├── README.md ├── image │ ├── image-1.png │ ├── image-2.png │ ├── image-3.png │ └── image-4.png └── photo-project │ ├── manage.py │ ├── photo │ ├── __init__.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py │ └── photoapp │ ├── __init__.py │ ├── admin.py │ ├── apps.py │ ├── models.py │ ├── static │ └── photoapp │ │ ├── back-ground.jpg │ │ └── style.css │ ├── templates │ └── photoapp │ │ ├── detail.html │ │ └── index.html │ ├── tests.py │ ├── urls.py │ └── views.py ├── section-17-building-rest-api's-with-python-and-django ├── README.md ├── apidemo │ ├── apidemo │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-36.pyc │ │ │ ├── settings.cpython-36.pyc │ │ │ ├── urls.cpython-36.pyc │ │ │ └── wsgi.cpython-36.pyc │ │ ├── settings.py │ │ ├── urls.py │ │ └── wsgi.py │ ├── app │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-36.pyc │ │ │ ├── admin.cpython-36.pyc │ │ │ ├── models.cpython-36.pyc │ │ │ ├── serializers.cpython-36.pyc │ │ │ └── views.cpython-36.pyc │ │ ├── admin.py │ │ ├── apps.py │ │ ├── models.py │ │ ├── serializers.py │ │ ├── tests.py │ │ └── views.py │ ├── manage.py │ └── media │ │ └── Images │ │ ├── image-3.jpg │ │ └── image9.png └── image │ ├── image-1.png │ ├── image-2.png │ ├── image-3.png │ ├── image-4.png │ ├── image-5.png │ ├── image-6.png │ └── image-7.png ├── section-18-learn-how-to-crawl-websites-using-python-web-crawling ├── README.md ├── demo.py ├── domain.py ├── image │ ├── image-1.png │ └── image-2.png ├── link_finder.py ├── main.py ├── spider.py └── thesite │ ├── crawled.txt │ └── queue.txt ├── section-19-complex-python-challenges ├── README.md ├── challenge-7.py ├── code │ ├── challenge-1-1.py │ ├── challenge-1-2.py │ ├── challenge-2-1.py │ ├── challenge-2-2.py │ ├── challenge-3.py │ ├── challenge-4.py │ └── challenge-8.py └── image │ ├── image-1.png │ ├── image-2.png │ ├── image-3.png │ ├── image-4.png │ ├── image-5.png │ ├── image-6.png │ ├── image-7.png │ └── image-8.png ├── section-20-automation-with-selenium-web-driver-and-python ├── README.md └── image │ └── image-1.png ├── section-21-building-a-facebook-auto-poster └── README.md ├── section-22-python-best-practices-writing-clean-and-efficient-python-code └── README.md └── section-23-network-programming-in-python-using-sockets-building-a-chat-application └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | _pycache_/ 2 | db.sqlite3 3 | migrations/ -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /section-01-introduction-the-course/README.md: -------------------------------------------------------------------------------- 1 | # Section 01: Introduction to the course 2 | ## Course Overview 3 | - **Instructor:** [Ashutosh Pawar Entrepreneur](https://www.udemy.com/user/a9ff8aeb-0700-4b60-950d-ffdce7bf69bc/) 4 | 5 | ### What is Python ? 6 | - Python is a high-level object-oriented programming language used to develop websites and many other applications. 7 | - With extremely simple and elegant syntax, Python is the perfect choice for those first learning programming. 8 | 9 | - Python is increasingly proving its advantage in building and deploying many different types of applications such as web applications, desktop applications, statistical analysis, Machine Leaning, Deep Learning, etc. It is fast, powerful, user-friendly, enforceable, and completely free. 10 | 11 | ### What need to know before get started 12 | 13 | Basic knowledge of: 14 | - If you don't have knowledge , the course teaches you to start over 15 | - Computer Skill (Type the text , open file , dowload file , using Command line) 16 | - Listening skill 17 | ### Course structure 18 | - Section 1: Python. 19 | - Section 2: Make GUI In Python Using Tkinter. 20 | - Section 3: Making Database Oriented Desktop Apps With PostgreSQL. 21 | - Section 4: Data Analysis. 22 | - Section 5: Python Web Framework Django. 23 | - Section 6: Python Web Framework Flask. 24 | - Section 7: REST APIs Using Django Rest Framework. 25 | - Section 8: Web Scraping in Python. 26 | - Section 9: Automation with Python & Selenium. 27 | - Section 10: Best Practices: Writing Clean & Efficient Python Code. 28 | - Section 11: Image Processing With Python & OpenCV. 29 | 30 | ## The Big Picture 31 | In this hands-on course, you will learn Python right starting from scratch to the level where you can build almost anything with it, be it a fully functional database oriented web application or an automation tool. 32 | 33 | This course will teach you Python right from scratch from a very basic level and will gradually move you towards more advanced topics. 34 | 35 | We not just cover all the Python basics but also the most popular Python libraries such as Django, Flask, Tkinter & Selenium. -------------------------------------------------------------------------------- /section-02-basic-python-concepts/add-to-path.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-02-basic-python-concepts/add-to-path.png -------------------------------------------------------------------------------- /section-02-basic-python-concepts/open-idle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-02-basic-python-concepts/open-idle.png -------------------------------------------------------------------------------- /section-02-basic-python-concepts/run-idle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-02-basic-python-concepts/run-idle.png -------------------------------------------------------------------------------- /section-03-control-structures-in-python/coding-challenge-2.py: -------------------------------------------------------------------------------- 1 | faorite_foods = ['Bún Đậu','Bún Mắm','Bún Ngan','Bún Bò','Bún Chả'] 2 | print(faorite_foods[2]) 3 | faorite_foods.append('Bún Thịt Nướng') 4 | print(faorite_foods) 5 | faorite_foods.insert(3, "Bún Cá") 6 | print(faorite_foods) 7 | -------------------------------------------------------------------------------- /section-03-control-structures-in-python/coding-challenge-3.py: -------------------------------------------------------------------------------- 1 | for i in range(0,5): 2 | print('I am a programmer') 3 | 4 | def display_square(): 5 | for x in range(1,10): 6 | print(x*x) 7 | display_square() -------------------------------------------------------------------------------- /section-04-functions-and-modules-in-python/coding-challenge-4.py: -------------------------------------------------------------------------------- 1 | def cal_BMI(new_weight, new_height): 2 | new_bmi = new_weight/(pow(new_height, 2)) 3 | return new_bmi 4 | 5 | weight = float(input('Enter weight in Kgs')) 6 | height = float(input('Enter height in meters')) 7 | bmi = cal_BMI(weight, height) 8 | print(bmi) -------------------------------------------------------------------------------- /section-05-exception-handling-&-file-handling-in-python/README.md: -------------------------------------------------------------------------------- 1 | # Section 05: Learn Exception Handling & File Handling In Python 2 | ## Lesson overview 3 | - Errors and Exceptions: 4 | - Exceptions 5 | - The try statement works as follows 6 | - File handling in python 7 | - The open Function 8 | - Syntax 9 | ### Errors & exceptions in Python 10 | - The exception is errors that may arise during program execution. 11 | - Access variable does not exist 12 | - Open file does not exist 13 | - Converts an invalid string to a number 14 | - Access exceeds the index of the List 15 | - Key access does not exist in Dictionary 16 | - ... 17 | - When an error occurs, if not handled, Python will issue an error message and stop the program. 18 | - Example : 19 | ``` 20 | print(int('a')) 21 | ``` 22 | The above program, when running, will give the following notice: 23 | ```diff 24 | - ValueError: invalid literal for int() with base 10: 'a' 25 | ``` 26 | 27 | ### Exception handling in Python 28 | - How to handle exceptions in Python: 29 | ``` 30 | try: 31 | # do something 32 | except: 33 | print("Exception occurred") 34 | ``` 35 | - When an exception occurs, the program will run into the block below the except: line, then the next segment of the try / except block will continue to execute. 36 | - To handle each exception exception individually, the exception type can be specified in the except declaration 37 | ``` 38 | try: 39 | # do something 40 | except ErrorType1: 41 | print("Error type 1") 42 | except ErrorType2: 43 | print("Error type 2") 44 | except: 45 | print("Other exception") 46 | ``` 47 | Example 48 | ``` 49 | try: 50 | x = int('a') 51 | except ValueError: 52 | print("Invalid input number") 53 | except: 54 | print("Other exception") 55 | ``` 56 | 57 | ### Finally block 58 | - In case you want to perform an action after finishing a job regardless of the exception that occurred during the execution of that job, the structure can be used: 59 | ``` 60 | try: 61 | # do something 62 | except: 63 | print("Exception occurred") 64 | finally: 65 | print('After try/except finished') 66 | ``` 67 | ### File handling 68 | - Open file in Python : 69 | ``` 70 | f = open (, , encoding = ) 71 | ``` 72 | - Inside : 73 | - : the file name to open 74 | - mode: File open mode, commonly used values: 75 | - 'r': Open file for reading, this is the default value 76 | - 'rb': Open file for reading in binary format 77 | - 'w': Create a new file for writing 78 | - 'wb': Create a new file for writing in binary format 79 | - 'a': Open file for appending (append) 80 | - 'ab': Open the file to add the end of it in binary format 81 | 82 | - encoding: Encoding mode with text file 83 | - None: the default value, depending on the system 84 | - 'utf-8': Unicode encoding in UTF-8 85 | ### Reading data from file 86 | - Read the entire file content: 87 | ``` 88 | data = f.read () 89 | ``` 90 | If the file is opened in text mode ('r'), the file reading is a string variable. If the file is opened in binary mode ('rb'), the file read result is a variable with a data type of bytes. 91 | - Read the entire lines of the file (with text files): 92 | If the file is opened in text mode ('r'), the file contents can be read line by line with the command: 93 | ``` 94 | lines = f.readlines () 95 | ``` 96 | The result is a List, each element is a string containing the contents of the file's lines 97 | - Read each line of the file: 98 | If the file is opened in text mode ('r'), it is possible to read file by line with the structure: 99 | ``` 100 | for line in f: 101 | # process line 102 | ``` 103 | ### Adding data to the file 104 | - For text files, the data to write to the file requires a string type 105 | ``` 106 | f.write () 107 | ``` 108 | For example: 109 | ``` 110 | f = open ('test.txt', 'w') 111 | f.write ('hello') 112 | f.close () 113 | ``` 114 | 115 | - For binary files, the data written to the file needs to be of type bytes 116 | ``` 117 | f.write () 118 | ``` 119 | For example: 120 | ``` 121 | f = open ('test.dat', 'wb') 122 | f.write ('hello'.encode ()) 123 | f.close () 124 | ``` 125 | ### Appending to a file 126 | - After opening the file with the open command, close the file with the close command to avoid missing the file contents at the end of the program. To avoid forgetting to close the file after opening, you can use the with structure: 127 | ``` 128 | with open (, , ) as f: 129 | # Process file 130 | ``` 131 | - With the with structure, the file is automatically closed when the program has finished running the block inside the with. 132 | For example: 133 | ``` 134 | with open ('test.txt', 'w') as f: 135 | f.write ('Line1 \ n') 136 | f.write ('Line2 \ n') 137 | ``` 138 | ### Quiz 4: Quiz For Section 5: 139 | - The code in the finally block is executed: No matter if the exception occurs or not 140 | - Appending to a file: Keeps previous contents of the file 141 | - Writing data to the file: Removes/ discards previous contents 142 | - Following blocks can be used to accept exceptions: Both try and except block 143 | ### Coding challenge 5 144 | - Write a function which would divide two numbers, design the function in a manner that it handles the divide by zero exception. 145 | ### Coding challenge 5 solution 146 | ``` 147 | def divide(a,b): 148 | try: 149 | return a/b 150 | except ZeroDivisionError: 151 | print("There is a divide by zero error") 152 | return 0 153 | 154 | x = float(input('Enter a number')) 155 | y = float(input('Enter value by which you want to divide the number')) 156 | result = divide(x, y) 157 | print(result) 158 | ``` 159 | ### Coding challenge 6 160 | - Write Python code to open a file named demo.txt and write some random data into it. 161 | 162 | - Open the file, read the contents and display them as output. 163 | 164 | - Write python code to add additional text to the existing file on a new line without deleting the previous contents. 165 | ### Coding challenge 6 solution 166 | ``` 167 | f= open('demo.txt', 'w') 168 | f.write("hello there") 169 | f.close() 170 | 171 | #reading data from the file 172 | 173 | f= open('demo.txt','r') 174 | print(f.read()) 175 | f.close() 176 | 177 | #adding additional contents 178 | 179 | f= open('demo.txt','a') 180 | f.write('\n Hello again') 181 | f.close() 182 | ``` 183 | ### Notes & Summary For Section 5 -------------------------------------------------------------------------------- /section-05-exception-handling-&-file-handling-in-python/coding-challenge-5.py: -------------------------------------------------------------------------------- 1 | def div_num(a,b): 2 | try: 3 | return a//b 4 | print(div_num(2,0)) 5 | except BaseException as be: 6 | print('[Error]',be) 7 | finally: 8 | print('After try/except finished') -------------------------------------------------------------------------------- /section-05-exception-handling-&-file-handling-in-python/coding-challenge-6.py: -------------------------------------------------------------------------------- 1 | def read(input_file): 2 | file_name = input_file 3 | try: 4 | f = open(file_name,'r') 5 | read_file = f.read() 6 | print(read_file) 7 | f.close() 8 | except Exception as e: 9 | print(type(e),e) 10 | 11 | 12 | def write(input_file): 13 | file_name = input_file 14 | try: 15 | f =open(file_name,'w') 16 | replace = input("Text Here : ") 17 | f.write(replace) 18 | except Exception as e: 19 | print(type(e),e) 20 | 21 | def write_next_text(input_file): 22 | file_name = input_file 23 | try: 24 | f =open(file_name,'a') 25 | replace = input("Text Here : ") 26 | f.write(replace) 27 | except Exception as e: 28 | print(type(e),e) 29 | 30 | 31 | 32 | write_next_text('..\khoa.txt') 33 | # write('/../khoa.txt') 34 | read('..\khoa.txt') 35 | 36 | # read('/../khoa.txt') -------------------------------------------------------------------------------- /section-05-exception-handling-&-file-handling-in-python/khoa.txt: -------------------------------------------------------------------------------- 1 | Khoa 2 | -------------------------------------------------------------------------------- /section-06-some-more-types-in-python/coding-challenge-7.py: -------------------------------------------------------------------------------- 1 | product = { 2 | 'Meat':30, 3 | 'Fish':25, 4 | 'Noodle':45, 5 | 'Vegetable':30, 6 | 'Egg':10 7 | } 8 | 9 | new_pro = input('Enter the Name : ') 10 | if new_pro in product: 11 | print(product.get(new_pro)) 12 | else: 13 | print('No Found') -------------------------------------------------------------------------------- /section-06-some-more-types-in-python/coding-challenge-8.py: -------------------------------------------------------------------------------- 1 | odd_list = [x for x in range(1,100) if x % 2 == 1] 2 | print(odd_list) -------------------------------------------------------------------------------- /section-07-functional-programming-in-python/README.md: -------------------------------------------------------------------------------- 1 | # Section 07: Functional Programming in Python 2 | ## Lesson overview 3 | - Functional programming in python 4 | - Lambdas in Python 5 | - The map() Function 6 | - Filtering 7 | ### Functional programming 8 | - Functional programming is a programming paradigm in which we try to bind everything in pure mathematical functions style. 9 | - It is a declarative type of programming style. 10 | - Its main focus is on “what to solve” in contrast to an imperative style where the main focus is “how to solve“. 11 | - It uses expressions instead of statements. 12 | - An expression is evaluated to produce a value whereas a statement is executed to assign variables. 13 | - Python too supports Functional Programming paradigms without the support of any special features or libraries. 14 | Pure Functions 15 | - As Discussed above, pure functions have two properties. 16 | - It always produces the same output for the same arguments. For example, 3+7 will always be 10 no matter what. 17 | - It does not change or modifies the input variable. 18 | 19 | Example: 20 | ``` 21 | def pure_func(List): 22 | New_List = [] 23 | for i in List: 24 | New_List.append(i**2) 25 | return New_List 26 | Original_List = [1, 2, 3, 4] 27 | Modified_List = pure_func(Original_List) 28 | print("Original List:", Original_List) 29 | print("Modified List:", Modified_List) 30 | ``` 31 | Output: 32 | ``` 33 | Original List: [1, 2, 3, 4] 34 | Modified List: [1, 4, 9, 16] 35 | ``` 36 | ### Lambdas in Python 37 | - A lambda function is a small anonymous function. 38 | - A lambda function can take any number of arguments, but can only have one expression. 39 | - Syntax : ```lambda arguments : expression``` 40 | - The expression is executed and the result is returned 41 | - Example: 42 | ``` 43 | x = lambda a : a + 10 44 | print(x(5)) 45 | ``` 46 | 47 | ### Map in Python 48 | - The map() function executes a specified function for each item in a iterable. The item is sent to the function as a parameter. 49 | - Syntax : ```map(function, iterables)``` 50 | Example: 51 | ``` 52 | list_old = [10, 9, 8, 7, 6, 1, 2, 3, 4, 5] 53 | list_new = list(map(lambda a: a*2 , list_old)) 54 | print(list_old) 55 | ``` 56 | Output: 57 | ``` 58 | [20, 18, 16, 14, 12, 2, 4, 6, 8, 10] 59 | ``` 60 | ### Filters in Python 61 | - The filter() function returns an iterator were the items are filtered through a function to test if the item is accepted or not. 62 | - Syntax : ```filter(function, iterable)``` 63 | Example: 64 | ``` 65 | ages = [5, 12, 17, 18, 24, 32] 66 | def myFunc(x): 67 | if x < 18: 68 | return False 69 | else: 70 | return True 71 | adults = filter(myFunc, ages) 72 | for x in adults: 73 | print(x) 74 | ``` 75 | Output: 76 | ``` 77 | 18 78 | 24 79 | 32 80 | ``` 81 | ### Generators in Python 82 | - Generator is a great means to create an infinite stream of data. These infinite streams do not need to be stored entirely in memory because the generator only generates one element at a time, so it can represent infinite data flow. 83 | ``` 84 | def all_even(): 85 | n = 0f 86 | while True: 87 | yield n 88 | n += 2 89 | ``` 90 | ### Coding challenge 9 91 | - Assume you want to build two functions for discounting products on a website. 92 | - Function number 1 is for student discount which discounts the current price to 10%. 93 | - Function number 2 is for additional discount for regular buyers which discounts an additional 5% on the current student discounted price. 94 | - Depending on the situation, we want to be able to apply both the discounts on the products. 95 | 96 | Design the above two mentioned functions and apply them both simultaneously on the price. 97 | ### Coding challenge 9 solution 98 | ``` 99 | def student_discount(price): 100 | price = price - (price * 10) / 100 101 | return price 102 | 103 | def additional_discount(newprice): 104 | newprice = newprice - (newprice * 5) / 100 105 | return newprice 106 | 107 | selling_price = 100 108 | 109 | #applying both discounts simultaneously 110 | 111 | print(additional_discount(student_discount(selling_price))) 112 | ``` 113 | ### Coding challenge 10 114 | - Calculate the value of mathematical expression x*(x+5)^2 where x= 5 using lambda expression. 115 | ### Coding challenge 10 solution 116 | ``` 117 | result = (lambda x: x*(x+5)**2)(5) 118 | print(result) 119 | ``` 120 | ### Coding challenge 11 121 | - Consider a list in Python which includes prices of all the items in a store. 122 | - Build a function to discount the price of all the products by 10%. 123 | - Use map to apply the function to all the elements of the list so that all the product prices are discounted 124 | ### Coding challenge 11 solution 125 | ``` 126 | def discount(price): 127 | price = price - (price * 10) / 100 128 | return price 129 | 130 | product_prices = [100, 200, 300, 400, 500] 131 | 132 | updated_prices = list(map(discount,product_prices)) 133 | 134 | print(updated_prices) 135 | ``` 136 | 137 | -------------------------------------------------------------------------------- /section-07-functional-programming-in-python/coding-challenge-10.py: -------------------------------------------------------------------------------- 1 | x = lambda x : x*(x+5)**2 2 | print(x(5)) -------------------------------------------------------------------------------- /section-07-functional-programming-in-python/coding-challenge-11.py: -------------------------------------------------------------------------------- 1 | x =list(x for x in range(10,20) if x % 2 == 0) 2 | print(x) 3 | def dis_cout(price): 4 | return price - (price * 10) / 100 5 | new_price = map(dis_cout,x) 6 | print(list(new_price)) -------------------------------------------------------------------------------- /section-07-functional-programming-in-python/coding-challenge-9.py: -------------------------------------------------------------------------------- 1 | def student_discount(price): 2 | price = price - (price * 10) / 100 3 | return price 4 | 5 | def additional_discount(newprice): 6 | newprice = newprice - (newprice * 5) / 100 7 | return newprice 8 | 9 | selling_price = 100 10 | print(additional_discount(student_discount(selling_price))) -------------------------------------------------------------------------------- /section-08-object-oriented-programming-in-python/biniary-operator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-08-object-oriented-programming-in-python/biniary-operator.png -------------------------------------------------------------------------------- /section-08-object-oriented-programming-in-python/coding-challenge-12.py: -------------------------------------------------------------------------------- 1 | class Computer: 2 | 3 | 4 | def __init__(self,price,brand): 5 | self.price = price 6 | self.brand = brand 7 | 8 | def getspecs(self): 9 | self.price = input('Enter the price: ') 10 | self.brand = input('Enter the brand: ') 11 | def displayspec(self): 12 | print(self.price) 13 | print(self.brand) 14 | class Desktop(Computer): 15 | 16 | 17 | def __init__(self, price, brand,location): 18 | super().__init__(price, brand) 19 | self.location = location 20 | 21 | def getspecs(self): 22 | super().getspecs() 23 | self.location = input('Enter the location') 24 | def displayspec(self): 25 | super().displayspec() 26 | print(self.location) 27 | class Laptop(Computer): 28 | 29 | 30 | def __init__(self, price, brand,batery): 31 | super().__init__(price, brand) 32 | self.batery = batery 33 | 34 | def getspecs(self): 35 | super().getspecs() 36 | self.batery = input('Enter the batery') 37 | def displayspec(self): 38 | super().displayspec() 39 | print(self.batery) 40 | desktop_1 = Desktop(0,'','') 41 | desktop_1.getspecs() 42 | desktop_1.displayspec() 43 | 44 | laptop_1 = Laptop(0,'','') 45 | laptop_1.getspecs() 46 | laptop_1.displayspec() 47 | -------------------------------------------------------------------------------- /section-08-object-oriented-programming-in-python/coding-challenge-13.py: -------------------------------------------------------------------------------- 1 | class Number: 2 | 3 | def __init__(self,num): 4 | self.num = num 5 | 6 | def __mul__(self,other): 7 | return self.num + other.num 8 | 9 | num_1 = Number(3) 10 | num_2 = Number(4) 11 | print(num_1 * num_2) -------------------------------------------------------------------------------- /section-08-object-oriented-programming-in-python/comparsion-operator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-08-object-oriented-programming-in-python/comparsion-operator.png -------------------------------------------------------------------------------- /section-09-regular-expressions-in-python/README.md: -------------------------------------------------------------------------------- 1 | # Section 09: Regular expressions in Python 2 | ## Lesson overview 3 | - Pattern syntax used in RegEx Python 4 | - Match object 5 | - Use the prefix r before RegEx 6 | ### Regular expressions in Python 7 | - Regular Expression (RegEx), also known as a regular expression, is a sequence of special characters that follow certain patterns, representing a string or a set of strings. 8 | ``` 9 | ^a...s$ 10 | ``` 11 | - match():This function attempts to match RE *pattern* to *string* with optional flags. 12 | - Syntax: ```re.match(pattern, string, flags=0)``` 13 | - ```pattern```: This is the regular expression to be matched. 14 | - ``string``: This is the string, which would be searched to match the pattern at the beginning of string 15 | - ``flags``: You can specify different flags using bitwise OR (|). These are modifiers, which are listed in the table belo 16 | Example: 17 | ``` 18 | import re 19 | 20 | pattern = '^a...s$' 21 | test_string = 'abyss' 22 | result = re.match(pattern, test_string) 23 | 24 | if result: 25 | print("Match Successfully.") 26 | else: 27 | print("Can't match.") 28 | ``` 29 | Output 30 | ``` 31 | Match Successfully. 32 | ``` 33 | ### Search & find all 34 | - re.search(): This function searches for first occurrence of RE pattern within string with optional flags. 35 | - Syntax: ```re.search(pattern, string, flags=0)``` 36 | - ```pattern```: This is the regular expression to be matched. 37 | - ```string```: This is the string, which would be searched to match the pattern anywhere in the string. 38 | - ```flags```: You can specify different flags using bitwise OR (|). These are modifiers, which are listed in the table below. 39 | ``` 40 | import re 41 | 42 | string = "Khoa live in Ha Noi" 43 | 44 | # Check 'Khoa' is it at the beginning of the string 45 | match = re.search('\AKhoa', string) 46 | 47 | if match: 48 | print("Found 'Khoa' is located at the top string") 49 | else: 50 | print("Not found Khoa is located at the top string") 51 | ``` 52 | Output 53 | ``` 54 | Found 'Khoa' is located at the top string 55 | ``` 56 | - The re.findall () method returns a list of strings containing all results that match the given pattern. 57 | - Syntax: ```findall(partern, string)``` 58 | - The ```pattern``` is RegEx. 59 | - ```string``` is the string to match. 60 | Example:Extract numbers from the following given string: "hello 12 hi 89. Howdy 34" 61 | ``` 62 | import re 63 | 64 | string = 'hello 12 hi 89. Howdy 34' 65 | pattern = '\d+' 66 | 67 | result = re.findall(pattern, string) 68 | print(result) 69 | ``` 70 | Output 71 | ``` 72 | ['12', '89', '34'] 73 | ``` 74 | ### Find & replace 75 | - re.sub(): This is one of the most important methods used with Regular Expression 76 | - re.sub () will replace all results that match the pattern in the string with another content passed in and return the modified string. 77 | - Syntax: ```re.sub(pattern, replace, string, count)``` 78 | - The ```pattern```is RegEx. 79 | - ```replace``` is the replacement for the result string that matches the pattern. 80 | - ```string``` is the string to match. 81 | - ```count (integer)``` is the number of replacements. If left blank, Python will treat this value as 0, matching and replacing all strings that meet the criteria. 82 | Example: The program deletes all spaces 83 | ``` 84 | import re 85 | 86 | string = 'abc 12\ 87 | de 23 \n f45 6' 88 | 89 | pattern = '\s+' 90 | 91 | replace = '' 92 | 93 | new_string = re.sub(pattern, replace, string) 94 | print(new_string) 95 | ``` 96 | Output 97 | ``` 98 | abc12de23f456 99 | ``` 100 | ### The dot metacharacter 101 | - The dot ``.`` matches any regular single character except the newline character '\ n'. 102 | Example: 103 | Expression|Example string|Description 104 | |---------|--------------|-----------| 105 | | |```a``` |Does not match because there is only one character| 106 | |``..`` |```ac``` |Matches because there are two characters| 107 | | |```acd``` |Matches because there are two or more characters| 108 | 109 | ### Caret & dollar metacharacter 110 | - Caret: ``^`` is used to match the beginning of a string. 111 | Example: 112 | Expression|Example string|Description 113 | |---------|--------------|-----------| 114 | | |```a``` |Match because starting with ``a``| 115 | |``^a`` |```abc``` |Match because starting with ``a``| 116 | | |```bac``` |Does not match because ``a`` is not in the first| 117 | - Dollar: ``$`` is used to match the end of a string. 118 | Example: 119 | Expression|Example string|Description 120 | |---------|--------------|-----------| 121 | | |```a``` |Match because ending with ``a``| 122 | |``$a`` |```formula``` |Match because ending with ``a``| 123 | | |```cab``` |Does not match because ``a`` is not in the final| 124 | ### Character class 125 | - The square brackets ``[]``are used to represent the set of characters you want to match. 126 | Example: 127 | Expression|Example string|Description 128 | |---------|--------------|-----------| 129 | | | ``a`` |Match because with ``a``| 130 | |``[abc]``|``ac`` |Match because with ``a``| 131 | | |``Hey Jude`` |Does not match | 132 | - Here, ``[abc]`` will match if the string you pass contains any of the letters ``a``, ``b`` or ``c``. 133 | - You can also specify a range of characters using - within the brackets 134 | - ``[a-e]`` is similar to ``[abcde]``. 135 | - ``[1-4]`` similar to ``[1234]``. 136 | - ``[0-39]`` similar to ``[01239]``. 137 | ### Star metacharacter 138 | - The asterisk symbol ``*`` can match a string with or without the character defined before it. This character can be repeated many times without quantity restriction. 139 | Example: 140 | Expression|Example string|Description 141 | |---------|--------------|-----------| 142 | | | ``mn`` |Matches because the preceding * character may not appear| 143 | | |``man`` |Matches because they appear full of characters| 144 | |``ma*n`` |``maaaan`` |Matches because the preceding * character may appear more than once| 145 | | |``main`` |Mismatch because unlike pattern, n does not lie next to a| 146 | | |``woman`` |Matches because they appear full of characters| 147 | ### Group 148 | - match.group (): The group () method returns parts of the string that match the pattern. 149 | ``` 150 | import re string = '39801 356, 2102 1111' pattern = '(\d{3}) (\d{2})' 151 | 152 | match = re.search(pattern, string) 153 | 154 | if match: 155 | print(match.group()) 156 | else: 157 | print("No match") 158 | ``` 159 | Output: 160 | ``` 161 | 801 35 162 | ``` 163 | Here, the match variable contains the match object. 164 | 165 | We have pattern (\ d {3}) (\ d {2}) divided into two small groups (\ d {3}) and (\ d {2}). You can get part of the string corresponding to the subgroups in this parenthesis as follows: 166 | ``` 167 | >>> match.group(1) 168 | '801' 169 | 170 | >>> match.group(2) 171 | '35' 172 | 173 | >>> match.group(1, 2) 174 | ('801', '35') 175 | 176 | >>> match.groups() 177 | ('801', '35') 178 | ``` 179 | 180 | 181 | 182 | 183 | 184 | -------------------------------------------------------------------------------- /section-10-create-gui-apps-in-python-using-tkinter/README.md: -------------------------------------------------------------------------------- 1 | # Section 10: Create GUI Apps In Python Using Tkinter 2 | ## Lesson overview 3 | - Import the Tkinter module. 4 | - Create the GUI application main window. 5 | - Add one or more of the above-mentioned widgets to the GUI application. 6 | - Enter the main event loop to take action against each event triggered by the user. 7 | ### Tkinter : Hello world program 8 | - Tkinter is a package in Python that contains the Tk module that supports GUI programming. Tk was originally written for the Tcl language. Tkinter was later written to use Tk with the Python-based Tcl interpreter. In addition to Tkinter, there are a number of other tools that help create a GUI application written in Python, such as wxPython, PyQt, and PyGTK. 9 | - Example: [Tkinter Program 1]((section-10-create-gui-apps-in-python-using-tkinter/demo-1.py)) 10 | 11 | 12 | ![Result 1](demo-1.png) 13 | ### Tkinter: Using frames 14 | - The Frame widget is very important for the process of grouping and organizing other widgets in a somehow friendly way. It works like a container, which is responsible for arranging the position of other widgets. 15 | - It uses rectangular areas in the screen to organize the layout and to provide padding of these widgets. A frame can also be used as a foundation class to implement complex widgets. 16 | - Syntax:```w = Frame ( master, option, ... )``` 17 | - Parameters 18 | - master − This represents the parent window. 19 | - options − Here is the list of most commonly used options for this widget. These options can be used as key-value pairs separated by commas. 20 | - Example: [Tkinter Program 2]((section-10-create-gui-apps-in-python-using-tkinter/demo-2.py)) 21 | 22 | 23 | ![Result 2](demo-2.png) 24 | ### Tkinter: Grid layout 25 | - This geometry manager organizes widgets in a table-like structure in the parent widget. 26 | - Syntax: ```widget.grid( grid_options )``` 27 | - Here is the list of possible options − 28 | - column − The column to put widget in; default 0 (leftmost column). 29 | - columnspan − How many columns widgetoccupies; default 1. 30 | - ipadx, ipady − How many pixels to pad widget, horizontally and vertically, inside widget's borders. 31 | - padx, pady − How many pixels to pad widget, horizontally and vertically, outside v's borders. 32 | - row − The row to put widget in; default the first row that is still empty. 33 | - rowspan − How many rowswidget occupies; default 1. 34 | - sticky − What to do if the cell is larger than widget. By default, with sticky='', widget is centered in its cell. sticky may be the string concatenation of zero or more of N, E, S, W, NE, NW, SE, and SW, compass directions indicating the sides and corners of the cell to which widget sticks. 35 | - Example: [Tkinter Program 3]((section-10-create-gui-apps-in-python-using-tkinter/demo-3.py)) 36 | 37 | 38 | ![Result 3](demo-3.png) 39 | ### Tkinter: Self adjusting widget 40 | - The pack() widget is used to organize widget in the block. The positions widgets added to the python application using the pack() method can be controlled by using the various options specified in the method call. 41 | - However, the controls are less and widgets are generally added in the less organized manner. 42 | 43 | - Syntax: ```widget.pack(options)``` 44 | A list of possible options that can be passed in pack() is given below. 45 | - expand: If the expand is set to true, the widget expands to fill any space. 46 | - Fill: By default, the fill is set to NONE. However, we can set it to X or Y to determine whether the widget contains any extra space. 47 | - size: it represents the side of the parent to which the widget is to be placed on the window. 48 | - Example: [Tkinter Program 4]((section-10-create-gui-apps-in-python-using-tkinter/demo-4.py)) 49 | 50 | 51 | ![Result 4](demo-4.png) 52 | ### Tkinter: Handling button clicks 53 | - The button widget is used to add various types of buttons to the python application. Python allows us to configure the look of the button according to our requirements. Various options can be set or reset depending upon the requirements. 54 | - We can also associate a method or function with a button which is called when the button is pressed. 55 | The syntax to use the button widget is given below. 56 | - Syntax: ```W = Button(parent, options) ``` 57 | - Example: [Tkinter Program 5]((section-10-create-gui-apps-in-python-using-tkinter/demo-5.py)) 58 | 59 | 60 | ![Result 5](demo-5.png) 61 | 62 | 63 | ![Result 5](demo-5(2).png) 64 | ### Tkinter: Using classes 65 | - Example: [Tkinter Program 6]((section-10-create-gui-apps-in-python-using-tkinter/demo-6.py)) 66 | 67 | 68 | ![Result 6](demo-6.png) 69 | ### Tkinter: Using drop downs 70 | - The Menu widget is used to create various types of menus (top level, pull down, and pop up) in the python application. 71 | - The top-level menus are the one which is displayed just under the title bar of the parent window. We need to create a new instance of the Menu widget and add various commands to it by using the add() method. 72 | - Syntax: ```w = Menu(top, options)``` 73 | - Example: [Tkinter Program 7]((section-10-create-gui-apps-in-python-using-tkinter/demo-7.py)) 74 | 75 | 76 | ![Result 7](demo-7.png) 77 | ### Tkinter: Toolbar 78 | - Example: [Tkinter Program 8]((section-10-create-gui-apps-in-python-using-tkinter/demo-8.py)) 79 | 80 | 81 | ![Result 8](demo-8.png) 82 | ### Tkinter: Making Status Bar 83 | - A status bar is normally a narrow bar at the bottom of the GUI to indicate some extra information like word counts of the file or anything that could add extra value to the user interface. 84 | - Tkinter doesn’t have a dedicated status bar widget but uses Label widget with appropriate configuration to work as the status bar in the GUI. 85 | - Example: [Tkinter Program 9]((section-10-create-gui-apps-in-python-using-tkinter/demo-9.py)) 86 | 87 | 88 | ![Result 9](demo-9.png) 89 | ### Tkinter: Message box 90 | - The Message widget is used to show the message to the user regarding the behaviour of the python application. The message widget shows the text messages to the user which can not be edited. 91 | 92 | - The message text contains more than one line. However, the message can only be shown in the single font. 93 | - Syntax: ``w = Message(parent, options)`` 94 | - Example: [Tkinter Program 10]((section-10-create-gui-apps-in-python-using-tkinter/demo-10.py)) 95 | 96 | 97 | ![Result 10](demo-10.png) 98 | - The messagebox module is used to display the message boxes in the python applications. There are the various functions which are used to display the relevant messages depending upon the application requirements. 99 | - Syntax: ``messagebox.function_name(title, message [, options])`` 100 | - Example: [Tkinter Program 11]((section-10-create-gui-apps-in-python-using-tkinter/demo-11.py)) 101 | 102 | 103 | ![Result 11](demo-11.png) 104 | ### Tkinter Drawing 105 | - The canvas widget is used to add the structured graphics to the python application. It is used to draw the graph and plots to the python application. 106 | - Syntax: ``w = canvas(parent, options) `` 107 | - Example: [Tkinter Program 12]((section-10-create-gui-apps-in-python-using-tkinter/demo-12.py)) 108 | 109 | 110 | ![Result 12](demo-12.png) -------------------------------------------------------------------------------- /section-10-create-gui-apps-in-python-using-tkinter/demo-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-10-create-gui-apps-in-python-using-tkinter/demo-1.png -------------------------------------------------------------------------------- /section-10-create-gui-apps-in-python-using-tkinter/demo-1.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | root = Tk() 3 | 4 | label1 = Label(root,text='Hello Word') 5 | 6 | label1.pack() 7 | root.mainloop() -------------------------------------------------------------------------------- /section-10-create-gui-apps-in-python-using-tkinter/demo-10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-10-create-gui-apps-in-python-using-tkinter/demo-10.png -------------------------------------------------------------------------------- /section-10-create-gui-apps-in-python-using-tkinter/demo-10.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | 3 | top = Tk() 4 | top.geometry("100x100") 5 | var = StringVar() 6 | msg = Message( top, text = "Welcome to Javatpoint") 7 | 8 | msg.pack() 9 | top.mainloop() -------------------------------------------------------------------------------- /section-10-create-gui-apps-in-python-using-tkinter/demo-11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-10-create-gui-apps-in-python-using-tkinter/demo-11.png -------------------------------------------------------------------------------- /section-10-create-gui-apps-in-python-using-tkinter/demo-11.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | 3 | from tkinter import messagebox 4 | 5 | top = Tk() 6 | 7 | top.geometry("100x100") 8 | 9 | messagebox.showinfo("information","Information") 10 | 11 | top.mainloop() -------------------------------------------------------------------------------- /section-10-create-gui-apps-in-python-using-tkinter/demo-12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-10-create-gui-apps-in-python-using-tkinter/demo-12.png -------------------------------------------------------------------------------- /section-10-create-gui-apps-in-python-using-tkinter/demo-12.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | 3 | top = Tk() 4 | 5 | top.geometry("200x200") 6 | 7 | #creating a simple canvas 8 | c = Canvas(top,bg = "pink",height = "200",width = 200) 9 | 10 | arc = c.create_arc((5,10,150,200),start = 0,extent = 150, fill= "white") 11 | 12 | c.pack() 13 | 14 | top.mainloop() -------------------------------------------------------------------------------- /section-10-create-gui-apps-in-python-using-tkinter/demo-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-10-create-gui-apps-in-python-using-tkinter/demo-2.png -------------------------------------------------------------------------------- /section-10-create-gui-apps-in-python-using-tkinter/demo-2.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | 3 | root = Tk() 4 | frame = Frame(root) 5 | frame.pack() 6 | 7 | bottomframe = Frame(root) 8 | bottomframe.pack( side = BOTTOM ) 9 | 10 | redbutton = Button(frame, text="Red", fg="red") 11 | redbutton.pack( side = LEFT) 12 | 13 | greenbutton = Button(frame, text="Brown", fg="brown") 14 | greenbutton.pack( side = LEFT ) 15 | 16 | bluebutton = Button(frame, text="Blue", fg="blue") 17 | bluebutton.pack( side = LEFT ) 18 | 19 | blackbutton = Button(bottomframe, text="Black", fg="black") 20 | blackbutton.pack( side = BOTTOM) 21 | 22 | root.mainloop() 23 | -------------------------------------------------------------------------------- /section-10-create-gui-apps-in-python-using-tkinter/demo-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-10-create-gui-apps-in-python-using-tkinter/demo-3.png -------------------------------------------------------------------------------- /section-10-create-gui-apps-in-python-using-tkinter/demo-3.py: -------------------------------------------------------------------------------- 1 | import tkinter 2 | root = tkinter.Tk( ) 3 | for r in range(3): 4 | for c in range(4): 5 | tkinter.Label(root, text='R%s/C%s'%(r,c), 6 | borderwidth=1 ).grid(row=r,column=c) 7 | root.mainloop( ) -------------------------------------------------------------------------------- /section-10-create-gui-apps-in-python-using-tkinter/demo-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-10-create-gui-apps-in-python-using-tkinter/demo-4.png -------------------------------------------------------------------------------- /section-10-create-gui-apps-in-python-using-tkinter/demo-4.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | top = Tk() 3 | top.geometry("400x250") 4 | name = Label(top, text = "Name").place(x = 30,y = 50) 5 | email = Label(top, text = "Email").place(x = 30, y = 90) 6 | password = Label(top, text = "Password").place(x = 30, y = 130) 7 | e1 = Entry(top).place(x = 80, y = 50) 8 | e2 = Entry(top).place(x = 80, y = 90) 9 | e3 = Entry(top).place(x = 95, y = 130) 10 | top.mainloop() -------------------------------------------------------------------------------- /section-10-create-gui-apps-in-python-using-tkinter/demo-5(2).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-10-create-gui-apps-in-python-using-tkinter/demo-5(2).png -------------------------------------------------------------------------------- /section-10-create-gui-apps-in-python-using-tkinter/demo-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-10-create-gui-apps-in-python-using-tkinter/demo-5.png -------------------------------------------------------------------------------- /section-10-create-gui-apps-in-python-using-tkinter/demo-5.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | 3 | top = Tk() 4 | 5 | top.geometry("200x100") 6 | 7 | def fun(): 8 | messagebox.showinfo("Hello", "Red Button clicked") 9 | 10 | 11 | b1 = Button(top,text = "Red",command = fun,activeforeground = "red",activebackground = "pink",pady=10) 12 | 13 | b2 = Button(top, text = "Blue",activeforeground = "blue",activebackground = "pink",pady=10) 14 | 15 | b3 = Button(top, text = "Green",activeforeground = "green",activebackground = "pink",pady = 10) 16 | 17 | b4 = Button(top, text = "Yellow",activeforeground = "yellow",activebackground = "pink",pady = 10) 18 | 19 | b1.pack(side = LEFT) 20 | 21 | b2.pack(side = RIGHT) 22 | 23 | b3.pack(side = TOP) 24 | 25 | b4.pack(side = BOTTOM) 26 | 27 | top.mainloop() -------------------------------------------------------------------------------- /section-10-create-gui-apps-in-python-using-tkinter/demo-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-10-create-gui-apps-in-python-using-tkinter/demo-6.png -------------------------------------------------------------------------------- /section-10-create-gui-apps-in-python-using-tkinter/demo-6.py: -------------------------------------------------------------------------------- 1 | from tkinter import Tk, Label, Button 2 | 3 | class MyFirstGUI: 4 | def __init__(self, master): 5 | self.master = master 6 | master.title("A simple GUI") 7 | 8 | self.label = Label(master, text="This is our first GUI!") 9 | self.label.pack() 10 | 11 | self.greet_button = Button(master, text="Greet", command=self.greet) 12 | self.greet_button.pack() 13 | 14 | self.close_button = Button(master, text="Close", command=master.quit) 15 | self.close_button.pack() 16 | 17 | def greet(self): 18 | print("Greetings!") 19 | 20 | root = Tk() 21 | my_gui = MyFirstGUI(root) 22 | root.mainloop() -------------------------------------------------------------------------------- /section-10-create-gui-apps-in-python-using-tkinter/demo-7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-10-create-gui-apps-in-python-using-tkinter/demo-7.png -------------------------------------------------------------------------------- /section-10-create-gui-apps-in-python-using-tkinter/demo-7.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | 3 | top = Tk() 4 | 5 | def hello(): 6 | print("hello!") 7 | 8 | # create a toplevel menu 9 | menubar = Menu(top) 10 | menubar.add_command(label="Hello!", command=hello) 11 | menubar.add_command(label="Quit!", command=top.quit) 12 | 13 | # display the menu 14 | top.config(menu=menubar) 15 | 16 | top.mainloop() -------------------------------------------------------------------------------- /section-10-create-gui-apps-in-python-using-tkinter/demo-8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-10-create-gui-apps-in-python-using-tkinter/demo-8.png -------------------------------------------------------------------------------- /section-10-create-gui-apps-in-python-using-tkinter/demo-8.py: -------------------------------------------------------------------------------- 1 | # Simple enough, just import everything from tkinter. 2 | from tkinter import * 3 | 4 | 5 | # Here, we are creating our class, Window, and inheriting from the Frame 6 | # class. Frame is a class from the tkinter module. (see Lib/tkinter/__init__) 7 | class Window(Frame): 8 | 9 | # Define settings upon initialization. Here you can specify 10 | def __init__(self, master=None): 11 | 12 | # parameters that you want to send through the Frame class. 13 | Frame.__init__(self, master) 14 | 15 | #reference to the master widget, which is the tk window 16 | self.master = master 17 | 18 | #with that, we want to then run init_window, which doesn't yet exist 19 | self.init_window() 20 | 21 | #Creation of init_window 22 | def init_window(self): 23 | 24 | # changing the title of our master widget 25 | self.master.title("GUI") 26 | 27 | # allowing the widget to take the full space of the root window 28 | self.pack(fill=BOTH, expand=1) 29 | 30 | # creating a menu instance 31 | menu = Menu(self.master) 32 | self.master.config(menu=menu) 33 | 34 | # create the file object) 35 | file = Menu(menu) 36 | 37 | # adds a command to the menu option, calling it exit, and the 38 | # command it runs on event is client_exit 39 | file.add_command(label="Exit", command=self.client_exit) 40 | 41 | #added "file" to our menu 42 | menu.add_cascade(label="File", menu=file) 43 | 44 | # create the file object) 45 | edit = Menu(menu) 46 | 47 | # adds a command to the menu option, calling it exit, and the 48 | # command it runs on event is client_exit 49 | edit.add_command(label="Undo") 50 | 51 | #added "file" to our menu 52 | menu.add_cascade(label="Edit", menu=edit) 53 | 54 | 55 | def client_exit(self): 56 | exit() 57 | 58 | 59 | # root window created. Here, that would be the only window, but 60 | # you can later have windows within windows. 61 | root = Tk() 62 | 63 | root.geometry("400x300") 64 | 65 | #creation of an instance 66 | app = Window(root) 67 | 68 | #mainloop 69 | root.mainloop() -------------------------------------------------------------------------------- /section-10-create-gui-apps-in-python-using-tkinter/demo-9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-10-create-gui-apps-in-python-using-tkinter/demo-9.png -------------------------------------------------------------------------------- /section-10-create-gui-apps-in-python-using-tkinter/demo-9.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | 3 | app = tk.Tk() 4 | app.geometry('300x200') 5 | app.title("Basic Status Bar") 6 | 7 | statusbar = tk.Label(app, text="on the way…", bd=1, relief=tk.SUNKEN, anchor=tk.W) 8 | 9 | statusbar.pack(side=tk.BOTTOM, fill=tk.X) 10 | app.mainloop() -------------------------------------------------------------------------------- /section-11-build-calculator-app-using-tkinter/README.md: -------------------------------------------------------------------------------- 1 | # Section 11: Build calculator app using tkinter 2 | ## Lesson overview 3 | - Python offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, tkinter is most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with tkinter outputs the fastest and easiest way to create the GUI applications. Creating a GUI using tkinter is an easy task. 4 | - Basic steps: 5 | - First we create an object named root out of tk. 6 | - We create an object of the calc and pass root as master to the init method. 7 | - Mainloop starts an event loop, which is basically an infinite loop waiting for events and respond accordingly. The mainloop can be terminated by closing the window or using close method. 8 | ### Building Calculator App Part 1 9 | ### Building Calculator App Part 2 10 | ### Building Calculator App Part 3 11 | ### Building Calculator App Part 4 12 | ### My-app 13 | [My-Caculator](section-11-build-calculator-app-using-tkinter/my-app.py) 14 | ### Solution 15 | [Solution](section-11-build-calculator-app-using-tkinter/solution.py) 16 | ### Test Case 17 | - Case 1 :1 + 1 = 2 18 | 19 | 20 | ![Test Case 1](test-1.png) 21 | 22 | 23 | ![Result 1](result-1.png) 24 | - Case 2 : 10 - 2 = 8 25 | 26 | 27 | ![Test Case 2](test-2.png) 28 | 29 | 30 | ![Result 2](result-2.png) 31 | - Case 3 : 10 * 3 = 30 32 | 33 | 34 | ![Test Case 3](test-3.png) 35 | 36 | 37 | ![Result 3](result-3.png) 38 | - Case 4 : 40 * 4 = 10 39 | 40 | 41 | ![Test Case 4](test-4.png) 42 | 43 | 44 | ![Result 4](result-4.png) -------------------------------------------------------------------------------- /section-11-build-calculator-app-using-tkinter/my-app.py: -------------------------------------------------------------------------------- 1 | 2 | # importing Tkinter and math 3 | from tkinter import * 4 | import math 5 | 6 | # calc class 7 | class calc: 8 | 9 | def getandreplace(self): 10 | 11 | """replace x with * and ÷ with /""" 12 | self.expression = self.e.get() 13 | self.newtext=self.expression.replace('/','/') 14 | self.newtext=self.newtext.replace('x','*') 15 | 16 | 17 | def equals(self): 18 | """when the equal button is pressed""" 19 | self.getandreplace() 20 | try: 21 | # evaluate the expression using the eval function 22 | self.value= eval(self.newtext) 23 | except SyntaxError or NameError: 24 | self.e.delete(0,END) 25 | self.e.insert(0,'Invalid Input!') 26 | else: 27 | self.e.delete(0,END) 28 | self.e.insert(0,self.value) 29 | 30 | def squareroot(self): 31 | """squareroot method""" 32 | self.getandreplace() 33 | try: 34 | # evaluate the expression using the eval function 35 | self.value= eval(self.newtext) 36 | except SyntaxError or NameError: 37 | self.e.delete(0,END) 38 | self.e.insert(0,'Invalid Input!') 39 | else: 40 | self.sqrtval=math.sqrt(self.value) 41 | self.e.delete(0,END) 42 | self.e.insert(0,self.sqrtval) 43 | 44 | def square(self): 45 | """square method""" 46 | self.getandreplace() 47 | try: 48 | #evaluate the expression using the eval function 49 | self.value= eval(self.newtext) 50 | except SyntaxError or NameError: 51 | self.e.delete(0,END) 52 | self.e.insert(0,'Invalid Input!') 53 | else: 54 | self.sqval=math.pow(self.value,2) 55 | self.e.delete(0,END) 56 | self.e.insert(0,self.sqval) 57 | 58 | def clearall(self): 59 | """when clear button is pressed,clears the text input area""" 60 | self.e.delete(0,END) 61 | 62 | def clear1(self): 63 | self.txt=self.e.get()[:-1] 64 | self.e.delete(0,END) 65 | self.e.insert(0,self.txt) 66 | 67 | def action(self,argi): 68 | """pressed button's value is inserted into the end of the text area""" 69 | self.e.insert(END,argi) 70 | 71 | def __init__(self,master): 72 | """Constructor method""" 73 | master.title('Calulator') 74 | master.geometry() 75 | self.e = Entry(master) 76 | self.e.grid(row=0,column=0,columnspan=6,pady=3) 77 | self.e.focus_set() #Sets focus on the input text area 78 | 79 | # Generating Buttons 80 | Button(master,text="=",width=11,height=3,fg="blue", 81 | bg="orange",command=lambda:self.equals()).grid( 82 | row=4, column=4,columnspan=2) 83 | 84 | Button(master,text='AC',width=5,height=3, 85 | fg="red", bg="light green", 86 | command=lambda:self.clearall()).grid(row=1, column=4) 87 | 88 | Button(master,text='C',width=5,height=3, 89 | fg="red",bg="light green", 90 | command=lambda:self.clear1()).grid(row=1, column=5) 91 | 92 | Button(master,text="+",width=5,height=3, 93 | fg="blue",bg="orange", 94 | command=lambda:self.action('+')).grid(row=4, column=3) 95 | 96 | Button(master,text="x",width=5,height=3, 97 | fg="blue",bg="orange", 98 | command=lambda:self.action('x')).grid(row=2, column=3) 99 | 100 | Button(master,text="-",width=5,height=3, 101 | fg="red",bg="light green", 102 | command=lambda:self.action('-')).grid(row=3, column=3) 103 | 104 | Button(master,text="÷",width=5,height=3, 105 | fg="blue",bg="orange", 106 | command=lambda:self.action('/')).grid(row=1, column=3) 107 | 108 | Button(master,text="%",width=5,height=3, 109 | fg="red",bg="light green", 110 | command=lambda:self.action('%')).grid(row=4, column=2) 111 | 112 | Button(master,text="7",width=5,height=3, 113 | fg="blue",bg="orange", 114 | command=lambda:self.action('7')).grid(row=1, column=0) 115 | 116 | Button(master,text="8",width=5,height=3, 117 | fg="red",bg="light green", 118 | command=lambda:self.action(8)).grid(row=1, column=1) 119 | 120 | Button(master,text="9",width=5,height=3, 121 | fg="blue",bg="orange", 122 | command=lambda:self.action(9)).grid(row=1, column=2) 123 | 124 | Button(master,text="4",width=5,height=3, 125 | fg="red",bg="light green", 126 | command=lambda:self.action(4)).grid(row=2, column=0) 127 | 128 | Button(master,text="5",width=5,height=3, 129 | fg="blue",bg="orange", 130 | command=lambda:self.action(5)).grid(row=2, column=1) 131 | 132 | Button(master,text="6",width=5,height=3, 133 | fg="white",bg="blue", 134 | command=lambda:self.action(6)).grid(row=2, column=2) 135 | 136 | Button(master,text="1",width=5,height=3, 137 | fg="red",bg="light green", 138 | command=lambda:self.action(1)).grid(row=3, column=0) 139 | 140 | Button(master,text="2",width=5,height=3, 141 | fg="blue",bg="orange", 142 | command=lambda:self.action(2)).grid(row=3, column=1) 143 | 144 | Button(master,text="3",width=5,height=3, 145 | fg="white",bg="blue", 146 | command=lambda:self.action(3)).grid(row=3, column=2) 147 | 148 | Button(master,text="0",width=5,height=3, 149 | fg="white",bg="blue", 150 | command=lambda:self.action(0)).grid(row=4, column=0) 151 | 152 | Button(master,text=".",width=5,height=3, 153 | fg="red",bg="light green", 154 | command=lambda:self.action('.')).grid(row=4, column=1) 155 | 156 | Button(master,text="(",width=5,height=3, 157 | fg="white",bg="blue", 158 | command=lambda:self.action('(')).grid(row=2, column=4) 159 | 160 | Button(master,text=")",width=5,height=3, 161 | fg="blue",bg="orange", 162 | command=lambda:self.action(')')).grid(row=2, column=5) 163 | 164 | Button(master,text="?",width=5,height=3, 165 | fg="red",bg="light green", 166 | command=lambda:self.squareroot()).grid(row=3, column=4) 167 | 168 | Button(master,text="x²",width=5,height=3, 169 | fg="white",bg="blue", 170 | command=lambda:self.square()).grid(row=3, column=5) 171 | 172 | # Driver Code 173 | root = Tk() 174 | 175 | obj=calc(root) # object instantiated 176 | 177 | root.mainloop() -------------------------------------------------------------------------------- /section-11-build-calculator-app-using-tkinter/result-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-11-build-calculator-app-using-tkinter/result-1.png -------------------------------------------------------------------------------- /section-11-build-calculator-app-using-tkinter/result-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-11-build-calculator-app-using-tkinter/result-2.png -------------------------------------------------------------------------------- /section-11-build-calculator-app-using-tkinter/result-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-11-build-calculator-app-using-tkinter/result-3.png -------------------------------------------------------------------------------- /section-11-build-calculator-app-using-tkinter/result-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-11-build-calculator-app-using-tkinter/result-4.png -------------------------------------------------------------------------------- /section-11-build-calculator-app-using-tkinter/solution.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | import parser 3 | 4 | root = Tk() 5 | root.title('Calculator') 6 | 7 | #get the user input and place it in the textfield 8 | i = 0 9 | def get_variables(num): 10 | global i 11 | display.insert(i,num) 12 | i+=1 13 | 14 | def calculate(): 15 | entire_string = display.get() 16 | try: 17 | a = parser.expr(entire_string).compile() 18 | result = eval(a) 19 | clear_all() 20 | display.insert(0,result) 21 | except Exception: 22 | clear_all() 23 | display.insert(0,"Error") 24 | 25 | def get_operation(operator): 26 | global i 27 | length = len(operator) 28 | display.insert(i,operator) 29 | i+=length 30 | 31 | 32 | def clear_all(): 33 | display.delete(0,END) 34 | 35 | def undo(): 36 | entire_string = display.get() 37 | if len(entire_string): 38 | new_string = entire_string[:-1] 39 | clear_all() 40 | display.insert(0,new_string) 41 | else: 42 | clear_all() 43 | display.insert(0,"Error") 44 | 45 | #adding the input field 46 | display = Entry(root) 47 | display.grid(row=1,columnspan=6,sticky=W+E) 48 | 49 | #adding buttons to the calculator 50 | 51 | Button(root,text="1",command = lambda :get_variables(1)).grid(row=2,column=0) 52 | Button(root,text="2",command = lambda :get_variables(2)).grid(row=2,column=1) 53 | Button(root,text="3",command = lambda :get_variables(3)).grid(row=2,column=2) 54 | 55 | Button(root,text="4",command = lambda :get_variables(4)).grid(row=3,column=0) 56 | Button(root,text="5",command = lambda :get_variables(5)).grid(row=3,column=1) 57 | Button(root,text="6",command = lambda :get_variables(6)).grid(row=3,column=2) 58 | 59 | Button(root,text="7",command = lambda :get_variables(7)).grid(row=4,column=0) 60 | Button(root,text="8",command = lambda :get_variables(8)).grid(row=4,column=1) 61 | Button(root,text="9",command = lambda :get_variables(9)).grid(row=4,column=2) 62 | 63 | #adding other buttons to the calculator 64 | Button(root,text="AC",command=lambda :clear_all()).grid(row=5,column=0) 65 | Button(root,text="0",command = lambda :get_variables(0)).grid(row=5,column=1) 66 | Button(root,text="=",command=lambda :calculate()).grid(row=5,column=2) 67 | 68 | 69 | Button(root,text="+",command= lambda :get_operation("+")).grid(row=2,column=3) 70 | Button(root,text="-",command= lambda :get_operation("-")).grid(row=3,column=3) 71 | Button(root,text="*",command= lambda :get_operation("*")).grid(row=4,column=3) 72 | Button(root,text="/",command= lambda :get_operation("/")).grid(row=5,column=3) 73 | 74 | # adding new operations 75 | Button(root,text="pi",command= lambda :get_operation("*3.14")).grid(row=2,column=4) 76 | Button(root,text="%",command= lambda :get_operation("%")).grid(row=3,column=4) 77 | Button(root,text="(",command= lambda :get_operation("(")).grid(row=4,column=4) 78 | Button(root,text="exp",command= lambda :get_operation("**")).grid(row=5,column=4) 79 | 80 | Button(root,text="<-",command= lambda :undo()).grid(row=2,column=5) 81 | Button(root,text="x!").grid(row=3,column=5) 82 | Button(root,text=")",command= lambda :get_operation(")")).grid(row=4,column=5) 83 | Button(root,text="^2",command= lambda :get_operation("**2")).grid(row=5,column=5) 84 | 85 | 86 | root.mainloop() -------------------------------------------------------------------------------- /section-11-build-calculator-app-using-tkinter/test-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-11-build-calculator-app-using-tkinter/test-1.png -------------------------------------------------------------------------------- /section-11-build-calculator-app-using-tkinter/test-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-11-build-calculator-app-using-tkinter/test-2.png -------------------------------------------------------------------------------- /section-11-build-calculator-app-using-tkinter/test-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-11-build-calculator-app-using-tkinter/test-3.png -------------------------------------------------------------------------------- /section-11-build-calculator-app-using-tkinter/test-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-11-build-calculator-app-using-tkinter/test-4.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/app.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | import tkinter as tk 3 | import psycopg2 4 | root = Tk() 5 | 6 | def get_data(name,age,phone): 7 | conn =psycopg2.connect( 8 | host='localhost', 9 | database='management', 10 | user='postgres', 11 | password='1234' 12 | ) 13 | 14 | cur = conn.cursor() 15 | query= '''INSERT INTO student (NAME,AGE,PHONE) VALUES (%s,%s,%s);''' 16 | cur.execute(query,(name,age,phone)) 17 | print('Insert Successfully') 18 | conn.commit() 19 | conn.close() 20 | def search(name): 21 | conn =psycopg2.connect( 22 | host='localhost', 23 | database='management', 24 | user='postgres', 25 | password='1234' 26 | ) 27 | cur = conn.cursor() 28 | query= f'''SELECT * FROM student WHERE NAME = '{name}' ;''' 29 | cur.execute(query,(name)) 30 | row = cur.fetchone() 31 | display_search(row) 32 | conn.commit() 33 | conn.close() 34 | display_all() 35 | 36 | def display_search(row): 37 | listbox = Listbox(frame,width=20,height=5) 38 | listbox.grid(row=9,column=0) 39 | listbox.insert(END,row) 40 | 41 | def display_all(): 42 | conn =psycopg2.connect( 43 | host='localhost', 44 | database='management', 45 | user='postgres', 46 | password='1234' 47 | ) 48 | cur = conn.cursor() 49 | query= '''SELECT * FROM student ;''' 50 | cur.execute(query) 51 | row = cur.fetchall() 52 | 53 | listbox = Listbox(frame,width=20,height=5) 54 | listbox.grid(row=10,column=1) 55 | for x in row: 56 | listbox.insert(END,x) 57 | canvas = Canvas(root,height = 280,width = 500) 58 | canvas.pack() 59 | 60 | frame = Frame() 61 | frame.place(relx=0.3,rely=0.1,relwidth=0.8,relheight=0.8) 62 | 63 | label = Label(frame,text="Add Data") 64 | label.grid(row = 0,column=1) 65 | 66 | label = Label(frame,text="Name") 67 | label.grid(row = 1,column=0) 68 | 69 | label = Label(frame,text="Age") 70 | label.grid(row = 2,column=0) 71 | 72 | label = Label(frame,text="Numberphone") 73 | label.grid(row = 3,column=0) 74 | 75 | entry_name = Entry(frame) 76 | entry_name.grid(row=1,column=1) 77 | 78 | entry_age = Entry(frame) 79 | entry_age.grid(row=2,column=1) 80 | 81 | entry_phone = Entry(frame) 82 | entry_phone.grid(row=3,column=1) 83 | 84 | button = Button( 85 | frame,text="Add Data", 86 | command= lambda: get_data( 87 | entry_name.get(), 88 | entry_age.get(), 89 | entry_phone.get() 90 | ) 91 | ) 92 | button.grid(row=4,column=1) 93 | 94 | label = Label(frame,text="Search Data") 95 | label.grid(row = 5,column=1) 96 | 97 | label = Label(frame,text="Search by Name") 98 | label.grid(row = 6,column=0) 99 | 100 | entry_data = Entry(frame) 101 | entry_data.grid(row=6,column=1) 102 | 103 | button = Button( 104 | frame,text="Search Data", command= lambda:search(entry_data.get()) 105 | ) 106 | button.grid(row=6,column=2) 107 | display_all() 108 | 109 | 110 | root.mainloop() -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/config.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | from configparser import ConfigParser 3 | 4 | 5 | def config(filename='database.ini', section='postgresql'): 6 | # create a parser 7 | parser = ConfigParser() 8 | # read config file 9 | parser.read(filename) 10 | 11 | # get section, default to postgresql 12 | db = {} 13 | if parser.has_section(section): 14 | params = parser.items(section) 15 | for param in params: 16 | db[param[0]] = param[1] 17 | else: 18 | raise Exception('Section {0} not found in the {1} file'.format(section, filename)) 19 | 20 | return db -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/create-table.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import psycopg2 4 | from config import config 5 | 6 | 7 | def create_tables(): 8 | """ create tables in the PostgreSQL database""" 9 | commands= """ CREATE TABLE student ( 10 | name VARCHAR(10) PRIMARY KEY, 11 | age VARCHAR(3) , 12 | phone VARCHAR(11) 13 | );""" 14 | conn = None 15 | try: 16 | # read the connection parameters 17 | params = config() 18 | # connect to the PostgreSQL server 19 | conn = psycopg2.connect(**params) 20 | cur = conn.cursor() 21 | # create table one by one 22 | for command in commands: 23 | cur.execute(command) 24 | # close communication with the PostgreSQL database server 25 | cur.close() 26 | # commit the changes 27 | conn.commit() 28 | except (Exception, psycopg2.DatabaseError) as error: 29 | print(error) 30 | finally: 31 | if conn is not None: 32 | conn.close() 33 | 34 | 35 | if __name__ == '__main__': 36 | create_tables() -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/database.ini: -------------------------------------------------------------------------------- 1 | [postgresql] 2 | host=localhost 3 | database=management 4 | user=postgres 5 | password=1234 -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/image/step-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-12-building-database-apps-with-postgreSQL-and-python/image/step-1.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/image/step-10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-12-building-database-apps-with-postgreSQL-and-python/image/step-10.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/image/step-11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-12-building-database-apps-with-postgreSQL-and-python/image/step-11.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/image/step-12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-12-building-database-apps-with-postgreSQL-and-python/image/step-12.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/image/step-13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-12-building-database-apps-with-postgreSQL-and-python/image/step-13.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/image/step-14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-12-building-database-apps-with-postgreSQL-and-python/image/step-14.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/image/step-15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-12-building-database-apps-with-postgreSQL-and-python/image/step-15.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/image/step-16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-12-building-database-apps-with-postgreSQL-and-python/image/step-16.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/image/step-17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-12-building-database-apps-with-postgreSQL-and-python/image/step-17.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/image/step-18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-12-building-database-apps-with-postgreSQL-and-python/image/step-18.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/image/step-19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-12-building-database-apps-with-postgreSQL-and-python/image/step-19.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/image/step-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-12-building-database-apps-with-postgreSQL-and-python/image/step-2.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/image/step-20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-12-building-database-apps-with-postgreSQL-and-python/image/step-20.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/image/step-21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-12-building-database-apps-with-postgreSQL-and-python/image/step-21.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/image/step-22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-12-building-database-apps-with-postgreSQL-and-python/image/step-22.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/image/step-23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-12-building-database-apps-with-postgreSQL-and-python/image/step-23.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/image/step-24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-12-building-database-apps-with-postgreSQL-and-python/image/step-24.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/image/step-25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-12-building-database-apps-with-postgreSQL-and-python/image/step-25.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/image/step-26.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-12-building-database-apps-with-postgreSQL-and-python/image/step-26.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/image/step-27.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-12-building-database-apps-with-postgreSQL-and-python/image/step-27.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/image/step-28.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-12-building-database-apps-with-postgreSQL-and-python/image/step-28.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/image/step-29.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-12-building-database-apps-with-postgreSQL-and-python/image/step-29.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/image/step-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-12-building-database-apps-with-postgreSQL-and-python/image/step-3.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/image/step-30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-12-building-database-apps-with-postgreSQL-and-python/image/step-30.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/image/step-31.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-12-building-database-apps-with-postgreSQL-and-python/image/step-31.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/image/step-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-12-building-database-apps-with-postgreSQL-and-python/image/step-32.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/image/step-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-12-building-database-apps-with-postgreSQL-and-python/image/step-4.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/image/step-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-12-building-database-apps-with-postgreSQL-and-python/image/step-5.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/image/step-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-12-building-database-apps-with-postgreSQL-and-python/image/step-6.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/image/step-7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-12-building-database-apps-with-postgreSQL-and-python/image/step-7.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/image/step-8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-12-building-database-apps-with-postgreSQL-and-python/image/step-8.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/image/step-9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-12-building-database-apps-with-postgreSQL-and-python/image/step-9.png -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/insert.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import psycopg2 4 | from config import config 5 | 6 | 7 | def insert_vendor(vendor_name): 8 | """ insert a new vendor into the vendors table """ 9 | sql = """INSERT INTO vendors(vendor_name) 10 | VALUES(%s) RETURNING vendor_id;""" 11 | conn = None 12 | vendor_id = None 13 | try: 14 | # read database configuration 15 | params = config() 16 | # connect to the PostgreSQL database 17 | conn = psycopg2.connect(**params) 18 | # create a new cursor 19 | cur = conn.cursor() 20 | # execute the INSERT statement 21 | cur.execute(sql, (vendor_name,)) 22 | # get the generated id back 23 | vendor_id = cur.fetchone()[0] 24 | # commit the changes to the database 25 | conn.commit() 26 | print('Insert successfully') 27 | # close communication with the database 28 | cur.close() 29 | except (Exception, psycopg2.DatabaseError) as error: 30 | print(error) 31 | finally: 32 | if conn is not None: 33 | conn.close() 34 | 35 | return vendor_id 36 | insert_vendor("ban") -------------------------------------------------------------------------------- /section-12-building-database-apps-with-postgreSQL-and-python/python-postgresql.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import psycopg2 3 | from config import config 4 | 5 | def connect(): 6 | """ Connect to the PostgreSQL database server """ 7 | conn = None 8 | try: 9 | # read connection parameters 10 | params = config() 11 | 12 | # connect to the PostgreSQL server 13 | print('Connecting to the PostgreSQL database...') 14 | conn = psycopg2.connect(**params) 15 | 16 | # create a cursor 17 | cur = conn.cursor() 18 | 19 | # execute a statement 20 | print('PostgreSQL database version:') 21 | cur.execute('SELECT version()') 22 | 23 | # display the PostgreSQL database server version 24 | db_version = cur.fetchone() 25 | print(db_version) 26 | 27 | # close the communication with the PostgreSQL 28 | cur.close() 29 | except (Exception, psycopg2.DatabaseError) as error: 30 | print(error) 31 | finally: 32 | if conn is not None: 33 | conn.close() 34 | print('Database connection closed.') 35 | 36 | 37 | if __name__ == '__main__': 38 | connect() -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-1.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-10.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-11.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-12.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-13.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-14.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-15.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-16.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-17.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-18.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-19.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-2.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-20.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-21.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-22.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-23.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-24.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-25.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-26.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-26.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-27.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-27.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-28.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-28.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-29.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-29.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-3.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-30.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-31.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-31.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-32.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-33.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-33.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-34.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-34.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-35.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-35.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-36.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-36.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-37.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-37.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-38.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-38.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-39.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-39.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-4.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-40.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-41.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-41.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-42.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-42.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-43.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-43.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-44.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-44.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-45.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-45.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-46.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-46.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-47.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-47.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-48.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-49.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-49.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-5.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-50.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-51.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-51.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-52.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-52.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-53.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-53.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-54.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-54.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-55.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-55.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-56.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-56.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-57.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-57.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-58.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-58.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-59.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-59.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-6.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-60.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-61.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-61.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-62.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-62.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-63.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-63.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-64.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-65.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-65.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-66.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-66.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-67.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-67.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-68.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-68.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-69.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-69.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-7.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-70.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-70.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-71.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-71.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-72.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-72.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-73.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-73.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-74.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-74.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-75.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-75.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-76.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-77.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-77.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-78.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-78.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-79.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-79.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-8.png -------------------------------------------------------------------------------- /section-13-data-analysis-using-python/image/image-9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-13-data-analysis-using-python/image/image-9.png -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/image/step-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-14-make-web-applications-in-python-using-django/image/step-1.png -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/image/step-10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-14-make-web-applications-in-python-using-django/image/step-10.png -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/image/step-11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-14-make-web-applications-in-python-using-django/image/step-11.png -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/image/step-12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-14-make-web-applications-in-python-using-django/image/step-12.png -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/image/step-13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-14-make-web-applications-in-python-using-django/image/step-13.png -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/image/step-14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-14-make-web-applications-in-python-using-django/image/step-14.png -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/image/step-15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-14-make-web-applications-in-python-using-django/image/step-15.png -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/image/step-16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-14-make-web-applications-in-python-using-django/image/step-16.png -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/image/step-17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-14-make-web-applications-in-python-using-django/image/step-17.png -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/image/step-18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-14-make-web-applications-in-python-using-django/image/step-18.png -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/image/step-19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-14-make-web-applications-in-python-using-django/image/step-19.png -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/image/step-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-14-make-web-applications-in-python-using-django/image/step-2.png -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/image/step-20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-14-make-web-applications-in-python-using-django/image/step-20.png -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/image/step-21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-14-make-web-applications-in-python-using-django/image/step-21.png -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/image/step-22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-14-make-web-applications-in-python-using-django/image/step-22.png -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/image/step-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-14-make-web-applications-in-python-using-django/image/step-3.png -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/image/step-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-14-make-web-applications-in-python-using-django/image/step-4.png -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/image/step-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-14-make-web-applications-in-python-using-django/image/step-5.png -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/image/step-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-14-make-web-applications-in-python-using-django/image/step-6.png -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/image/step-7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-14-make-web-applications-in-python-using-django/image/step-7.png -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/image/step-8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-14-make-web-applications-in-python-using-django/image/step-8.png -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/image/step-9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-14-make-web-applications-in-python-using-django/image/step-9.png -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/web-section-14/.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/ 2 | venv/ 3 | __pycache__ 4 | db.sqlite3 -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/web-section-14/mysite/books/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-14-make-web-applications-in-python-using-django/web-section-14/mysite/books/__init__.py -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/web-section-14/mysite/books/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import Book 3 | # Register your models here. 4 | 5 | admin.site.register(Book) 6 | -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/web-section-14/mysite/books/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class BooksConfig(AppConfig): 5 | name = 'books' 6 | -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/web-section-14/mysite/books/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.core.urlresolvers import reverse 3 | 4 | 5 | # Create your models here. 6 | 7 | 8 | class Book(models.Model): 9 | 10 | def get_absolute_url(self): 11 | return reverse("book:details", kwargs={"pk": self.pk}) 12 | 13 | def __str__(self): 14 | 15 | return self.name + '-' + self.author 16 | 17 | name = models.CharField(max_length=100) 18 | author = models.CharField(max_length=100) 19 | price = models.CharField(max_length=100) 20 | type = models.CharField(max_length=100) 21 | year = models.CharField(max_length=100) 22 | book_image = models.CharField(max_length=100) 23 | -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/web-section-14/mysite/books/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/web-section-14/mysite/books/urls.py: -------------------------------------------------------------------------------- 1 | from django.conf.urls import url 2 | from . import views 3 | 4 | app_name = 'books' 5 | 6 | urlpatterns = [ 7 | url(r'^$', views.IndexListView.as_view(), name='index'), 8 | url(r'^(?P[0-9]+)/$', views.DetailView.as_view( ), name='detail'), 9 | url(r"^books/add/$", views.BookCreateView.as_view(), name="book-add"), 10 | 11 | ] -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/web-section-14/mysite/books/views.py: -------------------------------------------------------------------------------- 1 | from django.views import generic 2 | from django.views.generic.edit import CreateView 3 | 4 | from .models import Book 5 | class IndexListView(generic.ListView): 6 | template_name = "books/index.html" 7 | 8 | def get_queryset(self): 9 | return Book.objects.all() 10 | 11 | class DetailView(generic.DetailView): 12 | model = Book 13 | template_name = "books/detail.html" 14 | 15 | class BookCreateView(CreateView): 16 | model = Book 17 | fields = [ 18 | 'name','author','price', 19 | 'type','year','book_image' 20 | ] 21 | template_name = "books/book_form.html" 22 | -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/web-section-14/mysite/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings") 7 | try: 8 | from django.core.management import execute_from_command_line 9 | except ImportError: 10 | # The above import may fail for some other reason. Ensure that the 11 | # issue is really that Django is missing to avoid masking other 12 | # exceptions on Python 2. 13 | try: 14 | import django 15 | except ImportError: 16 | raise ImportError( 17 | "Couldn't import Django. Are you sure it's installed and " 18 | "available on your PYTHONPATH environment variable? Did you " 19 | "forget to activate a virtual environment?" 20 | ) 21 | raise 22 | execute_from_command_line(sys.argv) 23 | -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/web-section-14/mysite/mysite/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-14-make-web-applications-in-python-using-django/web-section-14/mysite/mysite/__init__.py -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/web-section-14/mysite/mysite/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for mysite project. 3 | 4 | Generated by 'django-admin startproject' using Django 1.11.2. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/1.11/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/1.11/ref/settings/ 11 | """ 12 | 13 | import os 14 | 15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'j9dze=pglx-886t8)$*$dtmk#9w&twf2p73s+=%uqy5uy#oqi%' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = [] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | 'books' 41 | ] 42 | 43 | MIDDLEWARE = [ 44 | 'django.middleware.security.SecurityMiddleware', 45 | 'django.contrib.sessions.middleware.SessionMiddleware', 46 | 'django.middleware.common.CommonMiddleware', 47 | 'django.middleware.csrf.CsrfViewMiddleware', 48 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 49 | 'django.contrib.messages.middleware.MessageMiddleware', 50 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 51 | ] 52 | 53 | ROOT_URLCONF = 'mysite.urls' 54 | 55 | TEMPLATES = [ 56 | { 57 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 58 | 'DIRS': [os.path.join(BASE_DIR, 'templates')], 59 | 'APP_DIRS': True, 60 | 'OPTIONS': { 61 | 'context_processors': [ 62 | 'django.template.context_processors.debug', 63 | 'django.template.context_processors.request', 64 | 'django.contrib.auth.context_processors.auth', 65 | 'django.contrib.messages.context_processors.messages', 66 | ], 67 | }, 68 | }, 69 | ] 70 | 71 | WSGI_APPLICATION = 'mysite.wsgi.application' 72 | 73 | 74 | # Database 75 | # https://docs.djangoproject.com/en/1.11/ref/settings/#databases 76 | 77 | DATABASES = { 78 | 'default': { 79 | 'ENGINE': 'django.db.backends.sqlite3', 80 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 81 | } 82 | } 83 | 84 | 85 | # Password validation 86 | # https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators 87 | 88 | AUTH_PASSWORD_VALIDATORS = [ 89 | { 90 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 91 | }, 92 | { 93 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 94 | }, 95 | { 96 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 97 | }, 98 | { 99 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 100 | }, 101 | ] 102 | 103 | 104 | # Internationalization 105 | # https://docs.djangoproject.com/en/1.11/topics/i18n/ 106 | 107 | LANGUAGE_CODE = 'en-us' 108 | 109 | TIME_ZONE = 'UTC' 110 | 111 | USE_I18N = True 112 | 113 | USE_L10N = True 114 | 115 | USE_TZ = True 116 | 117 | 118 | # Static files (CSS, JavaScript, Images) 119 | # https://docs.djangoproject.com/en/1.11/howto/static-files/ 120 | 121 | STATIC_URL = '/static/' 122 | STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')] 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/web-section-14/mysite/mysite/urls.py: -------------------------------------------------------------------------------- 1 | from django.conf.urls import include, url 2 | from django.contrib import admin 3 | 4 | urlpatterns = [ 5 | url(r'^books/', include('books.urls')), 6 | url(r'^admin/', admin.site.urls), 7 | ] -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/web-section-14/mysite/mysite/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for mysite project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings") 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/web-section-14/mysite/static/books/back.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-14-make-web-applications-in-python-using-django/web-section-14/mysite/static/books/back.jpg -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/web-section-14/mysite/static/books/khoa.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-14-make-web-applications-in-python-using-django/web-section-14/mysite/static/books/khoa.png -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/web-section-14/mysite/static/books/purple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-14-make-web-applications-in-python-using-django/web-section-14/mysite/static/books/purple.png -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/web-section-14/mysite/static/books/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | background: white; 3 | } 4 | 5 | .jumbotron { 6 | background: white url("yellow.jpg"); 7 | } 8 | 9 | .jumbotron-special { 10 | background: white url("purple.png"); 11 | } 12 | 13 | .jumbotron-special h2 { 14 | color: white; 15 | } -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/web-section-14/mysite/static/books/yellow.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-14-make-web-applications-in-python-using-django/web-section-14/mysite/static/books/yellow.jpg -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/web-section-14/mysite/templates/books/base.html: -------------------------------------------------------------------------------- 1 | {% load static %} 2 | 3 | 4 | 5 | 6 | Title 7 | 8 | 10 | 11 | 12 | 41 | {% block body %} 42 | {% endblock %} 43 | 44 | 45 | -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/web-section-14/mysite/templates/books/book_form.html: -------------------------------------------------------------------------------- 1 | {% extends 'books/base.html' %} 2 | 3 | {% block body %} 4 | 5 |
6 |
7 |
8 |
9 |
10 | 11 |
12 | {% csrf_token %} 13 | {% include 'books/form-template.html' %} 14 |
15 |
16 | 17 |
18 |
19 |
20 | 21 | 22 |
23 |
24 |
25 |
26 |
27 | 28 | {% endblock %} -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/web-section-14/mysite/templates/books/detail.html: -------------------------------------------------------------------------------- 1 | {% extends 'books/base.html' %} {% block body %} 2 | 3 | 13 | 14 |
15 |
16 | Generic placeholder thumbnail 17 | 18 |
19 |

{{book.name}}

20 |

{{book.author}}

21 |

22 |
23 |
24 |
25 | 26 |
27 |
28 |

{{book.name}}

29 |

Author: {{book.author}}

30 |

Price: {{book.price}}$

31 |

Category: {{book.type}}

32 | 33 | 34 | Read Sample 35 | 36 |
37 |
38 | 39 | {% endblock %} -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/web-section-14/mysite/templates/books/form-template.html: -------------------------------------------------------------------------------- 1 | {% for field in form %} 2 |
3 |
4 | {{field.errors}} 5 | 6 |
7 | 8 |
{{field}}
9 | 10 |
11 | {% endfor %} 12 | -------------------------------------------------------------------------------- /section-14-make-web-applications-in-python-using-django/web-section-14/mysite/templates/books/index.html: -------------------------------------------------------------------------------- 1 | {% extends 'books/base.html' %} {% block body %} 2 | 3 |
4 |

The Bookstore

5 |

Collection of all popular books

6 |
7 |
8 |
9 |

Popular Books

10 | 11 |
12 |
13 | 14 |
    15 | {% for book in object_list %} 16 | 18 | 19 | 20 |
    21 |
    22 | Generic placeholder thumbnail 23 | 24 | 25 |
    26 |

    {{book.name}}

    27 |

    {{book.author}}

    28 | 29 |

    30 | 31 | Details 32 | 33 | 34 | 35 | Delete 36 | 37 |

    38 |
    39 |
    40 | 41 | 42 |
    43 | 44 | {% endfor %} 45 |
46 | {% endblock %} -------------------------------------------------------------------------------- /section-15-make-web-applications-with-python-using-django-2.0/.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | db.sqlite3 -------------------------------------------------------------------------------- /section-15-make-web-applications-with-python-using-django-2.0/image/image-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-15-make-web-applications-with-python-using-django-2.0/image/image-1.png -------------------------------------------------------------------------------- /section-15-make-web-applications-with-python-using-django-2.0/image/image-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-15-make-web-applications-with-python-using-django-2.0/image/image-2.png -------------------------------------------------------------------------------- /section-15-make-web-applications-with-python-using-django-2.0/image/image-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-15-make-web-applications-with-python-using-django-2.0/image/image-3.png -------------------------------------------------------------------------------- /section-15-make-web-applications-with-python-using-django-2.0/image/image-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-15-make-web-applications-with-python-using-django-2.0/image/image-4.png -------------------------------------------------------------------------------- /section-15-make-web-applications-with-python-using-django-2.0/photo-project/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "photo.settings") 7 | try: 8 | from django.core.management import execute_from_command_line 9 | except ImportError as exc: 10 | raise ImportError( 11 | "Couldn't import Django. Are you sure it's installed and " 12 | "available on your PYTHONPATH environment variable? Did you " 13 | "forget to activate a virtual environment?" 14 | ) from exc 15 | execute_from_command_line(sys.argv) 16 | -------------------------------------------------------------------------------- /section-15-make-web-applications-with-python-using-django-2.0/photo-project/photo/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-15-make-web-applications-with-python-using-django-2.0/photo-project/photo/__init__.py -------------------------------------------------------------------------------- /section-15-make-web-applications-with-python-using-django-2.0/photo-project/photo/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for photo project. 3 | 4 | Generated by 'django-admin startproject' using Django 2.0. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.0/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/2.0/ref/settings/ 11 | """ 12 | 13 | import os 14 | 15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'csgw%(xes*#f_^b^d$k2gq&%_t5b%%92hx$gltc&hywde)m%#q' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = [] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'photoapp.apps.PhotoappConfig', 35 | 'django.contrib.admin', 36 | 'django.contrib.auth', 37 | 'django.contrib.contenttypes', 38 | 'django.contrib.sessions', 39 | 'django.contrib.messages', 40 | 'django.contrib.staticfiles', 41 | ] 42 | 43 | MIDDLEWARE = [ 44 | 'django.middleware.security.SecurityMiddleware', 45 | 'django.contrib.sessions.middleware.SessionMiddleware', 46 | 'django.middleware.common.CommonMiddleware', 47 | 'django.middleware.csrf.CsrfViewMiddleware', 48 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 49 | 'django.contrib.messages.middleware.MessageMiddleware', 50 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 51 | ] 52 | 53 | ROOT_URLCONF = 'photo.urls' 54 | 55 | TEMPLATES = [ 56 | { 57 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 58 | 'DIRS': [os.path.join(BASE_DIR, 'templates')], 59 | 'APP_DIRS': True, 60 | 'OPTIONS': { 61 | 'context_processors': [ 62 | 'django.template.context_processors.debug', 63 | 'django.template.context_processors.request', 64 | 'django.contrib.auth.context_processors.auth', 65 | 'django.contrib.messages.context_processors.messages', 66 | ], 67 | }, 68 | }, 69 | ] 70 | 71 | WSGI_APPLICATION = 'photo.wsgi.application' 72 | 73 | 74 | # Database 75 | # https://docs.djangoproject.com/en/2.0/ref/settings/#databases 76 | 77 | DATABASES = { 78 | 'default': { 79 | 'ENGINE': 'django.db.backends.sqlite3', 80 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 81 | } 82 | } 83 | 84 | 85 | # Password validation 86 | # https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators 87 | 88 | AUTH_PASSWORD_VALIDATORS = [ 89 | { 90 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 91 | }, 92 | { 93 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 94 | }, 95 | { 96 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 97 | }, 98 | { 99 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 100 | }, 101 | ] 102 | 103 | 104 | # Internationalization 105 | # https://docs.djangoproject.com/en/2.0/topics/i18n/ 106 | 107 | LANGUAGE_CODE = 'en-us' 108 | 109 | TIME_ZONE = 'UTC' 110 | 111 | USE_I18N = True 112 | 113 | USE_L10N = True 114 | 115 | USE_TZ = True 116 | 117 | 118 | # Static files (CSS, JavaScript, Images) 119 | # https://docs.djangoproject.com/en/2.0/howto/static-files/ 120 | 121 | STATIC_URL = '/static/' 122 | -------------------------------------------------------------------------------- /section-15-make-web-applications-with-python-using-django-2.0/photo-project/photo/urls.py: -------------------------------------------------------------------------------- 1 | """photo URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/2.0/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import path, include 18 | 19 | urlpatterns = [ 20 | path('admin/', admin.site.urls), 21 | path('photo/', include('photoapp.urls')), 22 | ] 23 | -------------------------------------------------------------------------------- /section-15-make-web-applications-with-python-using-django-2.0/photo-project/photo/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for photo project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "photo.settings") 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /section-15-make-web-applications-with-python-using-django-2.0/photo-project/photoapp/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-15-make-web-applications-with-python-using-django-2.0/photo-project/photoapp/__init__.py -------------------------------------------------------------------------------- /section-15-make-web-applications-with-python-using-django-2.0/photo-project/photoapp/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /section-15-make-web-applications-with-python-using-django-2.0/photo-project/photoapp/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class PhotoappConfig(AppConfig): 5 | name = 'photoapp' 6 | -------------------------------------------------------------------------------- /section-15-make-web-applications-with-python-using-django-2.0/photo-project/photoapp/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | # Create your models here. 3 | from django.db.models import CharField 4 | 5 | 6 | class Photo(models.Model): 7 | name = models.CharField(max_length=100) 8 | creator: CharField = models.CharField(max_length=100) 9 | price = models.CharField(max_length=100) 10 | 11 | def __str__(self): 12 | return self.name + '-' + self.creator 13 | -------------------------------------------------------------------------------- /section-15-make-web-applications-with-python-using-django-2.0/photo-project/photoapp/static/photoapp/back-ground.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-15-make-web-applications-with-python-using-django-2.0/photo-project/photoapp/static/photoapp/back-ground.jpg -------------------------------------------------------------------------------- /section-15-make-web-applications-with-python-using-django-2.0/photo-project/photoapp/static/photoapp/style.css: -------------------------------------------------------------------------------- 1 | .body { 2 | color: #ff0000; 3 | } 4 | .h1 { 5 | color: yellow; 6 | } 7 | -------------------------------------------------------------------------------- /section-15-make-web-applications-with-python-using-django-2.0/photo-project/photoapp/templates/photoapp/detail.html: -------------------------------------------------------------------------------- 1 |

{{photo.id}}

2 |

{{photo.name}}

3 |

{{photo.creator}}

4 |

{{photo.price}}

-------------------------------------------------------------------------------- /section-15-make-web-applications-with-python-using-django-2.0/photo-project/photoapp/templates/photoapp/index.html: -------------------------------------------------------------------------------- 1 | {% load static %} 2 | 3 | 4 | 5 | 6 | Title 7 | 8 | 9 | 10 | 11 |

Khoa

12 |
    13 | {% for photo in all_photo %} 14 |
  • 15 | {{photo.name}} 16 |
  • 17 | {%endfor%} 18 |
19 | 20 | -------------------------------------------------------------------------------- /section-15-make-web-applications-with-python-using-django-2.0/photo-project/photoapp/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /section-15-make-web-applications-with-python-using-django-2.0/photo-project/photoapp/urls.py: -------------------------------------------------------------------------------- 1 | from django.conf.urls import url 2 | from django.urls import path 3 | from . import views 4 | 5 | app_name = 'photo' 6 | 7 | urlpatterns = [ 8 | path('', views.index, name='index'), 9 | path('/', views.detail, name='detail'), 10 | ] 11 | -------------------------------------------------------------------------------- /section-15-make-web-applications-with-python-using-django-2.0/photo-project/photoapp/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | from django.http.response import HttpResponse 3 | from .models import Photo 4 | from django.template import loader 5 | from django.shortcuts import render 6 | from django.http import Http404 7 | 8 | 9 | # Create your views here. 10 | 11 | 12 | def index(request): 13 | all_photo = Photo.objects.all() 14 | context = { 15 | 'all_photo': all_photo 16 | } 17 | return render(request, 'photoapp/index.html', context) 18 | 19 | 20 | def detail(request, photo_id): 21 | all_photo = Photo.objects.get(id= photo_id) 22 | context = { 23 | 'photo' : all_photo 24 | } 25 | return render(request, 'photoapp/detail.html', context) -------------------------------------------------------------------------------- /section-17-building-rest-api's-with-python-and-django/apidemo/apidemo/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-17-building-rest-api's-with-python-and-django/apidemo/apidemo/__init__.py -------------------------------------------------------------------------------- /section-17-building-rest-api's-with-python-and-django/apidemo/apidemo/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-17-building-rest-api's-with-python-and-django/apidemo/apidemo/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /section-17-building-rest-api's-with-python-and-django/apidemo/apidemo/__pycache__/settings.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-17-building-rest-api's-with-python-and-django/apidemo/apidemo/__pycache__/settings.cpython-36.pyc -------------------------------------------------------------------------------- /section-17-building-rest-api's-with-python-and-django/apidemo/apidemo/__pycache__/urls.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-17-building-rest-api's-with-python-and-django/apidemo/apidemo/__pycache__/urls.cpython-36.pyc -------------------------------------------------------------------------------- /section-17-building-rest-api's-with-python-and-django/apidemo/apidemo/__pycache__/wsgi.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-17-building-rest-api's-with-python-and-django/apidemo/apidemo/__pycache__/wsgi.cpython-36.pyc -------------------------------------------------------------------------------- /section-17-building-rest-api's-with-python-and-django/apidemo/apidemo/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for apidemo project. 3 | 4 | Generated by 'django-admin startproject' using Django 1.11.4. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/1.11/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/1.11/ref/settings/ 11 | """ 12 | 13 | import os 14 | 15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'g*i*p1qoq_(vmu(2!jexg7^55yf=4od5lqu5)^s1031yy(-%)*' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = [] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'rest_framework', 35 | 'app', 36 | 'django.contrib.admin', 37 | 'django.contrib.auth', 38 | 'django.contrib.contenttypes', 39 | 'django.contrib.sessions', 40 | 'django.contrib.messages', 41 | 'django.contrib.staticfiles', 42 | 'django_filters' 43 | ] 44 | 45 | MIDDLEWARE = [ 46 | 'django.middleware.security.SecurityMiddleware', 47 | 'django.contrib.sessions.middleware.SessionMiddleware', 48 | 'django.middleware.common.CommonMiddleware', 49 | 'django.middleware.csrf.CsrfViewMiddleware', 50 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 51 | 'django.contrib.messages.middleware.MessageMiddleware', 52 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 53 | ] 54 | 55 | ROOT_URLCONF = 'apidemo.urls' 56 | 57 | TEMPLATES = [ 58 | { 59 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 60 | 'DIRS': [], 61 | 'APP_DIRS': True, 62 | 'OPTIONS': { 63 | 'context_processors': [ 64 | 'django.template.context_processors.debug', 65 | 'django.template.context_processors.request', 66 | 'django.contrib.auth.context_processors.auth', 67 | 'django.contrib.messages.context_processors.messages', 68 | ], 69 | }, 70 | }, 71 | ] 72 | 73 | WSGI_APPLICATION = 'apidemo.wsgi.application' 74 | 75 | 76 | # Database 77 | # https://docs.djangoproject.com/en/1.11/ref/settings/#databases 78 | 79 | DATABASES = { 80 | 'default': { 81 | 'ENGINE': 'django.db.backends.sqlite3', 82 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 83 | } 84 | } 85 | 86 | 87 | # Password validation 88 | # https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators 89 | 90 | AUTH_PASSWORD_VALIDATORS = [ 91 | { 92 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 93 | }, 94 | { 95 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 96 | }, 97 | { 98 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 99 | }, 100 | { 101 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 102 | }, 103 | ] 104 | 105 | 106 | # Internationalization 107 | # https://docs.djangoproject.com/en/1.11/topics/i18n/ 108 | 109 | LANGUAGE_CODE = 'en-us' 110 | 111 | TIME_ZONE = 'UTC' 112 | 113 | USE_I18N = True 114 | 115 | USE_L10N = True 116 | 117 | USE_TZ = True 118 | 119 | 120 | # Static files (CSS, JavaScript, Images) 121 | # https://docs.djangoproject.com/en/1.11/howto/static-files/ 122 | 123 | STATIC_URL = '/static/' 124 | MEDIA_ROOT = os.path.join(BASE_DIR, 'media') 125 | MEDIA_URL = '/media/' 126 | 127 | LOGIN_REDIRECT = '/task' -------------------------------------------------------------------------------- /section-17-building-rest-api's-with-python-and-django/apidemo/apidemo/urls.py: -------------------------------------------------------------------------------- 1 | """apidemo URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/1.11/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.conf.urls import url, include 14 | 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) 15 | """ 16 | from django.conf.urls import include, url 17 | from django.contrib import admin 18 | from rest_framework import routers 19 | from app.views import TaskViewSet, CreateUserView 20 | from app import views 21 | from django.conf.urls.static import static 22 | from django.conf import settings 23 | router = routers.DefaultRouter() 24 | # router = routers.SimpleRouter() 25 | router.register(r'task', views.TaskViewSet) 26 | # router.register(r'completed_task', views.CompletedTaskViewSet) 27 | # router.register(r'due_task', views.DueTaskViewSet) 28 | 29 | urlpatterns = [ 30 | url(r'^register/$', views.CreateUserView.as_view(),name='user'), 31 | url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')), 32 | url(r'^', include(router.urls)), 33 | url(r'^admin/', admin.site.urls), 34 | ]+ static(settings.MEDIA_URL, document_root= settings.MEDIA_ROOT) 35 | -------------------------------------------------------------------------------- /section-17-building-rest-api's-with-python-and-django/apidemo/apidemo/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for apidemo project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "apidemo.settings") 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /section-17-building-rest-api's-with-python-and-django/apidemo/app/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-17-building-rest-api's-with-python-and-django/apidemo/app/__init__.py -------------------------------------------------------------------------------- /section-17-building-rest-api's-with-python-and-django/apidemo/app/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-17-building-rest-api's-with-python-and-django/apidemo/app/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /section-17-building-rest-api's-with-python-and-django/apidemo/app/__pycache__/admin.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-17-building-rest-api's-with-python-and-django/apidemo/app/__pycache__/admin.cpython-36.pyc -------------------------------------------------------------------------------- /section-17-building-rest-api's-with-python-and-django/apidemo/app/__pycache__/models.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-17-building-rest-api's-with-python-and-django/apidemo/app/__pycache__/models.cpython-36.pyc -------------------------------------------------------------------------------- /section-17-building-rest-api's-with-python-and-django/apidemo/app/__pycache__/serializers.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-17-building-rest-api's-with-python-and-django/apidemo/app/__pycache__/serializers.cpython-36.pyc -------------------------------------------------------------------------------- /section-17-building-rest-api's-with-python-and-django/apidemo/app/__pycache__/views.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-17-building-rest-api's-with-python-and-django/apidemo/app/__pycache__/views.cpython-36.pyc -------------------------------------------------------------------------------- /section-17-building-rest-api's-with-python-and-django/apidemo/app/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import Task 3 | # Register your models here. 4 | 5 | 6 | admin.site.register(Task) 7 | -------------------------------------------------------------------------------- /section-17-building-rest-api's-with-python-and-django/apidemo/app/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class AppConfig(AppConfig): 5 | name = 'app' 6 | -------------------------------------------------------------------------------- /section-17-building-rest-api's-with-python-and-django/apidemo/app/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | 4 | # Create your models here. 5 | 6 | class Task(models.Model): 7 | task_name = models.CharField(max_length=200) 8 | task_desc = models.CharField(max_length=200) 9 | date_created = models.DateTimeField(auto_now=True) 10 | completed = models.BooleanField(default=False) 11 | image = models.ImageField(upload_to='Images/', default='Images/None/No0img.jpg') 12 | -------------------------------------------------------------------------------- /section-17-building-rest-api's-with-python-and-django/apidemo/app/serializers.py: -------------------------------------------------------------------------------- 1 | from .models import Task 2 | from rest_framework import serializers 3 | from django.contrib.auth import get_user_model 4 | 5 | 6 | class UserSerializer(serializers.ModelSerializer): 7 | password = serializers.CharField(write_only=True) 8 | 9 | def create(self, validated_data): 10 | user = get_user_model().objects.create( 11 | username=validated_data['username'] 12 | ) 13 | user.set_password(validated_data['password']) 14 | user.save() 15 | return user 16 | 17 | class Meta: 18 | model = get_user_model() 19 | fields = ('username', 'password') 20 | 21 | 22 | class TaskSerializers(serializers.ModelSerializer): 23 | image = serializers.ImageField(max_length=None, use_url=True) 24 | 25 | class Meta: 26 | model = Task 27 | fields = ('id', 'task_name', 'task_desc', 'completed', 'date_created', 'image') 28 | -------------------------------------------------------------------------------- /section-17-building-rest-api's-with-python-and-django/apidemo/app/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /section-17-building-rest-api's-with-python-and-django/apidemo/app/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | from rest_framework import viewsets 3 | from .serializers import TaskSerializers, UserSerializer 4 | from .models import Task 5 | from rest_framework import filters 6 | from rest_framework.permissions import IsAuthenticated, AllowAny 7 | from django.contrib.auth import get_user_model 8 | from rest_framework.generics import CreateAPIView 9 | 10 | # Create your views here. 11 | 12 | class TaskViewSet(viewsets.ModelViewSet): 13 | permission_classes = (IsAuthenticated,) 14 | queryset = Task.objects.all().order_by('-date_created') 15 | serializer_class = TaskSerializers 16 | filter_backends = (filters.DjangoFilterBackend, filters.OrderingFilter, filters.SearchFilter) 17 | filter_fields = ('completed',) 18 | ordering = ('-date_created',) 19 | search_fields = ('task_name', ) 20 | 21 | class CreateUserView(CreateAPIView): 22 | model = get_user_model() 23 | permission_classes = (AllowAny,) 24 | serializer_class = UserSerializer 25 | 26 | ''' 27 | class DueTaskViewSet(viewsets.ModelViewSet): 28 | queryset = Task.objects.all().order_by('-date_created').filter(completed=False) 29 | serializer_class = TaskSerializers 30 | 31 | 32 | class CompletedTaskViewSet(viewsets.ModelViewSet): 33 | queryset = Task.objects.all().order_by('-date_created').filter(completed=True) 34 | serializer_class = TaskSerializers 35 | ''' 36 | -------------------------------------------------------------------------------- /section-17-building-rest-api's-with-python-and-django/apidemo/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "apidemo.settings") 7 | try: 8 | from django.core.management import execute_from_command_line 9 | except ImportError: 10 | # The above import may fail for some other reason. Ensure that the 11 | # issue is really that Django is missing to avoid masking other 12 | # exceptions on Python 2. 13 | try: 14 | import django 15 | except ImportError: 16 | raise ImportError( 17 | "Couldn't import Django. Are you sure it's installed and " 18 | "available on your PYTHONPATH environment variable? Did you " 19 | "forget to activate a virtual environment?" 20 | ) 21 | raise 22 | execute_from_command_line(sys.argv) 23 | -------------------------------------------------------------------------------- /section-17-building-rest-api's-with-python-and-django/apidemo/media/Images/image-3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-17-building-rest-api's-with-python-and-django/apidemo/media/Images/image-3.jpg -------------------------------------------------------------------------------- /section-17-building-rest-api's-with-python-and-django/apidemo/media/Images/image9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-17-building-rest-api's-with-python-and-django/apidemo/media/Images/image9.png -------------------------------------------------------------------------------- /section-17-building-rest-api's-with-python-and-django/image/image-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-17-building-rest-api's-with-python-and-django/image/image-1.png -------------------------------------------------------------------------------- /section-17-building-rest-api's-with-python-and-django/image/image-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-17-building-rest-api's-with-python-and-django/image/image-2.png -------------------------------------------------------------------------------- /section-17-building-rest-api's-with-python-and-django/image/image-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-17-building-rest-api's-with-python-and-django/image/image-3.png -------------------------------------------------------------------------------- /section-17-building-rest-api's-with-python-and-django/image/image-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-17-building-rest-api's-with-python-and-django/image/image-4.png -------------------------------------------------------------------------------- /section-17-building-rest-api's-with-python-and-django/image/image-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-17-building-rest-api's-with-python-and-django/image/image-5.png -------------------------------------------------------------------------------- /section-17-building-rest-api's-with-python-and-django/image/image-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-17-building-rest-api's-with-python-and-django/image/image-6.png -------------------------------------------------------------------------------- /section-17-building-rest-api's-with-python-and-django/image/image-7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-17-building-rest-api's-with-python-and-django/image/image-7.png -------------------------------------------------------------------------------- /section-18-learn-how-to-crawl-websites-using-python-web-crawling/demo.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | 4 | def create_project_dir(directory): 5 | if not os.path.exists(directory): 6 | print('Creating the directory' + directory) 7 | os.makedirs(directory) 8 | 9 | 10 | def create_data_files(project_name, base_url): 11 | queue = os.path.join(project_name, 'queue.txt') 12 | crawled = os.path.join(project_name, "crawled.txt") 13 | if not os.path.isfile(queue): 14 | write_file(queue, base_url) 15 | if not os.path.isfile(crawled): 16 | write_file(crawled, '') 17 | 18 | 19 | def write_file(path, data): 20 | with open(path, 'w') as f: 21 | f.write(data) 22 | 23 | 24 | def append_to_file(path, data): 25 | with open(path, 'a') as f: 26 | f.write(data, '\n') 27 | 28 | 29 | def delete_file_contents(path): 30 | open(path, 'w').close() 31 | 32 | 33 | def file_to_set(file_name): 34 | results = set() 35 | with open(file_name, 'rt') as f: 36 | for line in f: 37 | results.add(line.replace('\n', '')) 38 | return results 39 | 40 | 41 | def set_to_file(links, file_name): 42 | with open(file_name, "w") as f: 43 | for l in sorted(links): 44 | f.write(l + "\n") -------------------------------------------------------------------------------- /section-18-learn-how-to-crawl-websites-using-python-web-crawling/domain.py: -------------------------------------------------------------------------------- 1 | from urllib.parse import urlparse 2 | 3 | 4 | def get_domain_name(url): 5 | try: 6 | results = get_sub_domain_name(url).split('.') 7 | return results[-2] + '.' + results[-1] 8 | except: 9 | return '' 10 | 11 | 12 | def get_sub_domain_name(url): 13 | try: 14 | return urlparse(url).netloc 15 | except: 16 | return '' -------------------------------------------------------------------------------- /section-18-learn-how-to-crawl-websites-using-python-web-crawling/image/image-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-18-learn-how-to-crawl-websites-using-python-web-crawling/image/image-1.png -------------------------------------------------------------------------------- /section-18-learn-how-to-crawl-websites-using-python-web-crawling/image/image-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-18-learn-how-to-crawl-websites-using-python-web-crawling/image/image-2.png -------------------------------------------------------------------------------- /section-18-learn-how-to-crawl-websites-using-python-web-crawling/link_finder.py: -------------------------------------------------------------------------------- 1 | from html.parser import HTMLParser 2 | from urllib import parse 3 | 4 | 5 | class LinkFinder(HTMLParser): 6 | 7 | def __init__(self, base_url, page_url): 8 | super().__init__() 9 | self.base_url = base_url 10 | self.page_url = page_url 11 | self.links = set() 12 | 13 | def error(self, message): 14 | pass 15 | 16 | def handle_starttag(self, tag, attrs): 17 | if tag == 'a': 18 | for (attribute, value) in attrs: 19 | if attribute == 'href': 20 | url = parse.urljoin(self.base_url, value) 21 | self.links.add(url) 22 | 23 | def page_links(self): 24 | return self.links -------------------------------------------------------------------------------- /section-18-learn-how-to-crawl-websites-using-python-web-crawling/main.py: -------------------------------------------------------------------------------- 1 | import threading 2 | from queue import Queue 3 | from spider import Spider 4 | from domain import * 5 | from demo import * 6 | PROJECT_NAME ='thesite' 7 | HOMEPAGE = 'https://www.djangoadmintutorials.com/' 8 | DOMAIN_NAME = get_domain_name(HOMEPAGE) 9 | QUEUE_FILE = PROJECT_NAME + '/queue.txt' 10 | CRAWLED_FILE = PROJECT_NAME + '/crawled.txt' 11 | NUMBER_OF_THREADS = 8 12 | queue= Queue() 13 | Spider(PROJECT_NAME,HOMEPAGE,DOMAIN_NAME) 14 | 15 | 16 | def crawl(): 17 | queued_links = file_to_set(QUEUE_FILE) 18 | if len(queued_links) > 0: 19 | print(str(len(queued_links)) + ' Links in the queue ') 20 | create_jobs() 21 | 22 | 23 | def create_jobs(): 24 | for link in file_to_set(QUEUE_FILE): 25 | queue.put(link) 26 | queue.join() 27 | crawl() 28 | 29 | 30 | def create_workers(): 31 | for _ in range(NUMBER_OF_THREADS): 32 | t = threading.Thread(target=work) 33 | t.daemon = True 34 | t.start() 35 | 36 | 37 | def work(): 38 | while True: 39 | url = queue.get() 40 | Spider.crawl_page(threading.current_thread().name, url) 41 | queue.task_done() 42 | 43 | 44 | create_workers() 45 | crawl() -------------------------------------------------------------------------------- /section-18-learn-how-to-crawl-websites-using-python-web-crawling/spider.py: -------------------------------------------------------------------------------- 1 | from urllib.request import urlopen 2 | from link_finder import LinkFinder 3 | from demo import * 4 | from domain import * 5 | 6 | 7 | class Spider: 8 | project_name = '' 9 | base_url = '' 10 | domain_name = '' 11 | queue_file = '' 12 | crawled_file = '' 13 | queue = set() 14 | crawled = set() 15 | 16 | def __init__(self, project_name, base_url, domain_name): 17 | Spider.project_name = project_name 18 | Spider.base_url = base_url 19 | Spider.domain_name = domain_name 20 | Spider.queue_file = Spider.project_name + '/queue.txt' 21 | Spider.crawled_file = Spider.project_name + '/crawled.txt' 22 | self.boot() 23 | self.crawl_page('First spider', Spider.base_url) 24 | 25 | @staticmethod 26 | def boot(): 27 | create_project_dir(Spider.project_name) 28 | create_data_files(Spider.project_name, Spider.base_url) 29 | Spider.queue = file_to_set(Spider.queue_file) 30 | Spider.crawled = file_to_set(Spider.crawled_file) 31 | 32 | @staticmethod 33 | def crawl_page(thread_name, page_url): 34 | if page_url not in Spider.crawled: 35 | print(thread_name + 'Now crawling ' + page_url) 36 | print('Queue' + str(len(Spider.queue)) + ' | Crawled ' + str(len(Spider.crawled))) 37 | Spider.add_links_to_queue(Spider.gather_links(page_url)) 38 | Spider.queue.remove(page_url) 39 | Spider.crawled.add(page_url) 40 | Spider.update_files() 41 | 42 | @staticmethod 43 | def gather_links(page_url): 44 | html_string = '' 45 | try: 46 | response = urlopen(page_url) 47 | if 'text/html' in response.getheader('Content-Type'): 48 | html_bytes = response.read() 49 | html_string = html_bytes.decode("utf-8") 50 | finder = LinkFinder(Spider.base_url, page_url) 51 | finder.feed(html_string) 52 | except Exception as e: 53 | print(str(e)) 54 | return set() 55 | return finder.page_links() 56 | 57 | @staticmethod 58 | def add_links_to_queue(links): 59 | for url in links: 60 | if (url in Spider.queue) or (url in Spider.crawled): 61 | continue 62 | if Spider.domain_name != get_domain_name(url): 63 | continue 64 | Spider.queue.add(url) 65 | 66 | @staticmethod 67 | def update_files(): 68 | set_to_file(Spider.queue, Spider.queue_file) 69 | set_to_file(Spider.crawled, Spider.crawled_file) -------------------------------------------------------------------------------- /section-18-learn-how-to-crawl-websites-using-python-web-crawling/thesite/crawled.txt: -------------------------------------------------------------------------------- 1 | https://br.wikipedia.org/wiki/ 2 | https://gn.wikipedia.org/wiki/ 3 | https://ku.wikipedia.org/ 4 | https://ku.wikipedia.org/w/index.php?title=Destp%C3%AAk&action=purge 5 | https://kv.wikipedia.org/ 6 | https://www.djangoadmintutorials.com/ 7 | https://www.djangoadmintutorials.com/how-to-customize-django-admin-index-page-and-add-a-chart/ 8 | https://www.djangoadmintutorials.com/w/index.php?title=%D0%9E%D1%82%D1%81%D0%B0%D1%81%D1%8F%D0%BD:ElectronPdf&page=%D0%9C%D0%B5%D0%B4%D1%88%D3%A7%D1%80+%D0%BB%D0%B8%D1%81%D1%82+%D0%B1%D0%BE%D0%BA&action=show-download-screen 9 | https://www.djangoadmintutorials.com/w/index.php?title=Ape&action=info 10 | https://www.djangoadmintutorials.com/wiki/%D0%9A%D0%BE%D0%BC%D0%B8_%D1%80%D0%B5%D1%81%D0%BF%D1%83%D0%B1%D0%BB%D0%B8%D0%BA%D0%B0 11 | https://www.djangoadmintutorials.com/wiki/Wikimedia_Foundation 12 | https://www.wikipedia.org/ 13 | -------------------------------------------------------------------------------- /section-18-learn-how-to-crawl-websites-using-python-web-crawling/thesite/queue.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-18-learn-how-to-crawl-websites-using-python-web-crawling/thesite/queue.txt -------------------------------------------------------------------------------- /section-19-complex-python-challenges/README.md: -------------------------------------------------------------------------------- 1 | # Section 19: Complex Python Challenges 2 | ## Lesson overview 3 | ### Challenge 1: Tile contractor app. 4 | - A tile contractor charges for his work in terms of tiles fitted per square feet, example if he charges `20$/square` feet means for `100sqft` the charges would be `$2000` You want to build a simple calculator for him so that he can quote a final amount to his customer. 5 | - Level 1: 6 | The calculator should have the following features: 7 | 1. Should accept inputs as the length and breadth of the room to be tiled. 8 | 2. Should give an option to offer discount in terms of percentage. 9 | 3. Should give output as total area covered, total discount in terms of $, the total amount customer has to pay. 10 | - [Code](code/chanllenge-1-1.py) 11 | 12 | 13 | ![Image](image/image-1.png) 14 | - Level 2: 15 | 1. Try accepting length values in different units, build a separate function to convert unit from meter to feet. 16 | 2. Try to make the above calculator in the form of a GUI using Tkinter. 17 | 3. Try to optimize the code. i.e. Try to use less variables and less redundancies. 18 | - [Code](code/chanllenge-1-2.py) 19 | 20 | 21 | ![Image](image/image-2.png) 22 | 23 | 24 | 25 | ### Challenge 2: Tax calculator. 26 | - A particular state in XYZ country charges taxes on its citizen's income. These tax rates varies from person to person depending on income and age and hence they have to pay different taxes.Here are the tax rules laid by the government which states the percent tax for category of individual. 27 | - For taxpayers under 60 years of age: 28 | - annual income up to: $20,000 -> No tax 29 | - annual income from $20,001 to $50,000 -> 20% tax 30 | - annual income from $50,001 to $100,000 -> 30% tax 31 | - annual income above $100,001 -> 40% tax 32 | 33 | - For taxpayers above 60 years of age: 34 | - annual income up to: $20,000 -> No tax 35 | - annual income from $20,001 to $50,000 -> 10% tax 36 | - annual income from $50,001 to $100,000 -> 20% tax 37 | - annual income above $100,001 -> 30% tax 38 | 39 | - Level 1: Build a tax calculator which accepts the age and total income of an individual and calculates the total tax to be paid. 40 | - [Code](code/chanllenge-2-1.py) 41 | 42 | 43 | ![Image](image/image-3.png) 44 | 45 | - Level 2: 46 | 1. Design a GUI for the above code. 47 | 2. Try to add additional category of taxpayers such as businesses and charge them 7.5% additional taxes (considering taxes for age group below 60). 48 | - [Code](code/chanllenge-2-2.py) 49 | 50 | 51 | ![Image](image/image-4.png) 52 | 53 | ### Challenge 3: Text Editor 54 | - Write a Python script to make a notepad like text editor using Tkinter which has the following features. 55 | 56 | - Level 1: 57 | 1. Should be able to save text files. 58 | 2. Should be able to write normal text. 59 | 60 | - Level 2: 61 | 1. Should be able to delete files. 62 | 2. Should be able to edit existing files. 63 | 64 | - Hint: This challenge needs some research on how to implement complex features, feel free to do a google search to figure out how a particular feature can be implemented. 65 | 66 | - [Code](code/chanllenge-3.py) 67 | 68 | 69 | ![Image](image/image-5.png) 70 | 71 | 72 | ### Challenge 4: Product Inventory Project 73 | - Create an application which manages an inventory of products. Create a product class which has a price, id, and quantity on hand. Then create an inventory class which keeps track of various products and can sum up the inventory value. Should have the following features. 74 | 1. Ability to add new products. 75 | 76 | 2. Ability to delete existing products. 77 | 78 | 3. Ability to view product information. 79 | 80 | 4. Ability to edit existing products. 81 | 82 | - [Code](code/chanllenge-4.py) 83 | 84 | 85 | ![Image](image/image-6.png) 86 | 87 | 88 | 89 | 90 | ### Challenge 5: Airline / Hotel Reservation System 91 | - Create a reservation system which books airline seats or hotel rooms. It charges various rates for particular sections of the plane or hotel. Example, first class is going to cost more than coach. Hotel rooms have penthouse suites which cost more. Keep track of when rooms will be available and can be scheduled. 92 | 93 | - Level 1: Design a simple console based app for the above problem statement. 94 | - Level 2: Design a GUI based application. 95 | 96 | 97 | 98 | ### Challenge 6: Build a scientific calculator using Tkinter. 99 | - In one of the sections in the course we already learned about building a simple calculator. For this challenge your job is to build a scientific calculator. 100 | 101 | 102 | 103 | ### Challenge 7: Build a global clock which shows current local timings across the globe. 104 | - Time zones across the world vary differently. Build a watch which shows timings of at least 5 different global locations all at the same time. 105 | - [Code](code/chanllenge-7.py) 106 | 107 | 108 | ![Image](image/image-8.png) 109 | 110 | ### Challenge 8: Real time weather app. 111 | 112 | - Build an app which displays weather data as per your location using an API. 113 | - Description: 114 | 1. The app should display current weather conditions like temperature, pressure and humidity. 115 | 2. User should be able to choose from different locations. 116 | 117 | - Hint: This challenge needs some research as well. Search for some weather data providers which provide an API, read their documentation to know how to use their API to get real time weather data. 118 | - [Code](code/chanllenge-8.py) 119 | 120 | 121 | ![Image](image/image-7.png) 122 | 123 | 124 | ### Challenge 9: Web Crawler 125 | 126 | - Build a web crawler which crawls any real estate listing site of your own choice, collect the property data and save it into a text file. 127 | 128 | -------------------------------------------------------------------------------- /section-19-complex-python-challenges/challenge-7.py: -------------------------------------------------------------------------------- 1 | import requests, json 2 | 3 | base_url1 = "http://worldtimeapi.org/api/timezone/Asia/Ho_Chi_Minh" 4 | base_url2 = "http://worldtimeapi.org/api/timezone/Asia/Hong_Kong" 5 | base_url3 = "http://worldtimeapi.org/api/timezone/America/New_York" 6 | base_url4 = "http://worldtimeapi.org/api/timezone/Asia/Tokyo" 7 | base_url5 = "http://worldtimeapi.org/api/timezone/Europe/London" 8 | 9 | response1 = requests.get(base_url1) 10 | x1 = response1.json() 11 | print(x1["timezone"]) 12 | print(x1["utc_datetime"]) 13 | 14 | response2 = requests.get(base_url2) 15 | x2 = response2.json() 16 | print(x2["timezone"]) 17 | print(x2["utc_datetime"]) 18 | 19 | response3 = requests.get(base_url3) 20 | x3 = response3.json() 21 | print(x2["timezone"]) 22 | print(x2["utc_datetime"]) 23 | 24 | response4 = requests.get(base_url4) 25 | x4 = response4.json() 26 | print(x4["timezone"]) 27 | print(x4["utc_datetime"]) 28 | 29 | response5 = requests.get(base_url5) 30 | x5 = response5.json() 31 | print(x5["timezone"]) 32 | print(x5["utc_datetime"]) 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /section-19-complex-python-challenges/code/challenge-1-1.py: -------------------------------------------------------------------------------- 1 | width = int(input("Enter the width: ")) 2 | height = int(input("Enter the height: ")) 3 | copoun = input("Do you have copoun ? yes or no ") 4 | 5 | 6 | def sumary(width, height, copoun): 7 | s = width * height 8 | count = s * 20 9 | if copoun == "Yes" or copoun =="yes": 10 | values = int(input("Enter the % copoun: ")) 11 | sum = count - (values * count // 100) 12 | return "The total bill is: %s" %sum 13 | else: 14 | return "The total bill is: %s" %count 15 | 16 | print(sumary(width, height, copoun)) 17 | -------------------------------------------------------------------------------- /section-19-complex-python-challenges/code/challenge-1-2.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | from functools import partial 3 | 4 | 5 | def call_result(label_result, n1, n2, n3): 6 | num1 = (n1.get()) 7 | num2 = (n2.get()) 8 | num3 = (n3.get()) 9 | result = int(num1) * int(num2) * 20 10 | label_result.config(text="Result = %d" % result) 11 | return 12 | 13 | 14 | root = tk.Tk() 15 | root.geometry('200x200') 16 | 17 | root.title('Calculator') 18 | 19 | number1 = tk.StringVar() 20 | number2 = tk.StringVar() 21 | number3 = tk.StringVar() 22 | 23 | labelNum1 = tk.Label(root, text="Width").grid(row=1, column=0) 24 | 25 | labelNum2 = tk.Label(root, text="Height").grid(row=2, column=0) 26 | 27 | labelNum3 = tk.Label(root, text="Copoun").grid(row=3, column=0) 28 | 29 | labelResult = tk.Label(root) 30 | 31 | labelResult.grid(row=7, column=2) 32 | 33 | entryNum1 = tk.Entry(root, textvariable=number1).grid(row=1, column=2) 34 | 35 | entryNum2 = tk.Entry(root, textvariable=number2).grid(row=2, column=2) 36 | 37 | entryNum3 = tk.Entry(root, textvariable=number3).grid(row=3, column=2) 38 | 39 | call_result = partial(call_result, labelResult, number1, number2, number3) 40 | 41 | buttonCal = tk.Button(root, text="Calculate", command=call_result).grid(row=4, column=0) 42 | 43 | root.mainloop() -------------------------------------------------------------------------------- /section-19-complex-python-challenges/code/challenge-2-1.py: -------------------------------------------------------------------------------- 1 | def taxamount(price, tax): 2 | cost = price * (tax/100) 3 | totalcost = price + cost 4 | return totalcost 5 | 6 | def butter(): 7 | 8 | price = int(input("Enter the salary in year: ")) 9 | age = int(input("Enter the your age: ")) 10 | if age <= 60: 11 | if price <= 20000: 12 | tax = 0 13 | amount = taxamount(price, tax) 14 | print("The total cost after tip is: " + str(amount)) 15 | elif price >= 20001 and price < 50000: 16 | tax = 20 17 | amount = amount = taxamount(price, tax) 18 | print("The total cost after tip is: " + str(amount)) 19 | elif price >= 50001 and price < 100000: 20 | tax = 30 21 | amount = amount = taxamount(price, tax) 22 | print("The total cost after tip is: " + str(amount)) 23 | else: 24 | tax = 40 25 | amount = amount = taxamount(price, tax) 26 | print("The total cost after tip is: " + str(amount)) 27 | else: 28 | if price <= 20000: 29 | tax = 0 30 | amount = taxamount(price, tax) 31 | print("The total cost after tip is: " + str(amount)) 32 | elif price >= 20001 and price < 50000: 33 | tax = 10 34 | amount = amount = taxamount(price, tax) 35 | print("The total cost after tip is: " + str(amount)) 36 | elif price >= 50001 and price < 100000: 37 | tax = 20 38 | amount = amount = taxamount(price, tax) 39 | print("The total cost after tip is: " + str(amount)) 40 | else: 41 | tax = 30 42 | amount = amount = taxamount(price, tax) 43 | print("The total cost after tip is: " + str(amount)) 44 | butter() -------------------------------------------------------------------------------- /section-19-complex-python-challenges/code/challenge-2-2.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | 3 | def taxamount(price, tax): 4 | cost = price * (tax/100) 5 | totalcost = price + cost 6 | return totalcost 7 | 8 | def butter(): 9 | entryField.delete(0,'end') #Clears the entire entry field from index 0 to 'end 10 | price = int(pricefield.get()) 11 | age = int(agefield.get()) 12 | if age <= 60: 13 | if price <= 20000: 14 | tax = 0 15 | amount = taxamount(price, tax) 16 | entryer.set("The total cost after tip is: " + str(amount)) 17 | elif price >= 20001 and price < 50000: 18 | tax = 20 19 | amount = amount = taxamount(price, tax) 20 | entryer.set("The total cost after tip is: " + str(amount)) 21 | elif price >= 50001 and price < 100000: 22 | tax = 30 23 | amount = amount = taxamount(price, tax) 24 | entryer.set("The total cost after tip is: " + str(amount)) 25 | else: 26 | tax = 40 27 | amount = amount = taxamount(price, tax) 28 | entryer.set("The total cost after tip is: " + str(amount)) 29 | else: 30 | if price <= 20000: 31 | tax = 0 32 | amount = taxamount(price, tax) 33 | entryer.set("The total cost after tip is: " + str(amount)) 34 | elif price >= 20001 and price < 50000: 35 | tax = 10 36 | amount = amount = taxamount(price, tax) 37 | entryer.set("The total cost after tip is: " + str(amount)) 38 | elif price >= 50001 and price < 100000: 39 | tax = 20 40 | amount = amount = taxamount(price, tax) 41 | entryer.set("The total cost after tip is: " + str(amount)) 42 | else: 43 | tax = 30 44 | amount = amount = taxamount(price, tax) 45 | entryer.set("The total cost after tip is: " + str(amount)) 46 | 47 | 48 | 49 | 50 | root = Tk() 51 | 52 | root.title("Milos Tax Calculator") 53 | root.resizable(1,0) 54 | root.columnconfigure(0,weight=1) 55 | root.columnconfigure(1,weight=1) 56 | 57 | entryer = StringVar() 58 | entryField = Entry(root, textvariable=entryer,background="LightYellow2",foreground="blue4",justify=CENTER) 59 | entryField.grid(row=0,column=0,columnspan=2,sticky=W+E) 60 | entryField.columnconfigure(0,weight=1) 61 | 62 | labelage = Label(root, text="Age",background="blue4",foreground="PaleTurquoise1") 63 | labelage.grid(row=1,column=0, sticky=E) 64 | labelprice = Label(root, text="Price",background="blue4",foreground="PaleTurquoise1") 65 | labelprice.grid(row=2,column=0, sticky=E) 66 | 67 | 68 | agefield = Entry(root,background="SkyBlue2",foreground="blue4") 69 | agefield.grid(row=1,column=1,sticky=W) 70 | pricefield = Entry(root,background="SkyBlue2",foreground="blue4") 71 | pricefield.grid(row=2,column=1,sticky=W) 72 | 73 | 74 | button = Button(root, text="Find total cost", command=butter) 75 | button.grid(row=3, columnspan=2) 76 | 77 | 78 | root.mainloop() -------------------------------------------------------------------------------- /section-19-complex-python-challenges/code/challenge-3.py: -------------------------------------------------------------------------------- 1 | import tkinter 2 | import os 3 | from tkinter import * 4 | from tkinter.messagebox import * 5 | from tkinter.filedialog import * 6 | 7 | class Notepad: 8 | 9 | __root = Tk() 10 | 11 | # default window width and height 12 | __thisWidth = 300 13 | __thisHeight = 300 14 | __thisTextArea = Text(__root) 15 | __thisMenuBar = Menu(__root) 16 | __thisFileMenu = Menu(__thisMenuBar, tearoff=0) 17 | __thisEditMenu = Menu(__thisMenuBar, tearoff=0) 18 | __thisHelpMenu = Menu(__thisMenuBar, tearoff=0) 19 | 20 | # To add scrollbar 21 | __thisScrollBar = Scrollbar(__thisTextArea) 22 | __file = None 23 | 24 | def __init__(self,**kwargs): 25 | 26 | # Set icon 27 | try: 28 | self.__root.wm_iconbitmap("Notepad.ico") 29 | except: 30 | pass 31 | 32 | # Set window size (the default is 300x300) 33 | 34 | try: 35 | self.__thisWidth = kwargs['width'] 36 | except KeyError: 37 | pass 38 | 39 | try: 40 | self.__thisHeight = kwargs['height'] 41 | except KeyError: 42 | pass 43 | 44 | # Set the window text 45 | self.__root.title("Untitled - Notepad") 46 | 47 | # Center the window 48 | screenWidth = self.__root.winfo_screenwidth() 49 | screenHeight = self.__root.winfo_screenheight() 50 | 51 | # For left-alling 52 | left = (screenWidth / 2) - (self.__thisWidth / 2) 53 | 54 | # For right-allign 55 | top = (screenHeight / 2) - (self.__thisHeight /2) 56 | 57 | # For top and bottom 58 | self.__root.geometry('%dx%d+%d+%d' % (self.__thisWidth, 59 | self.__thisHeight, 60 | left, top)) 61 | 62 | # To make the textarea auto resizable 63 | self.__root.grid_rowconfigure(0, weight=1) 64 | self.__root.grid_columnconfigure(0, weight=1) 65 | 66 | # Add controls (widget) 67 | self.__thisTextArea.grid(sticky = N + E + S + W) 68 | 69 | # To open new file 70 | self.__thisFileMenu.add_command(label="New", 71 | command=self.__newFile) 72 | 73 | # To open a already existing file 74 | self.__thisFileMenu.add_command(label="Open", 75 | command=self.__openFile) 76 | 77 | # To save current file 78 | self.__thisFileMenu.add_command(label="Save", 79 | command=self.__saveFile) 80 | 81 | # To create a line in the dialog 82 | self.__thisFileMenu.add_separator() 83 | self.__thisFileMenu.add_command(label="Exit", 84 | command=self.__quitApplication) 85 | self.__thisMenuBar.add_cascade(label="File", 86 | menu=self.__thisFileMenu) 87 | 88 | # To give a feature of cut 89 | self.__thisEditMenu.add_command(label="Cut", 90 | command=self.__cut) 91 | 92 | # to give a feature of copy 93 | self.__thisEditMenu.add_command(label="Copy", 94 | command=self.__copy) 95 | 96 | # To give a feature of paste 97 | self.__thisEditMenu.add_command(label="Paste", 98 | command=self.__paste) 99 | 100 | # To give a feature of editing 101 | self.__thisMenuBar.add_cascade(label="Edit", 102 | menu=self.__thisEditMenu) 103 | 104 | # To create a feature of description of the notepad 105 | self.__thisHelpMenu.add_command(label="About Notepad", 106 | command=self.__showAbout) 107 | self.__thisMenuBar.add_cascade(label="Help", 108 | menu=self.__thisHelpMenu) 109 | 110 | self.__root.config(menu=self.__thisMenuBar) 111 | 112 | self.__thisScrollBar.pack(side=RIGHT,fill=Y) 113 | 114 | # Scrollbar will adjust automatically according to the content 115 | self.__thisScrollBar.config(command=self.__thisTextArea.yview) 116 | self.__thisTextArea.config(yscrollcommand=self.__thisScrollBar.set) 117 | 118 | 119 | def __quitApplication(self): 120 | self.__root.destroy() 121 | # exit() 122 | 123 | def __showAbout(self): 124 | showinfo("Notepad","Mrinal Verma") 125 | 126 | def __openFile(self): 127 | 128 | self.__file = askopenfilename(defaultextension=".txt", 129 | filetypes=[("All Files","*.*"), 130 | ("Text Documents","*.txt")]) 131 | 132 | if self.__file == "": 133 | 134 | # no file to open 135 | self.__file = None 136 | else: 137 | 138 | # Try to open the file 139 | # set the window title 140 | self.__root.title(os.path.basename(self.__file) + " - Notepad") 141 | self.__thisTextArea.delete(1.0,END) 142 | 143 | file = open(self.__file,"r") 144 | 145 | self.__thisTextArea.insert(1.0,file.read()) 146 | 147 | file.close() 148 | 149 | 150 | def __newFile(self): 151 | self.__root.title("Untitled - Notepad") 152 | self.__file = None 153 | self.__thisTextArea.delete(1.0,END) 154 | 155 | def __saveFile(self): 156 | 157 | if self.__file == None: 158 | # Save as new file 159 | self.__file = asksaveasfilename(initialfile='Untitled.txt', 160 | defaultextension=".txt", 161 | filetypes=[("All Files","*.*"), 162 | ("Text Documents","*.txt")]) 163 | 164 | if self.__file == "": 165 | self.__file = None 166 | else: 167 | 168 | # Try to save the file 169 | file = open(self.__file,"w") 170 | file.write(self.__thisTextArea.get(1.0,END)) 171 | file.close() 172 | 173 | # Change the window title 174 | self.__root.title(os.path.basename(self.__file) + " - Notepad") 175 | 176 | 177 | else: 178 | file = open(self.__file,"w") 179 | file.write(self.__thisTextArea.get(1.0,END)) 180 | file.close() 181 | 182 | def __cut(self): 183 | self.__thisTextArea.event_generate("<>") 184 | 185 | def __copy(self): 186 | self.__thisTextArea.event_generate("<>") 187 | 188 | def __paste(self): 189 | self.__thisTextArea.event_generate("<>") 190 | 191 | def run(self): 192 | 193 | # Run main application 194 | self.__root.mainloop() 195 | 196 | 197 | 198 | 199 | # Run main application 200 | notepad = Notepad(width=600,height=400) 201 | notepad.run() -------------------------------------------------------------------------------- /section-19-complex-python-challenges/code/challenge-4.py: -------------------------------------------------------------------------------- 1 | class Product: 2 | 3 | def __init__(self, id, price, quantity): 4 | self.id = id 5 | self.price = price 6 | self.quantity = quantity 7 | 8 | def show_info(self): 9 | print(f"Product ID: {self.id}") 10 | print(f"Product Price: {self.price}") 11 | print(f"Product Quantity: {self.quantity}") 12 | 13 | def edit_product(self): 14 | self.id = int(input("Edit Product ID: ")) 15 | self.price = int(input("Edit Product Price: ")) 16 | self.quantity = int(input("Edit Product Quantity: ")) 17 | 18 | product_object = [("ID", "Price", "Quantity"),] 19 | 20 | def program(): 21 | print("Menu management command: \n" 22 | "1. Add new Product \n" 23 | "2. Delete product with id \n" 24 | "3. Show product \n" 25 | "4. Edit product \n" 26 | "5. Exit Program") 27 | choose = input(" Enter the choice: ") 28 | if choose == "1": 29 | num = int(input("Number of products you want to import: ")) 30 | for i in range(0,num): 31 | id = int(input("Enter Product ID: ")) 32 | price = int(input("Enter Product Price: ")) 33 | quantity = int(input("Enter Product Quantity: ")) 34 | product_object.append(Product(id, price, quantity)) 35 | program() 36 | elif choose == "2": 37 | id = int(input("Enter the Product ID for delete: ")) 38 | del product_object[id] 39 | program() 40 | elif choose == "3": 41 | for i in range(1, len(product_object)): 42 | print(product_object[i].show_info()) 43 | program() 44 | elif choose == "4": 45 | id = int(input("Enter the Product ID for edit: ")) 46 | product_object[id].edit_product() 47 | program() 48 | elif choose == "5": 49 | exit() 50 | else: 51 | print("Error command, Try again !!!") 52 | program() 53 | program() -------------------------------------------------------------------------------- /section-19-complex-python-challenges/code/challenge-8.py: -------------------------------------------------------------------------------- 1 | import requests, json 2 | 3 | 4 | api_key = "fb1456186ddbe9e8e8f2a5b8230f5adc" 5 | 6 | base_url = " http://api.openweathermap.org/data/2.5/weather?" 7 | 8 | cityname = input("Enter the City Name: ") 9 | cityname.lower() 10 | url_api = base_url+f"q={cityname}"+f"&appid={api_key}" 11 | 12 | response = requests.get(url_api) 13 | 14 | x = response.json() 15 | 16 | if x["cod"] != "404": 17 | 18 | y = x["main"] 19 | current_temperature = y["temp"] 20 | current_pressure = y["pressure"] 21 | current_humidiy = y["humidity"] 22 | z = x["weather"] 23 | weather_description = z[0]["description"] 24 | print(" Temperature (in kelvin unit) = " + 25 | str(current_temperature) + 26 | "\n atmospheric pressure (in hPa unit) = " + 27 | str(current_pressure) + 28 | "\n humidity (in percentage) = " + 29 | str(current_humidiy) + 30 | "\n description = " + 31 | str(weather_description)) 32 | 33 | else: 34 | print(" City Not Found ") 35 | -------------------------------------------------------------------------------- /section-19-complex-python-challenges/image/image-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-19-complex-python-challenges/image/image-1.png -------------------------------------------------------------------------------- /section-19-complex-python-challenges/image/image-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-19-complex-python-challenges/image/image-2.png -------------------------------------------------------------------------------- /section-19-complex-python-challenges/image/image-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-19-complex-python-challenges/image/image-3.png -------------------------------------------------------------------------------- /section-19-complex-python-challenges/image/image-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-19-complex-python-challenges/image/image-4.png -------------------------------------------------------------------------------- /section-19-complex-python-challenges/image/image-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-19-complex-python-challenges/image/image-5.png -------------------------------------------------------------------------------- /section-19-complex-python-challenges/image/image-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-19-complex-python-challenges/image/image-6.png -------------------------------------------------------------------------------- /section-19-complex-python-challenges/image/image-7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-19-complex-python-challenges/image/image-7.png -------------------------------------------------------------------------------- /section-19-complex-python-challenges/image/image-8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-19-complex-python-challenges/image/image-8.png -------------------------------------------------------------------------------- /section-20-automation-with-selenium-web-driver-and-python/README.md: -------------------------------------------------------------------------------- 1 | # Section 20: Automation With Selenium Web Driver and Python 2 | ## Lesson overview 3 | - Installing Selenium 4 | - Opening a URL 5 | - Automating Google Search 6 | - Find Elements By XPATH 7 | - Clicking Links 8 | - Refreshing a Webpage 9 | - Using Forward and Backward Navigation Buttons 10 | - Scrolling and Getting the Current URL 11 | ### Introduction to Selenium 12 | - Selenium Python bindings provides a simple API to write functional/acceptance tests using Selenium WebDriver. Through Selenium Python API you can access all functionalities of Selenium WebDriver in an intuitive way. 13 | - Selenium Python bindings provide a convenient API to access Selenium WebDrivers like Firefox, Ie, Chrome, Remote etc. The current supported Python versions are 2.7, 3.5 and above. 14 | - This documentation explains Selenium 2 WebDriver API. Selenium 1 / Selenium RC API is not covered here. 15 | ### Installing Selenium 16 | - Install selenium with python 17 | ``` 18 | pip install selenium 19 | ``` 20 | - Install chormedriverm, choose the OS and download 21 | ``` 22 | https://chromedriver.storage.googleapis.com/index.html?path=85.0.4183.38/ 23 | ``` 24 | - Add to path `chormedriver.exe`in Edit the system environment variables 25 | - Choose PATH and click new then paste address foler 26 | 27 | 28 | ![Image 1](image/image-1.png) 29 | ### Opening a URL 30 | - Example code: 31 | ``` 32 | from selenium import webdriver 33 | 34 | driver = webdriver.Chrome() 35 | driver.get("https://www.google.com") 36 | ``` 37 | ### Automating Google Search 38 | - Finf id, class, name of attribute html for your test 39 | - Run scripts 40 | ``` 41 | from selenium import webdriver 42 | from selenium.webdriver.common.keys import Keys 43 | import time 44 | from time import sleep 45 | 46 | 47 | driver = webdriver.Chrome() 48 | driver.get("http://www.google.com") 49 | elem = driver.find_element_by_name('q') 50 | elem.send_keys("Python") 51 | elem.send_keys(Keys.RETURN) 52 | time.sleep(5) 53 | driver.quit() 54 | ``` 55 | ### Find Elements By XPATH 56 | - Types of XPATH 57 | - Absolute XPath: The absolute XPath begins with a single slash "/", which allows you to specify an absolute path to the UI object 58 | - For example, html / body / div [1] / div [2] / form / div / div [3] / div [1] / div / div [2] / div [1] / div [1] / div / div / input 59 | - The similar XPath: Begins with two slashes "//", which allows you to specify a UI object anywhere on the web page, without having to start with the html tag in the path. 60 | - For example: // div // input: allows to retrieve all the input tags that were previously a div tag. 61 | - Several ways to identify elements with XPath 62 | - Identify by the `"@"` attribute 63 | - Identify by the `text ()` attribute 64 | - Identify by using the `OR` and `AND` operators 65 | - Identify by `preceding` and `following` 66 | ### Clicking Links 67 | - Command: 68 | ``` 69 | driver = webdriver.Chrome() 70 | driver.get("http://www.google.com") 71 | elem = driver.find_element_by_link_text("Gmail") 72 | time.sleep(5) # sleep for 5 seconds so you can see the results 73 | elem.click() 74 | ``` 75 | ### Refreshing a Webpage 76 | - Command: 77 | ``` 78 | driver = webdriver.Chrome() 79 | driver.get("http://www.google.com") 80 | elem = driver.find_element_by_link_text("Gmail") 81 | time.sleep(5) # sleep for 5 seconds so you can see the results 82 | elem.click() 83 | time.sleep(5) 84 | driver.refresh() 85 | ``` 86 | ### Using Forward and Backward Navigation Buttons 87 | - Command: 88 | ``` 89 | driver = webdriver.Chrome() 90 | driver.get("http://www.google.com") 91 | elem = driver.find_element_by_link_text("Gmail") 92 | time.sleep(5) # sleep for 5 seconds so you can see the results 93 | elem.click() 94 | time.sleep(5) 95 | driver.back() 96 | time.sleep(5) 97 | driver.forward() 98 | ``` 99 | ### Scrolling and Getting the Current URL 100 | - Access by element, tag, ... at HOME and END in browser 101 | ``` 102 | driver = webdriver.Chrome() 103 | driver.get("http://www.wikipedia.org") 104 | elem = driver.find_element_by_tag_name('html') 105 | time.sleep(5) # sleep for 5 seconds so you can see the results 106 | elem.send_keys(Keys.END) 107 | time.sleep(5) 108 | elem.send_keys(Keys.HOME) 109 | ``` 110 | -------------------------------------------------------------------------------- /section-20-automation-with-selenium-web-driver-and-python/image/image-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KhoaDauTay/learn-python/9f4a256c758909ce399f19944b06fe285e1ec2e3/section-20-automation-with-selenium-web-driver-and-python/image/image-1.png -------------------------------------------------------------------------------- /section-21-building-a-facebook-auto-poster/README.md: -------------------------------------------------------------------------------- 1 | # Section 21: Building A Facebook Auto Poster 2 | ## Lesson overview 3 | - Learn about auto post facebook 4 | ### Coding 5 | ``` 6 | from selenium import webdriver 7 | import time 8 | from selenium.webdriver.common.keys import Keys 9 | from time import sleep 10 | from selenium.common.exceptions import TimeoutException 11 | from selenium.webdriver.support.ui import WebDriverWait 12 | from selenium.webdriver.support.ui import Select 13 | from selenium.webdriver.common.by import By 14 | from selenium.webdriver.support import expected_conditions 15 | from selenium.common.exceptions import NoSuchElementException 16 | 17 | driver = webdriver.Chrome() 18 | driver.get('https://www.facebook.com/') 19 | a = driver.find_element_by_id('email') 20 | a.send_keys('cuonglieu3256@gmail.com') 21 | b = driver.find_element_by_id('pass') 22 | b.send_keys('password') 23 | c = driver.find_element_by_id('loginbutton') 24 | c.click() 25 | post_box = driver.find_element_by_xpath("//*[@name='xhpc_message']") 26 | time.sleep(5) 27 | post_box.click() 28 | time.sleep(5) 29 | post_box.send_keys("Testing using Name not ID.Selenium is easy.") 30 | time.sleep(5) 31 | post_it = driver.find_element_by_xpath("//*[@id='u_0_1a']/div/div[6]/div/ul/li[2]/button") 32 | post_it.click() 33 | ``` 34 | -------------------------------------------------------------------------------- /section-22-python-best-practices-writing-clean-and-efficient-python-code/README.md: -------------------------------------------------------------------------------- 1 | # Section 22: Python Best Practices: Writing Clean & Efficient Python Code 2 | ## Lesson overview 3 | - Learn how to write Readable code 4 | - Learn Identation, Comments conventions 5 | - Learn Name conventions 6 | - Learn use Spacebar or Tab 7 | - Learn about Programming recommendations 8 | ### Writing Clean Python Code: Best Practices part 1 9 | - Readable code 10 | - Naming Conventions 11 | - Code Layout 12 | - Collaboration 13 | - Correct syntax is notenough 14 | ### Writing Clean Python Code: Best Practices part 2 15 | - Identation 16 | - Tab and Space: PEP8 Recommended use space 17 | - Comments 18 | - Limit the length of comments and text strings to 72 characters. 19 | - Use a complete sentence, starting with capital letters. 20 | - Be sure to update your comment when you change your code. 21 | ### Writing Clean Python Code: Best Practices part 3 22 | - Never use single, l, O or I names because they can be mistaken for 1 and 0 23 | - The best way to name a variable is to describe the name it represents. 24 | - Name conventions: 25 | - function: Use lowercase letters. Separate words by underscores. 26 | ``` 27 | function, my_function 28 | ``` 29 | - variables: Use lowercase letters. You can use one character, one word or many words. Separate words by underscores. 30 | ``` 31 | x, var, my_variable 32 | ``` 33 | - class: The first letter of each word is capitalized. Do not separate words with underscores. This spell is called camel case. 34 | ``` 35 | Model, MyClass 36 | ``` 37 | - methods: Use lowercase letters. Separate words by underscores. 38 | ``` 39 | class_method, method 40 | ``` 41 | ### Writing Clean Python Code: Best Practices part 4 42 | - Whitespace in expressions and statements 43 | - Whitespace around binary operators 44 | - Assignments (=, + ==, - =, etc.) 45 | - Comparison (==,! =,>, <, <=,> =) And (is, is not, not in) 46 | - Booleans (and, not, or) 47 | ``` 48 | # Recommended 49 | y = x**2 + 5 50 | z = (x+y) * (x-y) 51 | 52 | # Not Recommended 53 | y = x ** 2 + 5 54 | z = (x + y) * (x - y) 55 | ``` 56 | ### Writing Clean Python Code: Best Practices part 5 57 | - Do not compare boolean values with True or False using equivalent operators 58 | - Use definitions when checking empty strings in an if statement 59 | - Using is not rather than not ... is in the If statement 60 | - Do not use if x: when you mean if x not None 61 | - Use .startswith () and .endswith () instead of slicing 62 | ### Notes 63 | - If you follow all the advice of PEP 8, you can ensure that you will have clean, professional and readable code. This will benefit you as well as potential collaborators and employers. 64 | - However, some of the PEP 8 guidelines are inconvenient in the following situations: 65 | - Compliance with PEP 8 will break compatibility with existing software. 66 | - If the code around what you are doing is not compliant with PEP 8. 67 | - If the code needs to remain compatible with older versions of Python. -------------------------------------------------------------------------------- /section-23-network-programming-in-python-using-sockets-building-a-chat-application/README.md: -------------------------------------------------------------------------------- 1 | # Section 23: Network Programming In Python Using Sockets : Building A Chat Application 2 | ## Lesson overview 3 | ### IP Address 4 | - IP address: IP or Internet Protocol is a digital address available on any device connected to the network to share data with the Internet connection protocol 5 | - Static IP 6 | - A static IP address is simply an address that doesn't change. Once your device is assigned a static IP address, that number typically stays the same until the device is decommissioned or your network architecture changes. Static IP addresses generally are used by servers or other important equipment. 7 | - Dynamic IP 8 | - Dynamic IP addresses are subject to change, sometimes at a moment's notice. Dynamic addresses are assigned, as needed, by Dynamic Host Configuration Protocol (DHCP) servers. 9 | 10 | --------------------------------------------------------------------------------