mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2025-01-18 15:27:02 +00:00
Merge branch 'master' into master
This commit is contained in:
commit
da80aef32b
10
Clean_up_photo_directory/README.md
Normal file
10
Clean_up_photo_directory/README.md
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
# Clean_up_photo
|
||||||
|
|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
This program is used to find out the "bad" picture files and then eventually delete them.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Run the clean_up_photo.py
|
20
Clean_up_photo_directory/clean_up_photo.py
Normal file
20
Clean_up_photo_directory/clean_up_photo.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import os
|
||||||
|
from os.path import join
|
||||||
|
for (dirname, dirs, files) in os.walk('.'):
|
||||||
|
for filename in files:
|
||||||
|
if filename.endswith('.txt') :
|
||||||
|
thefile = os.path.join(dirname,filename)
|
||||||
|
size = os.path.getsize(thefile)
|
||||||
|
if size == 2578 or size == 2565:
|
||||||
|
print 'T-Mobile:',thefile
|
||||||
|
#os.remove(thefile) Add this when you are sure to delete the file
|
||||||
|
continue
|
||||||
|
fhand = open(thefile,'r')
|
||||||
|
lines = list()
|
||||||
|
for line in fhand:
|
||||||
|
lines.append(line)
|
||||||
|
fhand.close()
|
||||||
|
if len(lines) == 3 and lines[2].startswith('Sent from my iPhone'):
|
||||||
|
print 'iPhone:', thefile
|
||||||
|
#os.remove(thefile) Add this when you are sure to delete the file
|
||||||
|
continue
|
19
Pretty-CSV/README.md
Normal file
19
Pretty-CSV/README.md
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# Pretty CSV
|
||||||
|
|
||||||
|
This script pretty-prints CSV input into a table output for easier readibility. The script reads from stdin and writes into stdout for pipe compatibility.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
Read from local file
|
||||||
|
```sh
|
||||||
|
python3 pretty-csv.py < csv-file.csv
|
||||||
|
```
|
||||||
|
|
||||||
|
Read from `curl`
|
||||||
|
```sh
|
||||||
|
curl -fsSL https://people.sc.fsu.edu/~jburkardt/data/csv/cities.csv | python3 pretty-csv.py
|
||||||
|
```
|
||||||
|
|
||||||
|
Pipe to `less` for better navigation
|
||||||
|
```sh
|
||||||
|
python3 pretty-csv.py < long-csv-file.csv | less -S
|
||||||
|
```
|
41
Pretty-CSV/pretty-csv.py
Normal file
41
Pretty-CSV/pretty-csv.py
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
import csv
|
||||||
|
import sys
|
||||||
|
from typing import Iterable, List
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
content_lines = sys.stdin.buffer.readlines()
|
||||||
|
reader = csv.reader(line.decode('utf-8') for line in content_lines)
|
||||||
|
headers = next(reader)
|
||||||
|
print(create_table(reader, headers))
|
||||||
|
|
||||||
|
|
||||||
|
def create_table(rows: Iterable[List[str]], headers: List[str]) -> str:
|
||||||
|
table = [headers]
|
||||||
|
column_lengths = [len(header) for header in headers]
|
||||||
|
for row in rows:
|
||||||
|
for i, text in enumerate(row):
|
||||||
|
column_length = column_lengths[i]
|
||||||
|
text_length = len(text)
|
||||||
|
if text_length > column_length:
|
||||||
|
column_lengths[i] = text_length
|
||||||
|
table.append(list(row))
|
||||||
|
|
||||||
|
result = []
|
||||||
|
for row in table:
|
||||||
|
row_text = []
|
||||||
|
for i, text in enumerate(row):
|
||||||
|
column_length = column_lengths[i]
|
||||||
|
row_text.append(space_pad(text, column_length))
|
||||||
|
result.append(' '.join(row_text))
|
||||||
|
return '\n'.join(result)
|
||||||
|
|
||||||
|
|
||||||
|
def space_pad(text: str, length: int) -> str:
|
||||||
|
temp = text + ''.join(' ' for _ in range(length))
|
||||||
|
return temp[:length]
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
11
PyRecorder/README.md
Normal file
11
PyRecorder/README.md
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# PyRecorder
|
||||||
|
|
||||||
|
## Record Preview
|
||||||
|
|
||||||
|
![image](https://github.com/jainrocky/screen_recorder/blob/master/record_preview.PNG)
|
||||||
|
|
||||||
|
## Stop Preview
|
||||||
|
|
||||||
|
![image](https://github.com/jainrocky/screen_recorder/blob/master/stop_preview.PNG)
|
||||||
|
|
||||||
|
* [Download](https://github.com/jainrocky/screen_recorder/blob/master/dist/PyRecorder.exe) Executable File
|
194
PyRecorder/py_recorder.py
Normal file
194
PyRecorder/py_recorder.py
Normal file
|
@ -0,0 +1,194 @@
|
||||||
|
from tkinter.ttk import Combobox
|
||||||
|
from tkinter import Tk, Button, filedialog, messagebox, Label, Menu
|
||||||
|
from PIL import ImageGrab
|
||||||
|
from cv2 import VideoWriter, VideoWriter_fourcc, cvtColor, resize, COLOR_BGR2RGB
|
||||||
|
from ctypes import windll
|
||||||
|
import time
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
|
''' Application authors name'''
|
||||||
|
__author__="Rocky Jain"
|
||||||
|
|
||||||
|
''' copyright '''
|
||||||
|
__copyright__='Copyright (C) 2019 rocky jain'
|
||||||
|
|
||||||
|
''' Application license'''
|
||||||
|
__license__="Public Domain"
|
||||||
|
|
||||||
|
''' Application version '''
|
||||||
|
__version__='1.0'
|
||||||
|
|
||||||
|
''' Application Name '''
|
||||||
|
app_name = 'PyRecorder'
|
||||||
|
|
||||||
|
''' About Information '''
|
||||||
|
about_msg='''
|
||||||
|
App name: '''+app_name+'''
|
||||||
|
Developer name: Rocky Jain
|
||||||
|
Created date: 17-Jul-2019
|
||||||
|
'''
|
||||||
|
|
||||||
|
''' Contact Details '''
|
||||||
|
contact_us='''
|
||||||
|
Email: jainrocky1008@gmail.com
|
||||||
|
github: jainrocky
|
||||||
|
'''
|
||||||
|
|
||||||
|
''' Waiting time for Tk.after function '''
|
||||||
|
call_record_after = 60
|
||||||
|
|
||||||
|
''' Application Window Size(Constant or non resizable) '''
|
||||||
|
app_window_size='340x140'
|
||||||
|
|
||||||
|
''' Video resolution '''
|
||||||
|
video_res = (1280, 720)
|
||||||
|
|
||||||
|
''' stop text '''
|
||||||
|
btn_close_txt='Stop'
|
||||||
|
|
||||||
|
''' exit text '''
|
||||||
|
btn_exit_txt='Exit'
|
||||||
|
|
||||||
|
''' close button width '''
|
||||||
|
btn_close_width=15
|
||||||
|
|
||||||
|
''' start text '''
|
||||||
|
btn_start_txt='Record'
|
||||||
|
|
||||||
|
''' start button width '''
|
||||||
|
btn_start_width=15
|
||||||
|
|
||||||
|
''' Fps Combobox items '''
|
||||||
|
fps_combo_box=[10, 20, 30, 40, 50, 60]
|
||||||
|
|
||||||
|
''' default selected value combobox(20 fps)'''
|
||||||
|
default_cmbox_value = 1
|
||||||
|
|
||||||
|
''' opencv codec '''
|
||||||
|
codec='mp4v'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class WindowRecorder:
|
||||||
|
def __init__(self):
|
||||||
|
self.__app = Tk()
|
||||||
|
self.__app.title(app_name)
|
||||||
|
self.__app.geometry(app_window_size)
|
||||||
|
self.__app.resizable(0, 0)
|
||||||
|
self.__is_recording=False
|
||||||
|
self.__frame_per_sec=fps_combo_box[default_cmbox_value]
|
||||||
|
|
||||||
|
'''
|
||||||
|
CREATING CONTEXT OR FORM with two buttons one menu having three
|
||||||
|
items one label for timer and one combobox for fps selection
|
||||||
|
'''
|
||||||
|
def create_context(self):
|
||||||
|
self.__btn_start_stop = Button(self.__app, text=btn_start_txt, width=btn_start_width, command=self.start_recording, bg='green', fg='white', bd=0)
|
||||||
|
self.__btn_start_stop.pack(pady=10)
|
||||||
|
|
||||||
|
self.__btn_exit=Button(self.__app, text=btn_exit_txt, width=btn_close_width, command=self.destroy, fg='white', bg='blue', bd=0)
|
||||||
|
self.__btn_exit.pack()
|
||||||
|
|
||||||
|
''' Combo Box '''
|
||||||
|
self.__cmb_box=Combobox(self.__app, values=fps_combo_box, width=5)
|
||||||
|
self.__cmb_box.pack(side='right', padx=5, pady=5)
|
||||||
|
cmb_label = Label(self.__app, text='fps')
|
||||||
|
cmb_label.pack(side='right')
|
||||||
|
self.__cmb_box.current(default_cmbox_value)
|
||||||
|
self.__cmb_box.bind('<<ComboboxSelected>>', self.on_select_listener)
|
||||||
|
|
||||||
|
''' Timer label '''
|
||||||
|
self.__timer=Label(text='00:00:00')
|
||||||
|
self.__timer.pack(side='left', padx=5)
|
||||||
|
|
||||||
|
''' Root Menu '''
|
||||||
|
self.__root_menu = Menu(master=self.__app)
|
||||||
|
self.__app.config(menu=self.__root_menu)
|
||||||
|
|
||||||
|
''' File Menu '''
|
||||||
|
self.__file_menu = Menu(self.__root_menu, tearoff=0)
|
||||||
|
self.__file_menu.add_command(label='About', command=self.about)
|
||||||
|
self.__file_menu.add_command(label='Contact us', command=self.contact_us)
|
||||||
|
self.__file_menu.add_separator()
|
||||||
|
self.__file_menu.add_command(label='Exit', command=self.destroy)
|
||||||
|
|
||||||
|
self.__root_menu.add_cascade(label='Menu', menu=self.__file_menu)
|
||||||
|
|
||||||
|
|
||||||
|
''' Start application '''
|
||||||
|
def start(self):
|
||||||
|
self.__app.mainloop()
|
||||||
|
|
||||||
|
''' Start recording '''
|
||||||
|
def start_recording(self):
|
||||||
|
self.__is_recording=True
|
||||||
|
self.__temp_video_frames = list()
|
||||||
|
self.__btn_start_stop.configure(text=btn_close_txt, command=self.stop, bg='red')
|
||||||
|
self.__cmb_box['state']='disabled'
|
||||||
|
self.count=0
|
||||||
|
self.min=0
|
||||||
|
self.sec=0
|
||||||
|
self.__app.iconify()
|
||||||
|
self.record_frames()
|
||||||
|
|
||||||
|
''' Stop screen recording '''
|
||||||
|
def stop(self):
|
||||||
|
self.__is_recording=False
|
||||||
|
file = filedialog.asksaveasfile(defaultextension="*.*", filetypes=[('mp4', '.mp4'),])
|
||||||
|
if file:
|
||||||
|
if file.name:
|
||||||
|
print(file.name)
|
||||||
|
shape = self.__temp_video_frames[0].shape
|
||||||
|
print(shape)
|
||||||
|
fourcc = VideoWriter_fourcc(*codec)
|
||||||
|
video_writer = VideoWriter(file.name, fourcc, self.__frame_per_sec, (shape[1], shape[0]), True)
|
||||||
|
if self.__temp_video_frames:
|
||||||
|
for frame in self.__temp_video_frames:
|
||||||
|
video_writer.write(frame)
|
||||||
|
del self.__temp_video_frames
|
||||||
|
video_writer.release()
|
||||||
|
self.__btn_start_stop.configure(text=btn_start_txt, command=self.start_recording, bg='green')
|
||||||
|
self.__cmb_box['state']='normal'
|
||||||
|
|
||||||
|
''' Close application '''
|
||||||
|
def destroy(self):
|
||||||
|
self.__app.destroy()
|
||||||
|
|
||||||
|
''' Extracting list of frames '''
|
||||||
|
def record_frames(self):
|
||||||
|
screen = np.array(ImageGrab.grab())
|
||||||
|
screen = cvtColor(screen, COLOR_BGR2RGB)
|
||||||
|
screen = resize(screen, video_res)
|
||||||
|
self.__temp_video_frames.append(screen)
|
||||||
|
self.count += 1
|
||||||
|
dur = (self.count / self.__frame_per_sec)
|
||||||
|
self.min = int(dur / 60)
|
||||||
|
self.sec = dur % 60
|
||||||
|
self.__timer['text']=time.strftime('%H:%M:%S', time.gmtime(self.min*60 + self.sec))
|
||||||
|
if self.__is_recording:
|
||||||
|
self.__app.after(call_record_after, self.record_frames)
|
||||||
|
|
||||||
|
''' Combobox selection controller '''
|
||||||
|
def on_select_listener(self, event=None):
|
||||||
|
if event:
|
||||||
|
self.__frame_per_sec=int(event.widget.get())
|
||||||
|
|
||||||
|
''' Contact us information '''
|
||||||
|
def contact_us(self):
|
||||||
|
messagebox.showinfo('Contact us', contact_us)
|
||||||
|
|
||||||
|
''' About details'''
|
||||||
|
def about(self):
|
||||||
|
messagebox.showinfo('About', about_msg)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__=='__main__':
|
||||||
|
''' Fixing ImageGarb bug(i.e, not cropping full screen) '''
|
||||||
|
user_32=windll.user32
|
||||||
|
user_32.SetProcessDPIAware()
|
||||||
|
|
||||||
|
''' App Call '''
|
||||||
|
app=WindowRecorder()
|
||||||
|
app.create_context()
|
||||||
|
app.start()
|
3
PyRecorder/requirements.txt
Normal file
3
PyRecorder/requirements.txt
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
numpy==1.17.3
|
||||||
|
opencv-python==4.1.1.26
|
||||||
|
Pillow==6.2.0
|
|
@ -1,4 +1,4 @@
|
||||||
# Awesome Python Scripts :sunglasses: <img alt="PyPI" src="https://warehouse-camo.cmh1.psfhosted.org/18509a25dde64f893bd96f21682bd6211c3d4e80/68747470733a2f2f696d672e736869656c64732e696f2f707970692f707976657273696f6e732f64796e61636f6e662e737667">
|
# Awesome Python Scripts :sunglasses: <img alt="PyPI" src="https://warehouse-camo.cmh1.psfhosted.org/18509a25dde64f893bd96f21682bd6211c3d4e80/68747470733a2f2f696d672e736869656c64732e696f2f707970692f707976657273696f6e732f64796e61636f6e662e737667">
|
||||||
|
|
||||||
## What is this repo?
|
## What is this repo?
|
||||||
This repo is a compilation of some *awesome* Python scripts that automate some boring tasks or simply make our life easier...or both!
|
This repo is a compilation of some *awesome* Python scripts that automate some boring tasks or simply make our life easier...or both!
|
||||||
|
@ -72,6 +72,9 @@ So far, the following projects have been integrated to this repo:
|
||||||
|[Yoda-speak Translator](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/speak_like_yoda)|[sonniki](https://github.com/sonniki) |
|
|[Yoda-speak Translator](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/speak_like_yoda)|[sonniki](https://github.com/sonniki) |
|
||||||
|[Medium Article Downloader](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/medium_article_downloader)|[coolsonu39](https://github.com/coolsonu39)|
|
|[Medium Article Downloader](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/medium_article_downloader)|[coolsonu39](https://github.com/coolsonu39)|
|
||||||
|[RSA Key Pair Generator](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/RSA-key-pairs) | [Aditya Parikh](https://github.com/obiwan69) |
|
|[RSA Key Pair Generator](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/RSA-key-pairs) | [Aditya Parikh](https://github.com/obiwan69) |
|
||||||
|
|[Clean_up_photo](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Clean_up_photo)|[sritanmay001](https://github.com/sritanmy001)|
|
||||||
|
|[PyRecorder](./PyRecorder)|[Rocky Jain](https://github.com/jainrocky)|
|
||||||
|
|[Pretty CSV](https://github.com/Frizz925/Awesome-Python-Scripts/tree/pretty-csv/Pretty-CSV)|[Frizz925](https://github.com/Frizz925)|
|
||||||
|
|
||||||
## How to use :
|
## How to use :
|
||||||
|
|
||||||
|
@ -84,9 +87,9 @@ So far, the following projects have been integrated to this repo:
|
||||||
|
|
||||||
- Run the script :)
|
- Run the script :)
|
||||||
|
|
||||||
Remember to star the repo if you love the scipts~ :wink:
|
Remember to star the repo if you love the scripts~ :wink:
|
||||||
|
|
||||||
## Contribuition Guidelines :
|
## Contribution Guidelines :
|
||||||
- Make a **separate folder** for your script.
|
- Make a **separate folder** for your script.
|
||||||
- There shouldn't be any **spaces** between the names of the script. (Use underscore or dash Symbol)
|
- There shouldn't be any **spaces** between the names of the script. (Use underscore or dash Symbol)
|
||||||
- :x: Script One
|
- :x: Script One
|
||||||
|
|
Loading…
Reference in New Issue
Block a user