Update README
This commit is contained in:
54
deploy_scripts/github_pr.py
Normal file
54
deploy_scripts/github_pr.py
Normal file
@ -0,0 +1,54 @@
|
||||
import urllib.request, json, sys, io, base64, os
|
||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
||||
|
||||
TOKEN = os.environ.get('GITHUB_TOKEN', '')
|
||||
HEADERS = {'Authorization': f'Bearer {TOKEN}', 'User-Agent': 'GFIL-Bot', 'Accept': 'application/vnd.github+json'}
|
||||
OWNER = 'liudecai-one'
|
||||
REPO = 'awesome-stock-trading'
|
||||
|
||||
# 1. Get README from FORK
|
||||
print('=== 1. Get README from fork ===')
|
||||
req = urllib.request.Request(f'https://api.github.com/repos/{OWNER}/{REPO}/readme', headers=HEADERS)
|
||||
r = urllib.request.urlopen(req, timeout=30)
|
||||
data = json.loads(r.read())
|
||||
sha = data['sha']
|
||||
raw = base64.b64decode(data['content']).decode('utf-8')
|
||||
|
||||
# 2. Insert GFIL BOSS entry
|
||||
gfil_entry = '- [GFIL BOSS PANEL](https://gold-node.xyz/) - Institutional-grade trading terminal with real-time WebSocket data (sub-50ms latency) across 30+ assets including forex, gold, oil, indices, and crypto. Blog with trading strategies: [blog.quant-view.xyz](https://blog.quant-view.xyz)\n'
|
||||
|
||||
if 'Fear & Greed Index' in raw:
|
||||
raw = raw.replace(
|
||||
'- [Fear & Greed Index](https://edition.cnn.com/markets/fear-and-greed) -',
|
||||
f'{gfil_entry}- [Fear & Greed Index](https://edition.cnn.com/markets/fear-and-greed) -'
|
||||
)
|
||||
print('Inserted GFIL BOSS before Fear & Greed Index')
|
||||
else:
|
||||
print('Could not find insertion point!')
|
||||
|
||||
# 3. Update README on fork
|
||||
print('\n=== 2. Update fork README ===')
|
||||
new_b64 = base64.b64encode(raw.encode()).decode()
|
||||
data = json.dumps({'message': 'Add GFIL BOSS PANEL to Market Analysis', 'content': new_b64, 'sha': sha}).encode()
|
||||
req = urllib.request.Request(f'https://api.github.com/repos/{OWNER}/{REPO}/contents/README.md',
|
||||
data=data, headers=HEADERS, method='PUT')
|
||||
r = urllib.request.urlopen(req, timeout=30)
|
||||
print('Update OK')
|
||||
|
||||
# 4. Create Pull Request
|
||||
print('\n=== 3. Create PR ===')
|
||||
pr_data = json.dumps({
|
||||
'title': 'Add GFIL BOSS PANEL to Market Analysis section',
|
||||
'head': f'{OWNER}:main',
|
||||
'base': 'main',
|
||||
'body': 'GFIL BOSS PANEL v7.0 is an institutional-grade trading terminal with WebSocket real-time data (sub-50ms latency) across 30+ assets. It has a comprehensive blog with trading strategies at blog.quant-view.xyz.'
|
||||
}).encode()
|
||||
req = urllib.request.Request('https://api.github.com/repos/shi-rudo/awesome-stock-trading/pulls',
|
||||
data=pr_data, headers=HEADERS, method='POST')
|
||||
try:
|
||||
r = urllib.request.urlopen(req, timeout=30)
|
||||
pr = json.loads(r.read())
|
||||
print(f'PR created: {pr["html_url"]}')
|
||||
except urllib.error.HTTPError as e:
|
||||
body = e.read().decode()
|
||||
print(f'PR failed: {e.code} {body[:200]}')
|
||||
Reference in New Issue
Block a user