Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import matplotlib.pyplot as plt
- import numpy as np
- from tabulate import tabulate
- from collections import Counter
- def tabelarno(phoneList):
- mydata = phoneList
- head = ["Ime", "Proizvođač", "Procesor", "Megapikseli kamere", "Boja", "Cena"]
- print(tabulate(mydata, headers=head, tablefmt="grid"))
- def plot_phone_prices(phoneList):
- # izdvajanje cena
- cene = [float(phone[5]) for phone in phoneList]
- # pravljenje bar charta
- plt.bar(range(len(phoneList)), cene, tick_label=[phone[0] for phone in phoneList])
- plt.xlabel('Modeli telefona')
- plt.ylabel('Cena (EUR)')
- plt.title('Cene telefona')
- plt.xticks(rotation=45) # zbog citljivosti
- plt.show()
- def plot_zastupljenost_brendova(phoneList):
- brendovi = [phone[1] for phone in phoneList]
- brojac_brendova = Counter(brendovi)
- plt.pie(brojac_brendova.values(), labels=brojac_brendova.keys(), autopct='%1.1f%%')
- plt.title('Zastupljenost brendova')
- plt.show()
- def register():
- status = True
- while status:
- status = False
- username = input("Unesite korisnicko ime: ")
- with open("users.txt", "r") as file:
- for line in file:
- s = line.strip().split(":")
- if username == s[0]:
- status = True
- break
- if status:
- print("Korisnicko ime vec postoji, pokusajte ponovo! ")
- else:
- password = input("Unesite lozinku: ")
- with open("users.txt", "a") as file:
- file.write(f"{username}:{password}\n")
- print("Registracija uspesna!")
- def login():
- username = input("Unesite korisničko ime: ")
- password = input("Unesite lozinku: ")
- tacnaSifra = False
- while not tacnaSifra:
- with open("users.txt", "r") as file:
- for line in file:
- stored_username, stored_password = line.strip().split(":")
- if username == stored_username and password == stored_password:
- tacnaSifra = True
- if not tacnaSifra:
- print("Netačno korisničko ime ili lozinka.")
- username = input("Unesite korisničko ime: ")
- password = input("Unesite lozinku: ")
- print("Uspešno ste se ulogovali")
- def admin_login():
- adminlogin = input("Unesite administratorsko ime: ")
- adminpass = input("Unesite administratorsku lozinku: ")
- tacnaSifra = False
- while not tacnaSifra:
- with open("admins.txt", "r") as file:
- for line in file:
- stored_username, stored_password = line.strip().split(":")
- if adminlogin == stored_username and adminpass == stored_password:
- tacnaSifra = True
- if not tacnaSifra:
- print("Netačno korisničko ime ili lozinka.")
- adminlogin = input("Unesite korisničko ime: ")
- adminlogin = input("Unesite lozinku: ")
- print("Imate admin pristup.")
- def obrisiNalog(username):
- # administratorska funkcija
- try:
- # pravimo listu korisnika, laksa manipulacija
- userList = []
- infile = open("users.txt", "r")
- # citam red po red
- line = infile.readline()
- while line:
- userList.append(line.rstrip("\n").split(":"))
- line = infile.readline()
- infile.close()
- except FileNotFoundError:
- print("Nema fajla sa korisnicima, pravim novi")
- userList = []
- os.system('cls')
- status = False
- for t in userList:
- if username == t[0]:
- while not status:
- userList.remove(t)
- print("Uspesno brisanje izabranog naloga")
- fajl = open("users.txt", "w")
- for t in userList:
- fajl.write(t[0] + ":" + t[1] + "\n")
- fajl.close()
- exit()
- else:
- print("Takav nalog ne postoji. ")
- #def obrisiTelefon():
- # administratorska funkcija
- def save_phone_list(phoneList):
- try:
- with open("phoneList.txt", "w") as outfile:
- for phone in phoneList:
- # Join the phone data into a comma-separated string
- phone_line = ",".join(phone)
- outfile.write(phone_line + "\n")
- outfile.close()
- print("Lista telefona uspešno sačuvana.")
- except IOError:
- print("Greška pri čuvanju liste.")
- def main():
- print("Dobrodošli!")
- choice = 0
- while choice != "1" and choice != "2":
- choice = input("Unesite '1' za registraciju, '2' za prijavu: ")
- if choice != "1" and choice != "2":
- print("Nepravilan izbor " + choice)
- if choice == "1":
- register()
- elif choice == "2":
- login()
- elif choice == "3":
- admin_login()
- try:
- # lista telefona
- phoneList = []
- infile = open("phoneList.txt", "r")
- # citamo red po red
- line = infile.readline()
- while line: # is true
- phoneList.append(line.rstrip("\n").split(","))
- line = infile.readline()
- infile.close()
- # ovo cita i apenduje sve dok ne ponestane za citanje
- except FileNotFoundError:
- print("Fajl telefona nije pronadjen. ")
- print("Pravim novu listu! ")
- phoneList = []
- choice = 0
- while choice != "8":
- print("Menadzer telfona")
- print("1) Dodaj telefon")
- print("2) Pretrazi telefon")
- print("3) Prikazi telefone")
- print("4) Prikazi graf cena")
- print("5) Tabelarni prikaz")
- print("6) Prikaz zastupljenosti brendova")
- print("7) Izlađi i sačuvaj")
- choice = int(input())
- if choice == 1:
- print("Dodajem telefon...")
- nPhone = input("Unesi ime telefona: ")
- nManufacturer = input("Unesi proizvodjaca telefona: ")
- nCPU = input("Unesi procesor: ")
- nCamera = input("Unesi MP kamere: ")
- nColor = input("Unesi boju uredjaja: ")
- nPrice = input("Unesi cenu uredjaja: ")
- phoneList.append([nPhone, nManufacturer, nCPU, nCamera, nColor, nPrice])
- elif choice == 2:
- print("Pretrazujem telefon...")
- keyword = input("Unesi kljucnu rec: ")
- for phone in phoneList:
- if keyword in phone:
- print(phone)
- elif choice == 3:
- print("Stampam sve unete telefone...")
- for i in range(len(phoneList)):
- print(phoneList[i])
- elif choice == 4:
- print("Graficki prikaz cena: ")
- plot_phone_prices(phoneList)
- elif choice == 5:
- tabelarno(phoneList)
- elif choice == 6:
- plot_zastupljenost_brendova(phoneList)
- elif choice == 7:
- print("Izlazim iz programa")
- save_phone_list(phoneList)
- exit()
- print("Program prekinut. ")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement