-
Notifications
You must be signed in to change notification settings - Fork 0
commit of homework no. 10 - invoice generator #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| # | ||
| # české názvy jsou ponechány po vzoru zadání | ||
|
|
||
| from datetime import datetime, timedelta | ||
| import requests | ||
| import random | ||
| import json | ||
| import qrcode | ||
| now = datetime.now() | ||
| url = (f'https://data.kurzy.cz/json/meny/b[2]den[{now.strftime("%Y%m%d")}].json') | ||
|
|
||
|
|
||
| class CurrencyError(Exception): | ||
| def __init__(self, name): | ||
| self.name = name | ||
|
|
||
| def __str__(self): | ||
| return(f'Tato měna není na seznamu') | ||
|
|
||
|
|
||
| class LoadExchangeRates(): | ||
| def __init__(self, name): | ||
| self.name = name | ||
|
|
||
| def load_data(self): | ||
| exchange = requests.get(url=url) | ||
| with open("kurz_cnb.json", 'wb') as text_file: | ||
| text_file.write(exchange.content) | ||
|
|
||
| def exchange_rates(self): | ||
| with open("kurz_cnb.json", 'r') as text_file: | ||
| data = json.load(text_file) | ||
| json_date = datetime.strptime(data["den"], "%Y%m%d") | ||
| if now - json_date > timedelta(days=1): | ||
| LoadExchangeRates.load_data(self) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Toto nie je správne, nakoľko aktuálne si pristúpila k danej metóde ak k statickej. Ty chceš pristupovať priamo z instancie, teda správne Toto je dosť potrebné aby si pochopila... takže sa pýtaj. |
||
|
|
||
|
|
||
| class Payment: | ||
| def __init__(self, name, currency, amount_of_money): | ||
| self.name = name | ||
| self.currency = currency | ||
| self.amount_of_money = amount_of_money | ||
|
|
||
| def run_app(self): | ||
| if self.currency != 'KČ' or self.currency == None: | ||
| Convertor.convert(self) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Na nasledujúcich 4 riadkoch je podobný problém, ako vyšie... zlý spôsob volania metódy na danej instancii. |
||
| LoadExchangeRates.load_data(self) | ||
| Generator.vs_generator(self) | ||
| Generator.qr_generator(self) | ||
|
|
||
|
|
||
| class Convertor(Payment): | ||
| def convert(self): | ||
| with open("kurz_cnb.json", "r") as text_file: | ||
| data = json.load(text_file) | ||
| if self.currency in data["kurzy"]: | ||
| exchange_rate = data["kurzy"][self.currency]["dev_stred"] | ||
| exchange_unit = 1/data["kurzy"][self.currency]["jednotka"] | ||
| self.amount_of_money = int(self.amount_of_money) *\ | ||
| exchange_unit * exchange_rate | ||
| type(exchange_unit) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Toto je asi nejaký zabudnutý artefakt z vývoja... 🤔 |
||
| else: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ak by si celú túto podmeinku otočila, tak by si sa zbavila |
||
| raise CurrencyError(self) | ||
|
|
||
|
|
||
| class Generator(Payment): | ||
| def vs_generator(self): | ||
| list_of_remaining_numbers = list(range(999999)) | ||
| self.symbol = random.choice(list_of_remaining_numbers) | ||
| list_of_remaining_numbers.remove(self.symbol) | ||
|
|
||
| def qr_generator(self): | ||
| self.iban = 'CZ2030300000001280704082' | ||
| self.message = (f'SPD*1.0*ACC:{self.iban}*AM:{self.amount_of_money}\ | ||
| *CC:CZK*X-VS:{self.symbol}*MSG:{self.name}') | ||
| self.qr = qrcode.QRCode( | ||
| version=1, | ||
| box_size=10, | ||
| border=5) | ||
|
|
||
| self.qr.add_data(self.message) | ||
| self.qr.make(fit=True) | ||
| img = self.qr.make_image(fill='black', back_color='white') | ||
| img.save(f'qr_code{self.symbol}.png') | ||
|
|
||
| def template_generator(self): | ||
| with open('template.html', 'r') as html_file: | ||
| data = html_file.read() | ||
| data = data.replace('symbol', str(self.symbol)) | ||
| data = data.replace('name', self.name) | ||
| data = data.replace('amount_of_money', str(self.amount_of_money)) | ||
| data = data.replace('iban', self.iban) | ||
| data = data.replace('qr_code', (f'qr_code{self.symbol}.png')) | ||
| with open(f'invoice{self.symbol}.html', 'w') as html_file: | ||
| html_file.write(data) | ||
|
|
||
|
|
||
| print('''Generátor faktur. | ||
| Částka v jiných měnách než Kč, bude převedena na koruny podle platného kurzu ČNB.''') | ||
| payment = input('Zadej položku platby: ') | ||
| amount_of_money = input('Částka: ') | ||
| while not amount_of_money.isnumeric(): | ||
| print('Částka musí být číslo') | ||
| amount_of_money = input('Částka: ') | ||
| while int(amount_of_money) <= 0: | ||
| print('Částka musí být kladné číslo') | ||
| amount_of_money = int(input('Částka: ')) | ||
| currency = input('Měna: ').upper() | ||
| payment = Payment(payment, currency, amount_of_money) | ||
|
|
||
|
|
||
| Payment.run_app(payment) | ||
|
|
||
| print('Generuji fakturu...') | ||
|
|
||
| Generator.template_generator(payment) | ||
|
|
||
| print(f'Faktura je hotová na odkaze <Ukoly/DU_10/invoice{payment.symbol}.html>') | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| {"den":"20221202","denc":"2.12.2022","banka":"\u010Cesk\u00E1 spo\u0159itelna","url":"https://www.kurzy.cz/kurzy-men/kurzovni-listek/ceska-sporitelna/","kurzy":{ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tento súbor by bolo možno dobré pridať do |
||
| "AUD":{"jednotka":1,"dev_stred":15.833,"dev_nakup":15.437,"dev_prodej":16.229,"val_stred":15.833,"val_nakup":15.28,"val_prodej":16.39,"nazev":"Australsk\u00FD dolar","url":"https://www.kurzy.cz/aud"}, | ||
| "GBP":{"jednotka":1,"dev_stred":28.456,"dev_nakup":27.745,"dev_prodej":29.168,"val_stred":28.456,"val_nakup":27.46,"val_prodej":29.45,"nazev":"Britsk\u00E1 libra","url":"https://www.kurzy.cz/gbp"}, | ||
| "BGN":{"jednotka":1,"dev_stred":12.466,"dev_nakup":12.155,"dev_prodej":12.778,"val_stred":0,"val_nakup":0,"val_prodej":0,"nazev":"Bulharsk\u00FD lev","url":"https://www.kurzy.cz/bgn"}, | ||
| "DKK":{"jednotka":1,"dev_stred":3.278,"dev_nakup":3.196,"dev_prodej":3.36,"val_stred":3.278,"val_nakup":3.16,"val_prodej":3.39,"nazev":"D\u00E1nsk\u00E1 koruna","url":"https://www.kurzy.cz/dkk"}, | ||
| "EUR":{"jednotka":1,"dev_stred":24.38,"dev_nakup":23.771,"dev_prodej":24.99,"val_stred":24.38,"val_nakup":23.53,"val_prodej":25.23,"nazev":"Euro","url":"https://www.kurzy.cz/eur"}, | ||
| "HKD":{"jednotka":1,"dev_stred":2.978,"dev_nakup":2.904,"dev_prodej":3.052,"val_stred":0,"val_nakup":0,"val_prodej":0,"nazev":"Hongkongsk\u00FD dolar","url":"https://www.kurzy.cz/hkd"}, | ||
| "HRK":{"jednotka":1,"dev_stred":3.229,"dev_nakup":3.149,"dev_prodej":3.31,"val_stred":3.229,"val_nakup":3.12,"val_prodej":3.34,"nazev":"Chorvatsk\u00E1 kuna","url":"https://www.kurzy.cz/hrk"}, | ||
| "JPY":{"jednotka":100,"dev_stred":17.082,"dev_nakup":16.655,"dev_prodej":17.51,"val_stred":17.082,"val_nakup":16.48,"val_prodej":17.68,"nazev":"Japonsk\u00FD jen","url":"https://www.kurzy.cz/jpy"}, | ||
| "ZAR":{"jednotka":1,"dev_stred":1.315,"dev_nakup":1.282,"dev_prodej":1.348,"val_stred":0,"val_nakup":0,"val_prodej":0,"nazev":"Jihoafrick\u00FD rand","url":"https://www.kurzy.cz/zar"}, | ||
| "CAD":{"jednotka":1,"dev_stred":17.263,"dev_nakup":16.832,"dev_prodej":17.695,"val_stred":17.263,"val_nakup":16.66,"val_prodej":17.87,"nazev":"Kanadsk\u00FD dolar","url":"https://www.kurzy.cz/cad"}, | ||
| "HUF":{"jednotka":100,"dev_stred":5.924,"dev_nakup":5.776,"dev_prodej":6.072,"val_stred":5.924,"val_nakup":5.72,"val_prodej":6.13,"nazev":"Ma\u010Farsk\u00FD forint","url":"https://www.kurzy.cz/huf"}, | ||
| "NOK":{"jednotka":1,"dev_stred":2.379,"dev_nakup":2.32,"dev_prodej":2.439,"val_stred":2.379,"val_nakup":2.3,"val_prodej":2.46,"nazev":"Norsk\u00E1 koruna","url":"https://www.kurzy.cz/nok"}, | ||
| "NZD":{"jednotka":1,"dev_stred":14.816,"dev_nakup":14.445,"dev_prodej":15.186,"val_stred":0,"val_nakup":0,"val_prodej":0,"nazev":"Novoz\u00E9landsk\u00FD dolar","url":"https://www.kurzy.cz/nzd"}, | ||
| "PLN":{"jednotka":1,"dev_stred":5.197,"dev_nakup":5.067,"dev_prodej":5.327,"val_stred":5.197,"val_nakup":5.01,"val_prodej":5.38,"nazev":"Polsk\u00FD zlot\u00FD","url":"https://www.kurzy.cz/pln"}, | ||
| "RON":{"jednotka":1,"dev_stred":4.946,"dev_nakup":4.822,"dev_prodej":5.07,"val_stred":0,"val_nakup":0,"val_prodej":0,"nazev":"Rumunsk\u00FD nov\u00FD lei","url":"https://www.kurzy.cz/ron"}, | ||
| "SEK":{"jednotka":1,"dev_stred":2.243,"dev_nakup":2.187,"dev_prodej":2.299,"val_stred":2.243,"val_nakup":2.16,"val_prodej":2.32,"nazev":"\u0160v\u00E9dsk\u00E1 koruna","url":"https://www.kurzy.cz/sek"}, | ||
| "CHF":{"jednotka":1,"dev_stred":24.715,"dev_nakup":24.097,"dev_prodej":25.332,"val_stred":24.715,"val_nakup":23.85,"val_prodej":25.58,"nazev":"\u0160v\u00FDcarsk\u00FD frank","url":"https://www.kurzy.cz/chf"}, | ||
| "TND":{"jednotka":1,"dev_stred":7.222,"dev_nakup":7.042,"dev_prodej":7.403,"val_stred":0,"val_nakup":0,"val_prodej":0,"nazev":"Tunisk\u00FD din\u00E1r","url":"https://www.kurzy.cz/tnd"}, | ||
| "TRY":{"jednotka":1,"dev_stred":1.244,"dev_nakup":1.213,"dev_prodej":1.275,"val_stred":0,"val_nakup":0,"val_prodej":0,"nazev":"Tureck\u00E1 lira","url":"https://www.kurzy.cz/try"}, | ||
| "USD":{"jednotka":1,"dev_stred":23.175,"dev_nakup":22.596,"dev_prodej":23.754,"val_stred":23.175,"val_nakup":22.36,"val_prodej":23.99,"nazev":"Americk\u00FD dolar","url":"https://www.kurzy.cz/usd"}}} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <html> | ||
| <head> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nakoľko používaš diakritiku, tak by som sem odporučil prihodiť |
||
| <title>Faktura číslo 'symbol'</title> | ||
| </head> | ||
| <body> | ||
| <h1>Platba za name </h1> | ||
| <p>Částka: amount_of_money Kč</p> | ||
| <p>Na účet: iban </p> | ||
| <p>VS: symbol </p> | ||
| <h2>QR platba</h2> | ||
| <p><img src="qr_code"></p> | ||
| </body> | ||
| </html> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| class band_member: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tento súbor si sem asi dať nechcela 😅... pri vytváraní nových branchov by som odporučil najprv checkout na mastera a z neho následne vytvárať... |
||
| def __init__(self, name): | ||
| self.name = name | ||
|
|
||
| def play(self): | ||
| print(f'{self.name} plays on {self.instrument}') | ||
|
|
||
|
|
||
| class guitarist(band_member): | ||
| def play(self, number_of_strings): | ||
| self.number_of_strings = number_of_strings | ||
| if self.number_of_strings >= 4 and self.number_of_strings < 6: | ||
| self.instrument = 'bass guitar' | ||
| elif self.number_of_strings >= 6: | ||
| self.instrument = 'solo guitar' | ||
| super().play() | ||
|
|
||
|
|
||
| class singer(band_member): | ||
| def play(self): | ||
| print(f'{self.name} sings') | ||
|
|
||
|
|
||
| class drummer(band_member): | ||
| instrument = 'drums' | ||
|
|
||
| def __init__(self, name): | ||
| self.number_of_sticks = 2 | ||
| super().__init__(name) | ||
|
|
||
| def throw_a_stick(self): | ||
| self.number_of_sticks += 1 | ||
|
|
||
| def number_of_throwen_sticks(self): | ||
| if self.throw_a_stick(): | ||
| self.number_of_sticks += 2 | ||
| print(f'{self.name} allready threw {self.number_of_sticks} into the crowd.') | ||
|
|
||
|
|
||
| Tom = singer('Tom') | ||
|
|
||
| Jan = guitarist('Jan') | ||
| Jan.number_of_strings = 4 | ||
|
|
||
| Vojta = guitarist('Vojta') | ||
| Vojta.number_of_strings = 7 | ||
|
|
||
| Filip = guitarist('Filip') | ||
| Filip.number_of_strings = 6 | ||
|
|
||
| Martin = drummer('Martin') | ||
| for _ in range(3): | ||
| Martin.throw_a_stick() | ||
| Martin.number_of_throwen_sticks() | ||
|
|
||
|
|
||
| guitarists = [Jan, Vojta, Filip] | ||
| members = [Martin, Tom] | ||
|
|
||
| for guitarist in guitarists: | ||
| guitarist.play(guitarist.number_of_strings) | ||
|
|
||
| for member in members: | ||
| member.play() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, ale ten český komentár byť nemusel... ale to je maličkosť 😄.