118 lines
5.3 KiB
Python
Executable file
118 lines
5.3 KiB
Python
Executable file
import json, csv, sqlite3
|
|
|
|
MASTER_V2_PATH = '/workspace/ecommerce_research_sources/benchmark_master_v2.json'
|
|
TIMELINE_DATA_PATH = '/workspace/ecommerce_research_sources/timeline_deep_dataset.json'
|
|
DB_PATH = '/workspace/ecommerce_research_sources/ecommerce_brands_research.db'
|
|
|
|
with open(MASTER_V2_PATH, 'r', encoding='utf-8') as f:
|
|
master = json.load(f)
|
|
|
|
with open(TIMELINE_DATA_PATH, 'r', encoding='utf-8') as f:
|
|
timeline = json.load(f)
|
|
|
|
# 1. commissions_and_contracts.csv
|
|
commissions = master.get('commissions_data', [])
|
|
if commissions:
|
|
keys = list(commissions[0].keys())
|
|
with open('/workspace/ecommerce_research_sources/commissions_and_contracts.csv', 'w', encoding='utf-8-sig', newline='') as f:
|
|
writer = csv.DictWriter(f, fieldnames=keys, extrasaction='ignore')
|
|
writer.writeheader()
|
|
for row in commissions:
|
|
row_copy = row.copy()
|
|
if isinstance(row_copy.get('top_brands'), list):
|
|
row_copy['top_brands'] = ' | '.join(row_copy['top_brands'])
|
|
writer.writerow(row_copy)
|
|
|
|
# 2. growth_levers_analysis.csv
|
|
growth_levers = master.get('growth_levers_data', [])
|
|
if growth_levers:
|
|
keys = list(growth_levers[0].keys())
|
|
with open('/workspace/ecommerce_research_sources/growth_levers_analysis.csv', 'w', encoding='utf-8-sig', newline='') as f:
|
|
writer = csv.DictWriter(f, fieldnames=keys, extrasaction='ignore')
|
|
writer.writeheader()
|
|
for row in growth_levers:
|
|
writer.writerow(row)
|
|
|
|
# 3. revenue_models_roadmap.csv
|
|
revenue_models = master.get('revenue_models_data', [])
|
|
if revenue_models:
|
|
keys = list(revenue_models[0].keys())
|
|
with open('/workspace/ecommerce_research_sources/revenue_models_roadmap.csv', 'w', encoding='utf-8-sig', newline='') as f:
|
|
writer = csv.DictWriter(f, fieldnames=keys, extrasaction='ignore')
|
|
writer.writeheader()
|
|
for row in revenue_models:
|
|
writer.writerow(row)
|
|
|
|
# 4. yearly_metrics_timeline.csv
|
|
years = timeline.get('yearly_metrics', [])
|
|
with open('/workspace/ecommerce_research_sources/yearly_metrics_timeline.csv', 'w', encoding='utf-8-sig', newline='') as f:
|
|
writer = csv.writer(f)
|
|
writer.writerow(['سال شمسی', 'سال میلادی', 'فاز توسعه', 'تنوع کالا (SKU)', 'فروشندگان فعال', 'سفارش روزانه', 'پرسنل', 'سهم برند ایرانی (٪)', 'سهم برند خارجی (٪)', 'نفوذ ایکامرس (٪)', 'برندهای برتر', 'دستاوردها', 'پیوتها و شکستها', 'رگولاتوری'])
|
|
for y in years:
|
|
writer.writerow([
|
|
y.get('year_shamsi'),
|
|
y.get('year_gregorian'),
|
|
y.get('phase'),
|
|
y.get('sku_count'),
|
|
y.get('active_sellers'),
|
|
y.get('daily_orders'),
|
|
y.get('workforce'),
|
|
y.get('domestic_brand_share'),
|
|
y.get('foreign_brand_share'),
|
|
y.get('ecom_penetration_iran'),
|
|
' | '.join(y.get('top_brands', [])),
|
|
' | '.join(y.get('milestones', [])),
|
|
' | '.join(y.get('pivots_and_failures', [])),
|
|
' | '.join(y.get('regulatory_and_macro', []))
|
|
])
|
|
|
|
# 5. executives_and_interviews.csv
|
|
execs = master.get('executives_directory', [])
|
|
with open('/workspace/ecommerce_research_sources/executives_and_interviews.csv', 'w', encoding='utf-8-sig', newline='') as f:
|
|
writer = csv.writer(f)
|
|
writer.writerow(['نام مدیر', 'سمت و جایگاه سازمانی', 'دسته سازمانی', 'دوره فعالیت', 'موضع و دیدگاه کلیدی پیرامون برندها', 'مصاحبهها و لینکها'])
|
|
for e in execs:
|
|
invs_str = ' || '.join([f"{inv['title']} ({inv['platform']} {inv['year']}): {inv['url']}" for inv in e.get('key_interviews', [])])
|
|
writer.writerow([
|
|
e.get('name'),
|
|
e.get('title'),
|
|
e.get('role_category'),
|
|
e.get('tenure'),
|
|
e.get('key_stance'),
|
|
invs_str
|
|
])
|
|
|
|
# 6. industry_market_channels.csv
|
|
markets = master.get('market_channel_breakdown', [])
|
|
if markets:
|
|
keys = list(markets[0].keys())
|
|
with open('/workspace/ecommerce_research_sources/industry_market_channels.csv', 'w', encoding='utf-8-sig', newline='') as f:
|
|
writer = csv.DictWriter(f, fieldnames=keys, extrasaction='ignore')
|
|
writer.writeheader()
|
|
for row in markets:
|
|
writer.writerow(row)
|
|
|
|
# 7. failures_and_pivots.csv
|
|
failures = master.get('failures_and_pivots_dossier', [])
|
|
if failures:
|
|
keys = list(failures[0].keys())
|
|
with open('/workspace/ecommerce_research_sources/failures_and_pivots.csv', 'w', encoding='utf-8-sig', newline='') as f:
|
|
writer = csv.DictWriter(f, fieldnames=keys, extrasaction='ignore')
|
|
writer.writeheader()
|
|
for row in failures:
|
|
writer.writerow(row)
|
|
|
|
# 8. Update DB export to CSV
|
|
conn = sqlite3.connect(DB_PATH)
|
|
c = conn.cursor()
|
|
c.execute('SELECT * FROM sources')
|
|
rows = c.fetchall()
|
|
cols = [desc[0] for desc in c.description]
|
|
conn.close()
|
|
|
|
with open('/workspace/ecommerce_research_sources/ecommerce_brands_research.csv', 'w', encoding='utf-8-sig', newline='') as f:
|
|
writer = csv.writer(f)
|
|
writer.writerow(cols)
|
|
writer.writerows(rows)
|
|
|
|
print("All CSV exports generated successfully with full headers.")
|