-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmgp_bill_calculator.py
More file actions
executable file
·86 lines (72 loc) · 2.3 KB
/
Copy pathmgp_bill_calculator.py
File metadata and controls
executable file
·86 lines (72 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python3
import re
import sys
import subprocess
import requests
import datetime
from rich.console import Console
from rich.table import Table
date = datetime.datetime.now().strftime('%m%Y')
if len(sys.argv) > 1:
date = sys.argv[1]
def calculate_bill(bill, ignore = 0):
if(date.startswith('04')):
ignore = 240
bill = float(bill)
temp = (bill - ignore) / 100
temp = round(temp,2)
temp *= 100
temp *= 0.03
bill += temp
global total_commission
total_commission += int(temp)
return('\u20b9' + str(int(bill)))
url = f'https://nehainfotech.co.in/bills/16508PO_sum_{date}.pdf'
with requests.get(url, stream=True) as response:
with open(f'{date}.pdf', mode='wb') as file:
for chunk in response.iter_content(chunk_size=10 * 1024):
file.write(chunk)
subprocess.run(
f"pdftotext {date}.pdf grahak-bill.txt",
shell=True
)
subprocess.run(f"rm {date}.pdf", shell=True)
table = Table(title=f"grahak-bill {date}", show_lines=True)
table.add_column("Name")
table.add_column("Amount", style="green")
table.add_column("Bags", style="yellow")
total_commission = 0
content = ""
lines = []
with open("grahak-bill.txt") as file:
lines = file.readlines()
subprocess.run("rm grahak-bill.txt", shell=True)
save = False
for line in lines:
if save:
if re.search('^-',line):
save = False
break
content += ''.join(line)
if not save and re.search('-?#', line):
save = True
names = re.findall(r'[A-Z]+\s[A-Z]+\s[A-Z]+', content)
bags_bill = re.findall(r'[0-9]+\s\|\s[0-9]+\.[0-9]', content)
if(len(names) != len(bags_bill)):
print("Error while parsing: count mismatch")
exit(1)
bills = [ x.split()[-1] for x in bags_bill ]
bags = [ x.split()[0] for x in bags_bill ]
for name, bill, bag in zip(names, bills, bags):
if 'AARTI' in name:
continue
table.add_row(
''.join(
[ x.capitalize() + ' ' for x in name.split()]
),
calculate_bill(bill),
bag
)
console = Console()
console.print(table)
print("\nTotal commission :", total_commission)