Skip to content

Commit bf3fead

Browse files
authored
Merge branch 'master' into countdown
2 parents c7185e8 + 1cb83e9 commit bf3fead

File tree

10 files changed

+213
-33
lines changed

10 files changed

+213
-33
lines changed

Better_CSV_Storage/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
p
2+
3+
# Better CSV Storage
4+
5+
-> 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)
6+
7+
8+
9+
### What you Can Do ?
10+
11+
-> Filter Data Based On Certain Conditions that you provide,
12+
13+
-> Update Certain Value in particular row.
14+
15+
16+
17+
### How to use ?
18+
19+
-> It's OOP based Script so just import that in you Regular Script.
20+
21+
-> For Example,
22+
23+
​ -> I want to check and download_status of files.
24+
25+
​ -> csv file i have used -> `dummy_data.csv`
26+
27+
```python
28+
csv_path = 'dummy_data.csv'
29+
30+
#init class and get the object
31+
csv_obj = BetterCSVStorage(csv_path)
32+
33+
#Now user that object as storage
34+
35+
#Filter Data Based on Different parameters
36+
#This List will contain additional ( update_index ) which is row index of each row in csv.
37+
#This update_index will be use to update value of certain index.
38+
filtered_data = csv_obj.get_filtered_data('download_status', '==', '')
39+
40+
#Change Data Based on Different parameters
41+
csv_obj.update_data(10,'download_status', 'done')
42+
```
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import csv
2+
3+
class BetterCSVStorage():
4+
5+
def __init__(self, csv_path):
6+
self.csv_f_path = csv_path
7+
self.valid_headers = None
8+
self.allowed_comparison = ['==', '!=']
9+
10+
def load(self):
11+
with open(self.csv_f_path, 'r') as csv_f:
12+
csv_reader = csv.reader(csv_f)
13+
self.valid_headers = next(csv_reader)
14+
15+
def write_dict_csv(self, data_rows):
16+
if data_rows:
17+
field_names = list(data_rows[0].keys())
18+
with open(self.csv_f_path,'w') as csv_wf:
19+
csv_writer = csv.DictWriter(csv_wf, fieldnames=field_names)
20+
csv_writer.writeheader()
21+
for row in data_rows:
22+
csv_writer.writerow(row)
23+
print('[+] Data Written Successfully ...')
24+
else:
25+
print('[-] Error : Data Rows Could not be empty ...')
26+
27+
def get_filtered_data(self, col_name, comparison, value):
28+
if not self.valid_headers:
29+
self.load()
30+
if not col_name in self.valid_headers:
31+
print('[-] Error : Enter Valid Column Name.')
32+
print('[*] Info : Allowed Column Names Are : {}'.format(', '.join(self.valid_headers)))
33+
else:
34+
if not comparison in self.allowed_comparison:
35+
print('[-] Error : Invalid Comparison.')
36+
print('[*] Info : Allowed Comparison Are : {}'.format(', '.join(self.allowed_comparison)))
37+
else:
38+
filtered_data = []
39+
with open(self.csv_f_path,'r') as c_file:
40+
csv_reader = csv.DictReader(c_file)
41+
for row_index, row in enumerate(csv_reader):
42+
try:
43+
if (comparison == '=='):
44+
if row[col_name] == value:
45+
row['update_index'] = row_index
46+
filtered_data.append(row)
47+
if (comparison == '!='):
48+
if row[col_name] != value:
49+
row['update_index'] = row_index
50+
filtered_data.append(row)
51+
except KeyError:
52+
continue
53+
return filtered_data
54+
55+
def update_data(self, update_index, col_name, value):
56+
if not self.valid_headers:
57+
self.load()
58+
if not col_name in self.valid_headers:
59+
print('[-] Error : Enter Valid Column Name.')
60+
print('[*] Info : Allowed Column Names Are : {}'.format(', '.join(self.valid_headers)))
61+
else:
62+
if not update_index:
63+
print('[-] Error Valid Data Index ....')
64+
else:
65+
try:
66+
update_index = int(update_index)
67+
except:
68+
print('[-] Error : Update Index is Not Valid')
69+
return
70+
updated_rows = []
71+
with open(self.csv_f_path,'r') as csv_rf:
72+
csv_reader = csv.DictReader(csv_rf)
73+
for row_index, row in enumerate(csv_reader):
74+
if update_index == row_index:
75+
print('[+] Updating Index {}'.format(update_index))
76+
row[col_name] = value
77+
updated_rows.append(row)
78+
self.write_dict_csv(updated_rows)
79+
80+
if __name__ == '__main__':
81+
82+
csv_path = 'dummy_data.csv'
83+
84+
#init class and get the object
85+
csv_obj = BetterCSVStorage(csv_path)
86+
87+
#Now user that object as storage
88+
89+
#Filter Data Based on Different parameters
90+
#This List will contain additional ( update_index ) which is row index of each row in csv.
91+
#This update_index will be use to update value of certain index.
92+
filtered_data = csv_obj.get_filtered_data('download_status', '==', '')
93+
94+
#Change Data Based on Different parameters
95+
csv_obj.update_data(4,'download_status', 'done')

Better_CSV_Storage/dummy_data.csv

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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

PdfToAudio/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Pdf to Audiobook Converter
2+
This python script generates audio for given pdf files.
3+
4+
## Dependencies / Requirements
5+
- PyPDF2. Install it by typing this command in your terminal `pip install PyPDF2`
6+
- pyttsx3. Install it by `pip install pyttsx3`

PdfToAudio/pdf_to_audiobook.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Importing the required packages.
2+
import PyPDF2
3+
import pyttsx3
4+
5+
text = None
6+
7+
# Reading a PDF file from your computer by specifying the path and setting the read mode to binary.
8+
pdf_reader = PyPDF2.PdfFileReader(open(r"D:\MyPdf.pdf", "rb"))
9+
10+
# Getting the handle to speaker i.e. creating a reference to pyttsx3.Engine instance.
11+
speaker = pyttsx3.init()
12+
13+
# Splitting the PDF file into pages and reading one at a time.
14+
for page_number in range(pdf_reader.numPages):
15+
text = pdf_reader.getPage(page_number).extractText()
16+
# Generating speech.
17+
speaker.say(text)
18+
speaker.runAndWait()
19+
20+
# Stopping the speaker after the complete audio has been created.
21+
speaker.stop()
22+
23+
# Saving the audiobook to your computer.
24+
engine = pyttsx3.init()
25+
engine.save_to_file(text, r"D:\MyAudio.mp3")
26+
engine.runAndWait()

PdfToAudio/requirements.txt.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
PyPDF2
2+
pyttsx3

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ So far, the following projects have been integrated to this repo:
2020
|[AI chatbot](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Artificial-intelligence_bot) |[umar abdullahi](https://github.com/umarbrowser) |
2121
|[Asymmetric Encryption](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/asymmetric_cryptography) |[victor matheus](https://github.com/victormatheusc) |
2222
|[Bitcoin price GUI](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Bitcoin-Price-GUI) |[Amirul Abu](https://github.com/amirulabu) |
23+
|[Better_CSV_Storage](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Better_CSV_Storage) | [Bhargav Kuvadiya](https://github.com/techdobz) |
2324
|[Cryptocurrency Converter](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Cryptocurrency-converter) |[AdnCodz](https://github.com/AdnCodez) |
2425
|[Cryptocurrency Prices](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Cryptocurrency-Prices) |[xemeds](https://github.com/xemeds) |
25-
|[Caesar Cipher](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/caeser_cipher) |[epi052](https://github.com/epi052) |
26+
|[Caesar Cipher](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/caesar_cipher) |[epi052](https://github.com/epi052) |
2627
|[Checksum tool](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Checksum) |[Austin Ewens](https://github.com/aewens) |
2728
|[Codechef autosubmitter](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Codechef-Code-Submitter) |[Harshit Mahajan](https://github.com/hmahajan99) |
2829
|[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:
100101
|[Asymmetric Encryption](asymmetric_cryptography) |[victor matheus](https://github.com/victormatheusc) |
101102
|[Bitcoin price GUI](Bitcoin-Price-GUI) |[Amirul Abu](https://github.com/amirulabu) |
102103
|[Cryptocurrency Converter](Cryptocurrency-converter) |[AdnCodz](https://github.com/AdnCodez) |
103-
|[Caesar Cipher](caeser_cipher) |[epi052](https://github.com/epi052) |
104+
|[Caesar Cipher](caesar_cipher) |[epi052](https://github.com/epi052) |
104105
|[Checksum tool](Checksum) |[Austin Ewens](https://github.com/aewens) |
105106
|[Codechef autosubmitter](Codechef-Code-Submitter) |[Harshit Mahajan](https://github.com/hmahajan99) |
106107
|[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:
196197
|[Pressure_Converter](https://github.com/E-wave112/Awesome-Python-Scripts/tree/master/Pressure_Converter)|[E-Wave](https://github.com/E-wave112)|
197198
| [File Carving](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/File_Carving) | [Yeryeong Kim](https://github.com/icarusicarus/) |
198199
|[Google Meet Joiner](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/google_meet_joiner)|[JohanSanSebastian](https://github.com/JohanSanSebastian)|
200+
|[Pdf to AudioBook Converter](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/PdfToAudio)|[Ayesha Gull](https://github.com/ayeshag7/)|
199201
|[Countdown](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Countdown)|[Jeremias Gomes](https://github.com/j3r3mias)|
200202

201203
## How to use :

caesar_cipher/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Simple caesar Cipher [En,De]coder
2+
3+
A simple implementation of a CLI tool to work with caesar ciphers. The default implementation is ROT-13, but can be
4+
adjusted for any offset. Works on files and string arguments passed via CLI.
5+
6+
```bash
7+
python3 caesar.py
8+
9+
usage: caesar.py [-h] [-d] [-o OFFSET] (-f FILE | -s STRING)
10+
caesar.py: error: one of the arguments -f/--file -s/--string is required
11+
```
12+
13+
```bash
14+
python3 caesar.py -s "have you tried turning it off and on again?"
15+
unir lbh gevrq gheavat vg bss naq ba ntnva?
16+
```
17+
18+
```bash
19+
python3 caesar.py -d -s "unir lbh gevrq gheavat vg bss naq ba ntnva?"
20+
have you tried turning it off and on again?
21+
```
22+
23+
```bash
24+
python3 caesar.py -s "have you tried turning it off and on again?" -o -4
25+
dwra ukq pneaz pqnjejc ep kbb wjz kj wcwej?
26+
```
27+
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
maketrans = str.maketrans # python3
1010

1111

12-
def caeser_cipher(string_: str, offset: int, decode: bool, file_: string) -> None:
13-
""" Caeser Cipher implementation, reads file or string. Also decodes.
12+
def caesar_cipher(string_: str, offset: int, decode: bool, file_: string) -> None:
13+
""" caesar Cipher implementation, reads file or string. Also decodes.
1414
1515
Default implementation is ROT13 encoding.
1616
@@ -59,7 +59,7 @@ def check_offset_range(value: int) -> int:
5959

6060

6161
if __name__ == '__main__':
62-
parser = argparse.ArgumentParser(description="Simple Caeser Cipher [En,De]coder")
62+
parser = argparse.ArgumentParser(description="Simple caesar Cipher [En,De]coder")
6363

6464
parser.add_argument('-d', '--decode', action='store_true', dest='decode',
6565
help='decode ciphertext (offset should equal what was used to encode)', default=False)
@@ -72,4 +72,4 @@ def check_offset_range(value: int) -> int:
7272

7373
args = parser.parse_args()
7474

75-
caeser_cipher(args.string, args.offset, args.decode, args.file)
75+
caesar_cipher(args.string, args.offset, args.decode, args.file)

caeser_cipher/README.md

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)