Skip to content

Commit

Permalink
Merge pull request #12 from kom-senapati/dat-removal
Browse files Browse the repository at this point in the history
Dat-removal
  • Loading branch information
rohitagr0310 authored Oct 8, 2023
2 parents 38f77b4 + 592b1e4 commit 47de613
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
24 changes: 24 additions & 0 deletions CS_Source Code.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,30 @@ def delete_roll():
os.rename("temp.dat", "stud.dat")
input("Press any key to continue....")

if not os.path.isfile("stud.dat"):
print("'stud.dat' file doesn't exist.")
print("1 -> Generate a new empty file")
print("2 -> Generate a file with fake data")

print(40 * "=")
choice = input("Enter your choice: ")
print(40 * "=")

if choice == "1":
try:
file = open("stud.dat", "wb")
file.close()
print("New empty file 'stud.dat' created.")
except Exception as e:
print(f"Error: {e}")
elif choice == "2":
print("Generating fake data...")
os.system("python create_dat.py")
print("Fake data generated.")
else:
print("Invalid choice!")
time.sleep(1)


while True:
os.system("cls")
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ For every school, an important task for the administration department is to mana

- [MySQL](https://dev.mysql.com/downloads/mysql/)
- [MySQL Python Connector](https://dev.mysql.com/downloads/connector/python/)
- fake
```bash
pip install fake
```

##### 2. Install MySQL in Python using below command

Expand Down
37 changes: 37 additions & 0 deletions create_dat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from fake import Faker
import random
import pickle

class Student:
def __init__(self, roll, name, percentage):
self.roll = roll
self.name = name
self.percentage = percentage

def generate_fake_records(n):
fake = Faker()
records = []

for _ in range(n):
roll = random.randint(1000, 9999)
name = fake.name()
percentage = round(random.uniform(50, 100), 2)

student = Student(roll, name, percentage)
records.append(student)

return records

def save_to_dat(records):
try:
with open("fake_stud.dat", "wb") as file:
for record in records:
pickle.dump(record, file)
print(f"{len(records)} fake records saved to fake_stud.dat")
except Exception as e:
print(f"Error: {e}")

if __name__ == "__main__":
n = int(input("Enter the number of fake records to generate: "))
fake_records = generate_fake_records(n)
save_to_dat(fake_records)

0 comments on commit 47de613

Please sign in to comment.