forked from avinashkranjan/Amazing-Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
[pull] master from avinashkranjan:master #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
17f8b17
Update age_calc_gui.py
MesutKihal 2268ee7
Merge pull request #1261 from MesutKihal/master
avinashkranjan 75116d4
build(deps): bump joblib from 1.0.0 to 1.2.0 in /Traffic-Sign-Detection
dependabot[bot] c628829
Merge pull request #1283 from avinashkranjan/dependabot/pip/Traffic-S...
avinashkranjan 1c059e2
Update platform.txt
simar5244 13862b5
[+] Added New Script To Convert Folder To HTML File
bhargavnova 5e56c91
Merge pull request #1292 from simar5244/patch-1
avinashkranjan 8ef4556
Merge pull request #1291 from techdobz/master
avinashkranjan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
127 changes: 67 additions & 60 deletions
Age-Calculator-GUI/age_calc_gui.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,70 @@ | ||
# import libraries | ||
from tkinter import * | ||
import tkinter as tk | ||
from datetime import date | ||
|
||
# initialized window | ||
root = Tk() | ||
root.geometry('280x300') | ||
root.resizable(0, 0) | ||
root.title('Age Calculator') | ||
statement = Label(root) | ||
|
||
# defining the function for calculating age | ||
|
||
|
||
def ageCalc(): | ||
global statement | ||
statement.destroy() | ||
today = date.today() | ||
birthDate = date(int(yearEntry.get()), int( | ||
monthEntry.get()), int(dayEntry.get())) | ||
age = today.year - birthDate.year | ||
if today.month < birthDate.month or today.month == birthDate.month and today.day < birthDate.day: | ||
age -= 1 | ||
statement = Label(text=f"{nameValue.get()}'s age is {age}.") | ||
statement.grid(row=6, column=1, pady=15) | ||
|
||
|
||
# creating a label for person's name to display | ||
l1 = Label(text="Name: ") | ||
l1.grid(row=1, column=0) | ||
nameValue = StringVar() | ||
|
||
# creating a entry box for input | ||
nameEntry = Entry(root, textvariable=nameValue) | ||
nameEntry.grid(row=1, column=1, padx=10, pady=10) | ||
|
||
# label for year in which user was born | ||
l2 = Label(text="Year: ") | ||
l2.grid(row=2, column=0) | ||
yearValue = StringVar() | ||
yearEntry = Entry(root, textvariable=yearValue) | ||
yearEntry.grid(row=2, column=1, padx=10, pady=10) | ||
|
||
# label for month in which user was born | ||
l3 = Label(text="Month: ") | ||
l3.grid(row=3, column=0) | ||
monthValue = StringVar() | ||
monthEntry = Entry(root, textvariable=monthValue) | ||
monthEntry.grid(row=3, column=1, padx=10, pady=10) | ||
|
||
# label for day/date on which user was born | ||
l4 = Label(text="Day: ") | ||
l4.grid(row=4, column=0) | ||
dayValue = StringVar() | ||
dayEntry = Entry(root, textvariable=dayValue) | ||
dayEntry.grid(row=4, column=1, padx=10, pady=10) | ||
|
||
# create a button for calculating age | ||
button = Button(text="Calculate age", command=ageCalc) | ||
button.grid(row=5, column=1) | ||
|
||
# infinite loop to run program | ||
root.mainloop() | ||
# GUI App class | ||
class App: | ||
def __init__(self): | ||
# initialized window | ||
self.master = tk.Tk() | ||
self.master.geometry('280x300') | ||
self.master.configure(bg="lightblue") | ||
self.master.resizable(0, 0) | ||
self.master.title('Age Calculator') | ||
self.statement = tk.Label(self.master) | ||
|
||
def run(self): | ||
# creating a label for person's name to display | ||
self.l1 = tk.Label(text="Name: ", font="courier 10", bg="lightblue") | ||
self.l1.grid(row=1, column=0) | ||
nameValue = tk.StringVar() | ||
|
||
# creating a entry box for input | ||
self.nameEntry = tk.Entry(self.master, textvariable=nameValue, relief="solid") | ||
self.nameEntry.grid(row=1, column=1, padx=10, pady=10) | ||
|
||
# label for year in which user was born | ||
self.l2 = tk.Label(text="Year: ", font="courier 10", bg="lightblue") | ||
self.l2.grid(row=2, column=0) | ||
yearValue = tk.StringVar() | ||
self.yearEntry = tk.Entry(self.master, textvariable=yearValue, relief="solid") | ||
self.yearEntry.grid(row=2, column=1, padx=10, pady=10) | ||
|
||
# label for month in which user was born | ||
self.l3 = tk.Label(text="Month: ", font="courier 10", bg="lightblue") | ||
self.l3.grid(row=3, column=0) | ||
monthValue = tk.StringVar() | ||
self.monthEntry = tk.Entry(self.master, textvariable=monthValue, relief="solid") | ||
self.monthEntry.grid(row=3, column=1, padx=10, pady=10) | ||
|
||
# label for day/date on which user was born | ||
self.l4 = tk.Label(text="Day: ", font="courier 10", bg="lightblue") | ||
self.l4.grid(row=4, column=0) | ||
dayValue = tk.StringVar() | ||
self.dayEntry = tk.Entry(self.master, textvariable=dayValue, relief="solid") | ||
self.dayEntry.grid(row=4, column=1, padx=10, pady=10) | ||
|
||
# defining the function for calculating age | ||
def ageCalc(): | ||
self.statement.destroy() | ||
today = date.today() | ||
birthDate = date(int(self.yearEntry.get()), int( | ||
self.monthEntry.get()), int(self.dayEntry.get())) | ||
age = today.year - birthDate.year | ||
if today.month < birthDate.month or today.month == birthDate.month and today.day < birthDate.day: | ||
age -= 1 | ||
self.statement = tk.Label(text=f"{nameValue.get()}'s age is {age}.", font="courier 10", bg="lightblue") | ||
self.statement.grid(row=6, column=1, pady=15) | ||
|
||
# create a button for calculating age | ||
self.button = tk.Button(text="Calculate age", font="courier 12 bold", fg="white", bg="dodgerblue", command=ageCalc) | ||
self.button.grid(row=5, column=1) | ||
|
||
# infinite loop to run program | ||
self.master.mainloop() | ||
|
||
|
||
if __name__ == '__main__': | ||
age_calc = App() | ||
age_calc.run() | ||
|
25 changes: 25 additions & 0 deletions
Folder-To-HTML/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
|
||
# Folder To HTML Page | ||
|
||
-> Convert Any Folder or sub folders into Single HTML Page with CSS and Some JavaScript | ||
|
||
-> you can open this .html file into your browser to view data. | ||
|
||
-> will Show .mp4 as html videos , .mp3 as html audios and pdf document as link, you can open that directly in your browser, | ||
|
||
-> you can also add any document you want , just by adding some thing in code. | ||
|
||
### How TO Use | ||
|
||
-> Add all the data into td_data folder. | ||
|
||
-> Run : `python make_data.py` | ||
|
||
-> will create `data_view.html` file. | ||
|
||
### Features | ||
|
||
-> Search Data / Files based on Names, | ||
|
||
-> will convert folder names into tag format , you can filter data based on that also. |
153 changes: 153 additions & 0 deletions
Folder-To-HTML/make_data.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
import os | ||
|
||
data_folder = 'td_data' | ||
static_folder = 'td_static' | ||
html_file = 'data_view.html' | ||
data_dir_path = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
class DataView(): | ||
|
||
def __init__(self, data_folder, html_file): | ||
self.data_folder = data_folder | ||
self.html_file = html_file | ||
|
||
self.all_tags = set() | ||
self.objects = { | ||
'.mp4': [], | ||
'.mp3': [], | ||
'.pdf': [], | ||
'other': [] | ||
} | ||
|
||
self.allowed_data_types = ['.mp4','.mp3','.pdf'] | ||
self.data_types = { | ||
'.mp4': """ | ||
<video class="td-video" controls> | ||
<source src="{src_info}" type="video/mp4"> | ||
</video> | ||
""", | ||
'.mp3': """ | ||
<audio class="td-audio" controls> | ||
<source src="{src_info}" type="audio/ogg"> | ||
</audio> | ||
""", | ||
".pdf" : """ | ||
<a class="td-pdf" href="file://""" + data_dir_path + """/{src_info}" target="_blank" >OPEN</a> | ||
""" | ||
|
||
} | ||
self.list_of_files = {} | ||
|
||
|
||
def find_all_files(self): | ||
for (dirpath, dirnames, filenames) in os.walk(data_folder): | ||
for filename in filenames: | ||
self.list_of_files[filename] = os.sep.join([dirpath, filename]) | ||
|
||
def write_first_html(self, src_tags): | ||
with open(self.html_file,'w') as h_file: | ||
h_file.write( | ||
""" | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
|
||
<!-- ALL THE OUTSIDE CSS --> | ||
|
||
<!-- ALL CUSTOM CSS --> | ||
<link rel="stylesheet" href=" """+ static_folder +"""/css/main/data_view.css"> | ||
|
||
<title>Data View</title> | ||
|
||
</head> | ||
<body> | ||
<div class="_td-s"> | ||
<div id="search"> | ||
<input id="td-input" type="text" placeholder="Find data..."> | ||
</div> | ||
</div> | ||
<div class="td-main"> | ||
<div class="td-right"> | ||
<div class="_td-t"> | ||
<div class="_td-te tag-active">#all</div> | ||
{src_tags} | ||
</div> | ||
</div> | ||
<div class="td-left"> | ||
<div class="_td-c"> | ||
""".format(src_tags=src_tags) | ||
) | ||
|
||
def write_middle_html(self,object): | ||
ext = object['ext'] | ||
src_info = object['src_info'] | ||
src_name = object['src_name'] | ||
src_tags = object['src_tags'] | ||
|
||
with open(self.html_file,'a') as h_file: | ||
h_file.write( | ||
""" | ||
<div class="td-element"> | ||
{src_info} | ||
<div class="_tde-info">{src_name}</div> | ||
<div class="_tde-tags">{src_tags}</div> | ||
</div> | ||
""".format(src_info=self.data_types[ext].format(src_info=src_info),src_name=src_name,src_tags=src_tags) | ||
) | ||
|
||
def write_end_html(self): | ||
with open(self.html_file,'a') as h_file: | ||
h_file.write( | ||
""" | ||
</div> | ||
</div> | ||
</div> | ||
<!-- ALL OUTSIDE SCRIPTS --> | ||
<script src=" """+ static_folder +"""/js/outside/jquery-3.6.1.min.js"></script> | ||
|
||
<!-- ALL MAIN SCRIPTS--> | ||
<script src=" """+ static_folder +"""/js/main/data_view.js"></script> | ||
</body> | ||
</html> | ||
""" | ||
) | ||
|
||
def work_on_files(self): | ||
for file_name in self.list_of_files: | ||
file_path = self.list_of_files[file_name] | ||
name, ext = os.path.splitext(file_name) | ||
|
||
tags = file_path.split('/') | ||
tags.remove(self.data_folder) | ||
tags.remove(file_name) | ||
|
||
self.all_tags.update(tags) | ||
|
||
src_tags = '\n'.join('<span class="_td-te2">#{}</span>'.format(t) for t in tags) | ||
|
||
if ext in self.allowed_data_types: | ||
object = { | ||
'ext': ext, | ||
'src_info': file_path, | ||
'src_name': name, | ||
'src_tags': src_tags, | ||
} | ||
|
||
self.objects[ext].append(object) | ||
|
||
src_tags = '\n'.join('<div class="_td-te">#{}</div>'.format(t) for t in list(self.all_tags)) | ||
|
||
self.write_first_html(src_tags) | ||
|
||
for ext,object_list in self.objects.items(): | ||
for object_dict in object_list: | ||
self.write_middle_html(object_dict) | ||
|
||
self.write_end_html() | ||
|
||
data_obj = DataView(data_folder,html_file) | ||
data_obj.find_all_files() | ||
data_obj.work_on_files() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.