Skip to content

Instantly share code, notes, and snippets.

View keshan-spec's full-sized avatar
🏠
Working from home

Keshanth Jude keshan-spec

🏠
Working from home
View GitHub Profile
@keshan-spec
keshan-spec / app.py
Created December 6, 2022 20:48
Imports
from flask import Flask
from bs4 import BeautifulSoup
import requests
import os
import json
app = Flask(__name__) # Create an instance of Flask
# the / route
@app.route("/")
def home():
return json.dumps({"docker":"flask"})
# Run the app
if __name__ == "__main__":
app.run(debug=True, port=5000)
@keshan-spec
keshan-spec / app.py
Created December 6, 2022 21:22
Scraping the data
keys = [
"Country",
"Total Cases",
"New Cases",
"Total Deaths",
"New Deaths",
"Total Recovered",
"New Recovered",
"Active Cases",
] # the keys of the table
@keshan-spec
keshan-spec / app.py
Created December 6, 2022 21:27
Data preperation
s, e = 0, len(keys)
entries = []
# Loop through the temp list and make a dict with every 9 items
for _ in range(len(tmp) // len(keys)):
d = dict(zip(keys, tmp[s:e]))
if d:
entries.append(d)
s += len(keys)
e += len(keys)
@keshan-spec
keshan-spec / app.py
Last active December 6, 2022 21:48
Show Country API Endpoint
@app.route("/show/<country>")
def get_country(country):
entries = get_info_table()
if country == "all":
return json.dumps(entries)
else:
for entry in entries["data"]:
if entry["Country"] == country.lower():
return json.dumps(entry)
return json.dumps({"error": f"Country not found: {country}"})
@keshan-spec
keshan-spec / Dockerfile
Last active December 6, 2022 22:07
Dockerfile for Python Flask
# syntax=docker/dockerfile:1
FROM python:3.8-slim-buster
WORKDIR /code
COPY . .
EXPOSE 5000
RUN pip3 install -r requirements.txt
CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0"]
@keshan-spec
keshan-spec / docker-compose.yml
Last active December 6, 2022 22:11
Docker compose file
# docker-compose.yml
version: "3.2"
services:
web:
build: . # where the Dockerfile is located
ports:
- 5000:5000 # container:host
environment:
- URL=https://www.worldometers.info/coronavirus/
import os
import re
import dateutil.parser as dparser
conversions = {}
# Define the folder containing the files to be renamed
PATH = os.path.join(os.getcwd(),"files")
def create_dummy_files():
# For webcam input:
cap = cv2.VideoCapture(0)
with mp_face_detection.FaceDetection() as face_detection:
while cap.isOpened():
success, image = cap.read()
while not success:
success, image = cap.read()
# To improve performance, optionally mark the image as not writeable to
# pass by reference.
cap = cv2.VideoCapture(0)
with mp_face_detection.FaceDetection() as face_detection:
while cap.isOpened():
success, image = cap.read()
while not success:
success, image = cap.read()