Professional Documents
Culture Documents
05 Python Projects For Noob 5
05 Python Projects For Noob 5
05 Python Projects For Noob 5
Source Code:
from urllib.request import urlopenimport time
def get_load_time(url):
"This function takes a user defined url as input
and returns the time taken to load that url in seconds.
Args:
url (string): The user defined url.
Returns:
time_to_load (float): The time taken to load the website in seconds.
if (“https" or "http") in url: # Checking for presence of protocols
open_this_url = urlopen(url) # Open the url as entered by the user
else:
open_this_url = urlopen("https://" + url) # Adding https to the url
start_time = time.time() # Time stamp before the reading of url starts
open_this_url.read() # Reading the user defined url
end_time = time.time() # Time stamp after the reading of the url
open_this_url.close() # Closing the instance of the urlopen object
time_to_load = end_time - start_time
return time_to_loadif ___name__ == '_main
url = input(“Enter the url whose loading time you want to check: ")
print(f"\nThe time taken to load {url} is {get_load_time(url):.2} seconds.")23. Todo App using flask
+## Perform Operation like
1. Add Task
2. Delete Task
3. Update Task
#To run app
- Create virtual Environment
= Install requirements
*pip install requirements.txt”
=run app
“py app-py”
*Requirements*
Flask==1.1.2
Flask-SQLAlchem
Source code:
from flask import Flask, render_template, url_for, request, redirect
from flask_sqlalchemy import SQLAlchemy
from datetime import datetimeapp = Flask(__name__)
app.config|"SQLALCHEMY_DATABASE_URI"] = "sqlite:///test.db"
app.config|"SQLALCHEMY_TRACK_MODIFICATIONS'"] = False
db = SQLAlchemy(app)
class Todo(db. Model):
id = db.Column(db.Integer, primary_key=True)
content = db.Column(db.String(200), nullable=False)
completed = db.Column(db. Integer, default=0)
pub_date = db.Column(db.DateTime, nullable=False,
default=datetime.utcnow)
def __repr_(self):
return "