18 lines
906 B
Python
18 lines
906 B
Python
# -*- coding: utf-8 -*-
|
|
"""Laedt alle lokalen artikel/artikel-*.json per Contents-API nach Gitea (neu oder mit sha)."""
|
|
import base64, glob, json, os, sys
|
|
sys.path.insert(0, os.path.dirname(__file__))
|
|
exec(open(os.path.join(os.path.dirname(__file__), 'push_gitea.py'), encoding='utf-8').read().split('def sammle')[0])
|
|
|
|
for p in sorted(glob.glob('artikel/artikel-*.json')):
|
|
json.load(open(p, encoding='utf-8')) # nur gueltiges JSON hochladen
|
|
inhalt = base64.b64encode(open(p, 'rb').read()).decode()
|
|
code, d = ruf('GET', f"{REPO}/contents/{p}?ref=main")
|
|
daten = {'content': inhalt, 'message': f'Artikel {os.path.basename(p)}', 'branch': 'main'}
|
|
if code == 200:
|
|
daten['sha'] = d['sha']
|
|
code, d = ruf('PUT', f"{REPO}/contents/{p}", daten)
|
|
else:
|
|
code, d = ruf('POST', f"{REPO}/contents/{p}", daten)
|
|
print(code, p, '' if code in (200, 201) else str(d)[:200])
|