File

FILE: projects/patch_marketplace_dashboard.py
SIZE: 4620 bytes
SHA256: 70d32556b47cd92a2b827bce666e7b0ab2349004926151cb39bd7e0a3b5c7483
Lines: 37

Use path as FILE | Patch Context | Read first 100 | Read prev 100 | Read next 100 | Git diff this file | Code Buffers | Active Patch Context

LineTextActions
1
from pathlib import Path
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
2
import hashlib, os, time
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
3
root = Path(r'C:\Users\ash\Documents\ShopeeApi\app\static')
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
4
idx = root / 'index.html'
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
5
js = root / 'app.js'
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
6
expected = {idx:'f66c123631927ac7553a941a98fe84b57a25234ef13be8299117394419e6c320',js:'7bece52afafdaf5b4d5bc8c26f4ff6f37d40f68833be92212b4f5f0a5043ad13'}
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
7
for p,sha in expected.items():
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
8
    actual=hashlib.sha256(p.read_bytes()).hexdigest()
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
9
    if actual!=sha: raise SystemExit(f'SHA_PRECONDITION_FAILED {p} expected={sha} actual={actual}')
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
10
idx_text=idx.read_text(encoding='utf-8')
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
11
repls=[('<title>Shopee Operations Hub</title>','<title>Marketplace Operations Hub</title>'),('<p class=\"eyebrow\">DIY ADIL - SHOPEE OPERATIONS</p>','<p class=\"eyebrow\">DIY ADIL - MARKETPLACE OPERATIONS</p>'),('<h1>Shopee Dashboard Manager</h1>','<h1>Marketplace Dashboard</h1>'),('Dashboard operasi: Ready To Ship, packing, stok, analytics, AWB dan sync Shopee.','Dashboard operasi multi-platform: Ready To Ship, packing, stok, analytics, AWB dan sync marketplace.'),('>Download Shopee Operations</a>','>Download Operations APK</a>'),('<label class=\"shop-switcher\"><span>Shop utama</span>','<label class=\"shop-switcher\"><span>Kedai utama</span>'),('Income sebenar selepas caj Shopee dan kos produk','Income sebenar selepas caj marketplace dan kos produk'),('Payout sebenar ikut tarikh Shopee release. Nilai belum settle ditanda sebagai anggaran.','Payout sebenar ikut tarikh marketplace release. Nilai belum settle ditanda sebagai anggaran.'),('<p class=\"eyebrow\">POTONGAN SHOPEE</p>','<p class=\"eyebrow\">POTONGAN PLATFORM</p>'),('<p class=\"eyebrow\">KATALOG SHOPEE</p>','<p class=\"eyebrow\">KATALOG MARKETPLACE</p>'),('<label>Status Shopee<select id=\"productStatus\">','<label>Status platform<select id=\"productStatus\">'),('<th>Produk Shopee</th>','<th>Produk marketplace</th>'),('>Setting Inventori &amp; Shopee</a>','>Setting Inventori &amp; Marketplace</a>'),('Token Shopee tidak perlu authorize semula jika refresh token masih sah.','Token marketplace sedia ada tidak perlu authorize semula jika refresh token masih sah.'),('<script src=\"/static/app.js?v=health-retry-20260827-v1\"></script>','<script src=\"/static/app.js?v=marketplace-ready-20260831-v1\"></script>')]
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
12
for old,new in repls:
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
13
    if idx_text.count(old)!=1: raise SystemExit(f'INDEX_ANCHOR_FAILED count={idx_text.count(old)} old={old[:80]}')
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
14
    idx_text=idx_text.replace(old,new,1)
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
15
js_text=js.read_text(encoding='utf-8')
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
16
needle="function shopLabel(shopId){\n  return shopId  ?  `Shop ${shopId}` : 'Shop';\n}\n"
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
17
helper="function shopLabel(shopId){\n  return shopId  ?  `Shop ${shopId}` : 'Shop';\n}\nfunction shopPlatform(shopOrId){\n  const shop = typeof shopOrId === 'object' && shopOrId !== null\n    ? shopOrId\n    : (state.shops || []).find(item => Number(item.shop_id || 0) === Number(shopOrId || 0));\n  return String(shop?.platform || shop?.marketplace || 'SHOPEE').trim().toUpperCase() || 'SHOPEE';\n}\nfunction activePlatform(){\n  return shopPlatform(state.shopId);\n}\n"
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
18
if js_text.count(needle)!=1: raise SystemExit('SHOP_HELPER_ANCHOR_FAILED')
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
19
js_text=js_text.replace(needle,helper,1)
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
20
pairs=[('<small>${esc(id)}  |  ${esc(onboardingLabel(shop))}</small>','<small>${esc(shopPlatform(shop))}  |  ${esc(id)}  |  ${esc(onboardingLabel(shop))}</small>'),('${esc(shop.name || `Shop ${id}`)} (${esc(id)})  |  ${esc(meta)}','[${esc(shopPlatform(shop))}] ${esc(shop.name || `Shop ${id}`)} (${esc(id)})  |  ${esc(meta)}')]
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
21
for old,new in pairs:
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
22
    if js_text.count(old)!=1: raise SystemExit(f'JS_ANCHOR_FAILED {old[:60]}')
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
23
    js_text=js_text.replace(old,new,1)
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
24
js_text=js_text.replace("platform: 'SHOPEE',","platform: activePlatform(),")
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
25
js_text=js_text.replace("payload.platform || 'SHOPEE'","payload.platform || activePlatform()")
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
26
js_text=js_text.replace("ds.platform || 'SHOPEE'","ds.platform || activePlatform()")
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
27
js_text=js_text.replace("$('registryPlatform')?.value || 'SHOPEE'","$('registryPlatform')?.value || activePlatform()")
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
28
if "platform: 'SHOPEE'," in js_text: raise SystemExit('HARDCODED_PLATFORM_REMAINS')
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
29
stamp=time.strftime('%Y%m%dT%H%M%S')
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
30
for p,content in ((idx,idx_text),(js,js_text)):
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
31
    backup=p.with_name(p.name+f'.pre-marketplace-{stamp}.bak'); backup.write_bytes(p.read_bytes())
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
32
    tmp=p.with_name(p.name+'.marketplace.tmp')
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
33
    with tmp.open('w',encoding='utf-8',newline='\n') as f: f.write(content); f.flush(); os.fsync(f.fileno())
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
34
    os.replace(tmp,p)
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
35
print('MARKETPLACE_DASHBOARD_PATCH_OK')
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
36
print('INDEX_SHA='+hashlib.sha256(idx.read_bytes()).hexdigest())
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A
37
print('APPJS_SHA='+hashlib.sha256(js.read_bytes()).hexdigest())
Use FILE Use as OLD Use as NEW Open Patch Composer +/-3 CONTEXT +/-10 CONTEXT +/-25 CONTEXT Append to Buffer A