Last active
May 31, 2025 06:34
-
-
Save motebaya/81db6e8124523db834c4816b750b8790 to your computer and use it in GitHub Desktop.
request a personal data download through your account setting...usually it’s quick, takes less than a day, and you’ll get a pdf report.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# d: 28/05/2025 12:44:41 | |
# you need this dawg: https://pypi.org/project/PyMuPDF/ | |
import re | |
from datetime import datetime | |
PDF = "download.pdf" | |
PWS = "password123" | |
b = {k: f"{i:02}" for i, ks in enumerate([["Jan","Januari"],["Feb","Februari"],["Mar","Maret"],["Apr","April"],["Mei"],["Jun","Juni"],["Jul","Juli"],["Agu","Agustus"],["Sep","September"],["Okt","Oktober"],["Nov","November"],["Des","Desember"]],1) for k in ks} | |
t, total = {}, 0 | |
for i in filter(lambda x: x.get("status") == "Berhasil", [dict( | |
invoice=i.split("Status")[0].strip(), | |
**{k: (m:=re.search(p, i, re.IGNORECASE | re.MULTILINE)) and m.group(1).strip().replace("\n", " ") for k, p in { | |
"status": r"status\s*\n(.+)", | |
"tdate": r"tanggal order\s*(.+)", | |
"produk": r"nama produk\s*\n(.+)", | |
"penjual": r"nama penjual\s*(.+)", | |
"jumlah_total": r"jumlah total\s*Rp\s?([\d.]+)", | |
}.items()} | |
) for i in re.split( | |
r"No\. Invoice\s*", "".join(p.get_text() for p in ( | |
lambda d: (d.authenticate(PWS) if d.needs_pass else None, d)[-1])( | |
__import__("fitz").open(PDF))) | |
)[1:]]): | |
s = i.get("tdate","").split(",",1)[-1].strip() | |
for k in b: | |
if f" {k} " in s: | |
s = s.replace(f" {k} ", f"-{b[k]}-") | |
break | |
try: | |
dt = datetime.strptime(s,"%d-%m-%Y %H:%M:%S") | |
k = dt.strftime("%B %Y") | |
v = int(i["jumlah_total"].replace(".","")) | |
t[k] = t.get(k,0)+v | |
total+=v | |
except: ... | |
open('report.txt', 'w', encoding="utf-8").write("\n".join( | |
[f"{'Month/Year':<15} | Total (Rp)", "-"*30] + | |
[f"{k:<15} | {t[k]:,}".replace(",",".") for k in sorted(t, key=lambda x: datetime.strptime(x,"%B %Y"))] + | |
["-"*30, | |
f"{'Total':<15} | {total:,}".replace(",","."), | |
f"{'Months':<15} | {len(t):,}".replace(",", "."), | |
f"{'Years':<15} | {len(t)/12:.2f}".replace(".", ",") | |
] | |
)) | |
print('ok') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment