Merge branch 'master' into countdown

This commit is contained in:
Jeremias Moreira Gomes 2022-10-11 16:54:21 -03:00 committed by GitHub
commit bf3fead97e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 213 additions and 33 deletions

View File

@ -0,0 +1,42 @@
p
# Better CSV Storage
-> For User / Programmer who don't want to use databases and want to use csv instead, this script will help manage that csv file (storage)
### What you Can Do ?
-> Filter Data Based On Certain Conditions that you provide,
-> Update Certain Value in particular row.
### How to use ?
-> It's OOP based Script so just import that in you Regular Script.
-> For Example,
-> I want to check and download_status of files.
-> csv file i have used -> `dummy_data.csv`
```python
csv_path = 'dummy_data.csv'
#init class and get the object
csv_obj = BetterCSVStorage(csv_path)
#Now user that object as storage
#Filter Data Based on Different parameters
#This List will contain additional ( update_index ) which is row index of each row in csv.
#This update_index will be use to update value of certain index.
filtered_data = csv_obj.get_filtered_data('download_status', '==', '')
#Change Data Based on Different parameters
csv_obj.update_data(10,'download_status', 'done')
```

View File

@ -0,0 +1,95 @@
import csv
class BetterCSVStorage():
def __init__(self, csv_path):
self.csv_f_path = csv_path
self.valid_headers = None
self.allowed_comparison = ['==', '!=']
def load(self):
with open(self.csv_f_path, 'r') as csv_f:
csv_reader = csv.reader(csv_f)
self.valid_headers = next(csv_reader)
def write_dict_csv(self, data_rows):
if data_rows:
field_names = list(data_rows[0].keys())
with open(self.csv_f_path,'w') as csv_wf:
csv_writer = csv.DictWriter(csv_wf, fieldnames=field_names)
csv_writer.writeheader()
for row in data_rows:
csv_writer.writerow(row)
print('[+] Data Written Successfully ...')
else:
print('[-] Error : Data Rows Could not be empty ...')
def get_filtered_data(self, col_name, comparison, value):
if not self.valid_headers:
self.load()
if not col_name in self.valid_headers:
print('[-] Error : Enter Valid Column Name.')
print('[*] Info : Allowed Column Names Are : {}'.format(', '.join(self.valid_headers)))
else:
if not comparison in self.allowed_comparison:
print('[-] Error : Invalid Comparison.')
print('[*] Info : Allowed Comparison Are : {}'.format(', '.join(self.allowed_comparison)))
else:
filtered_data = []
with open(self.csv_f_path,'r') as c_file:
csv_reader = csv.DictReader(c_file)
for row_index, row in enumerate(csv_reader):
try:
if (comparison == '=='):
if row[col_name] == value:
row['update_index'] = row_index
filtered_data.append(row)
if (comparison == '!='):
if row[col_name] != value:
row['update_index'] = row_index
filtered_data.append(row)
except KeyError:
continue
return filtered_data
def update_data(self, update_index, col_name, value):
if not self.valid_headers:
self.load()
if not col_name in self.valid_headers:
print('[-] Error : Enter Valid Column Name.')
print('[*] Info : Allowed Column Names Are : {}'.format(', '.join(self.valid_headers)))
else:
if not update_index:
print('[-] Error Valid Data Index ....')
else:
try:
update_index = int(update_index)
except:
print('[-] Error : Update Index is Not Valid')
return
updated_rows = []
with open(self.csv_f_path,'r') as csv_rf:
csv_reader = csv.DictReader(csv_rf)
for row_index, row in enumerate(csv_reader):
if update_index == row_index:
print('[+] Updating Index {}'.format(update_index))
row[col_name] = value
updated_rows.append(row)
self.write_dict_csv(updated_rows)
if __name__ == '__main__':
csv_path = 'dummy_data.csv'
#init class and get the object
csv_obj = BetterCSVStorage(csv_path)
#Now user that object as storage
#Filter Data Based on Different parameters
#This List will contain additional ( update_index ) which is row index of each row in csv.
#This update_index will be use to update value of certain index.
filtered_data = csv_obj.get_filtered_data('download_status', '==', '')
#Change Data Based on Different parameters
csv_obj.update_data(4,'download_status', 'done')

View File

@ -0,0 +1,7 @@
id,file_name,file_url,download_date,download_status
1430,sample_video1.mp4,https://example.com/download/sample_video1.mp4,05/10/22,
239,sample_video2.mp4,https://example.com/download/sample_video2.mp4,05/10/22,
3421,sample_video3.mp4,https://example.com/download/sample_video3.mp4,05/10/22,
1305,sample_video4.mp4,https://example.com/download/sample_video4.mp4,05/10/22,
6375,sample_video5.mp4,https://example.com/download/sample_video5.mp4,06/10/22,done
1203,sample_video6.mp4,https://example.com/download/sample_video6.mp4,06/10/22,done
1 id file_name file_url download_date download_status
2 1430 sample_video1.mp4 https://example.com/download/sample_video1.mp4 05/10/22
3 239 sample_video2.mp4 https://example.com/download/sample_video2.mp4 05/10/22
4 3421 sample_video3.mp4 https://example.com/download/sample_video3.mp4 05/10/22
5 1305 sample_video4.mp4 https://example.com/download/sample_video4.mp4 05/10/22
6 6375 sample_video5.mp4 https://example.com/download/sample_video5.mp4 06/10/22 done
7 1203 sample_video6.mp4 https://example.com/download/sample_video6.mp4 06/10/22 done

6
PdfToAudio/README.md Normal file
View File

@ -0,0 +1,6 @@
# Pdf to Audiobook Converter
This python script generates audio for given pdf files.
## Dependencies / Requirements
- PyPDF2. Install it by typing this command in your terminal `pip install PyPDF2`
- pyttsx3. Install it by `pip install pyttsx3`

View File

@ -0,0 +1,26 @@
# Importing the required packages.
import PyPDF2
import pyttsx3
text = None
# Reading a PDF file from your computer by specifying the path and setting the read mode to binary.
pdf_reader = PyPDF2.PdfFileReader(open(r"D:\MyPdf.pdf", "rb"))
# Getting the handle to speaker i.e. creating a reference to pyttsx3.Engine instance.
speaker = pyttsx3.init()
# Splitting the PDF file into pages and reading one at a time.
for page_number in range(pdf_reader.numPages):
text = pdf_reader.getPage(page_number).extractText()
# Generating speech.
speaker.say(text)
speaker.runAndWait()
# Stopping the speaker after the complete audio has been created.
speaker.stop()
# Saving the audiobook to your computer.
engine = pyttsx3.init()
engine.save_to_file(text, r"D:\MyAudio.mp3")
engine.runAndWait()

View File

@ -0,0 +1,2 @@
PyPDF2
pyttsx3

View File

@ -20,9 +20,10 @@ So far, the following projects have been integrated to this repo:
|[AI chatbot](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Artificial-intelligence_bot) |[umar abdullahi](https://github.com/umarbrowser) | |[AI chatbot](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Artificial-intelligence_bot) |[umar abdullahi](https://github.com/umarbrowser) |
|[Asymmetric Encryption](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/asymmetric_cryptography) |[victor matheus](https://github.com/victormatheusc) | |[Asymmetric Encryption](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/asymmetric_cryptography) |[victor matheus](https://github.com/victormatheusc) |
|[Bitcoin price GUI](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Bitcoin-Price-GUI) |[Amirul Abu](https://github.com/amirulabu) | |[Bitcoin price GUI](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Bitcoin-Price-GUI) |[Amirul Abu](https://github.com/amirulabu) |
|[Better_CSV_Storage](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Better_CSV_Storage) | [Bhargav Kuvadiya](https://github.com/techdobz) |
|[Cryptocurrency Converter](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Cryptocurrency-converter) |[AdnCodz](https://github.com/AdnCodez) | |[Cryptocurrency Converter](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Cryptocurrency-converter) |[AdnCodz](https://github.com/AdnCodez) |
|[Cryptocurrency Prices](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Cryptocurrency-Prices) |[xemeds](https://github.com/xemeds) | |[Cryptocurrency Prices](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Cryptocurrency-Prices) |[xemeds](https://github.com/xemeds) |
|[Caesar Cipher](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/caeser_cipher) |[epi052](https://github.com/epi052) | |[Caesar Cipher](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/caesar_cipher) |[epi052](https://github.com/epi052) |
|[Checksum tool](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Checksum) |[Austin Ewens](https://github.com/aewens) | |[Checksum tool](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Checksum) |[Austin Ewens](https://github.com/aewens) |
|[Codechef autosubmitter](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Codechef-Code-Submitter) |[Harshit Mahajan](https://github.com/hmahajan99) | |[Codechef autosubmitter](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Codechef-Code-Submitter) |[Harshit Mahajan](https://github.com/hmahajan99) |
|[Colored B&W Image Converter](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Color_to_BW_Converter) |[Nitish Srivastava](https://github.com/nitish-iiitd) | |[Colored B&W Image Converter](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Color_to_BW_Converter) |[Nitish Srivastava](https://github.com/nitish-iiitd) |
@ -100,7 +101,7 @@ So far, the following projects have been integrated to this repo:
|[Asymmetric Encryption](asymmetric_cryptography) |[victor matheus](https://github.com/victormatheusc) | |[Asymmetric Encryption](asymmetric_cryptography) |[victor matheus](https://github.com/victormatheusc) |
|[Bitcoin price GUI](Bitcoin-Price-GUI) |[Amirul Abu](https://github.com/amirulabu) | |[Bitcoin price GUI](Bitcoin-Price-GUI) |[Amirul Abu](https://github.com/amirulabu) |
|[Cryptocurrency Converter](Cryptocurrency-converter) |[AdnCodz](https://github.com/AdnCodez) | |[Cryptocurrency Converter](Cryptocurrency-converter) |[AdnCodz](https://github.com/AdnCodez) |
|[Caesar Cipher](caeser_cipher) |[epi052](https://github.com/epi052) | |[Caesar Cipher](caesar_cipher) |[epi052](https://github.com/epi052) |
|[Checksum tool](Checksum) |[Austin Ewens](https://github.com/aewens) | |[Checksum tool](Checksum) |[Austin Ewens](https://github.com/aewens) |
|[Codechef autosubmitter](Codechef-Code-Submitter) |[Harshit Mahajan](https://github.com/hmahajan99) | |[Codechef autosubmitter](Codechef-Code-Submitter) |[Harshit Mahajan](https://github.com/hmahajan99) |
|[Colored B&W Image Converter](Color_to_BW_Converter) |[Nitish Srivastava](https://github.com/nitish-iiitd) | |[Colored B&W Image Converter](Color_to_BW_Converter) |[Nitish Srivastava](https://github.com/nitish-iiitd) |
@ -196,6 +197,7 @@ So far, the following projects have been integrated to this repo:
|[Pressure_Converter](https://github.com/E-wave112/Awesome-Python-Scripts/tree/master/Pressure_Converter)|[E-Wave](https://github.com/E-wave112)| |[Pressure_Converter](https://github.com/E-wave112/Awesome-Python-Scripts/tree/master/Pressure_Converter)|[E-Wave](https://github.com/E-wave112)|
| [File Carving](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/File_Carving) | [Yeryeong Kim](https://github.com/icarusicarus/) | | [File Carving](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/File_Carving) | [Yeryeong Kim](https://github.com/icarusicarus/) |
|[Google Meet Joiner](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/google_meet_joiner)|[JohanSanSebastian](https://github.com/JohanSanSebastian)| |[Google Meet Joiner](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/google_meet_joiner)|[JohanSanSebastian](https://github.com/JohanSanSebastian)|
|[Pdf to AudioBook Converter](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/PdfToAudio)|[Ayesha Gull](https://github.com/ayeshag7/)|
|[Countdown](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Countdown)|[Jeremias Gomes](https://github.com/j3r3mias)| |[Countdown](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Countdown)|[Jeremias Gomes](https://github.com/j3r3mias)|
## How to use : ## How to use :

27
caesar_cipher/README.md Normal file
View File

@ -0,0 +1,27 @@
# Simple caesar Cipher [En,De]coder
A simple implementation of a CLI tool to work with caesar ciphers. The default implementation is ROT-13, but can be
adjusted for any offset. Works on files and string arguments passed via CLI.
```bash
python3 caesar.py
usage: caesar.py [-h] [-d] [-o OFFSET] (-f FILE | -s STRING)
caesar.py: error: one of the arguments -f/--file -s/--string is required
```
```bash
python3 caesar.py -s "have you tried turning it off and on again?"
unir lbh gevrq gheavat vg bss naq ba ntnva?
```
```bash
python3 caesar.py -d -s "unir lbh gevrq gheavat vg bss naq ba ntnva?"
have you tried turning it off and on again?
```
```bash
python3 caesar.py -s "have you tried turning it off and on again?" -o -4
dwra ukq pneaz pqnjejc ep kbb wjz kj wcwej?
```

View File

@ -9,8 +9,8 @@ except AttributeError:
maketrans = str.maketrans # python3 maketrans = str.maketrans # python3
def caeser_cipher(string_: str, offset: int, decode: bool, file_: string) -> None: def caesar_cipher(string_: str, offset: int, decode: bool, file_: string) -> None:
""" Caeser Cipher implementation, reads file or string. Also decodes. """ caesar Cipher implementation, reads file or string. Also decodes.
Default implementation is ROT13 encoding. Default implementation is ROT13 encoding.
@ -59,7 +59,7 @@ def check_offset_range(value: int) -> int:
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Simple Caeser Cipher [En,De]coder") parser = argparse.ArgumentParser(description="Simple caesar Cipher [En,De]coder")
parser.add_argument('-d', '--decode', action='store_true', dest='decode', parser.add_argument('-d', '--decode', action='store_true', dest='decode',
help='decode ciphertext (offset should equal what was used to encode)', default=False) help='decode ciphertext (offset should equal what was used to encode)', default=False)
@ -72,4 +72,4 @@ if __name__ == '__main__':
args = parser.parse_args() args = parser.parse_args()
caeser_cipher(args.string, args.offset, args.decode, args.file) caesar_cipher(args.string, args.offset, args.decode, args.file)

View File

@ -1,27 +0,0 @@
# Simple Caeser Cipher [En,De]coder
A simple implementation of a CLI tool to work with caeser ciphers. The default implementation is ROT-13, but can be
adjusted for any offset. Works on files and string arguments passed via CLI.
```bash
python3 caeser.py
usage: caeser.py [-h] [-d] [-o OFFSET] (-f FILE | -s STRING)
caeser.py: error: one of the arguments -f/--file -s/--string is required
```
```bash
python3 caeser.py -s "have you tried turning it off and on again?"
unir lbh gevrq gheavat vg bss naq ba ntnva?
```
```bash
python3 caeser.py -d -s "unir lbh gevrq gheavat vg bss naq ba ntnva?"
have you tried turning it off and on again?
```
```bash
python3 caeser.py -s "have you tried turning it off and on again?" -o -4
dwra ukq pneaz pqnjejc ep kbb wjz kj wcwej?
```