-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy_render_direct.py
More file actions
118 lines (102 loc) · 3.72 KB
/
Copy pathdeploy_render_direct.py
File metadata and controls
118 lines (102 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
"""
Deploy to Render.com via Direct API (No GitHub Required)
Uses Render Blueprint API
"""
import requests
import json
import base64
from pathlib import Path
API_KEY = 'rnd_NFW3mtRJty97THVedLHx3Rpr3mL6'
PROJECT_NAME = 'API_bot'
BASE_URL = 'https://api.render.com/v1'
HEADERS = {
'Authorization': f'Bearer {API_KEY}',
'Content-Type': 'application/json',
'Accept': 'application/json'
}
def check_auth():
"""Verify API key is valid"""
print('🔑 Verifying API key...')
response = requests.get(f'{BASE_URL}/owners', headers=HEADERS)
if response.status_code == 200:
data = response.json()
print(f'✓ Authenticated')
if data:
owner = data[0]
print(f" Owner: {owner.get('name', 'N/A')}")
print(f" Email: {owner.get('email', 'N/A')}")
return owner.get('id')
return None
else:
print(f'✗ Authentication failed: {response.status_code}')
print(f' {response.text}')
return None
def list_services():
"""List all existing services"""
print('\n📋 Listing services...')
response = requests.get(f'{BASE_URL}/services', headers=HEADERS)
if response.status_code == 200:
services = response.json()
if isinstance(services, list) and services:
print(f'✓ Found {len(services)} service(s):')
for svc in services:
if isinstance(svc, dict):
svc_data = svc.get('service', svc)
print(f" - {svc_data.get('name', 'Unnamed')} ({svc_data.get('type', 'unknown')})")
else:
print(' No services found')
return services
else:
print(f'✗ Error: {response.status_code}')
return []
def create_web_service_direct(owner_id):
"""Create web service directly (requires Docker or manual setup)"""
print(f'\n🚀 Creating service: {PROJECT_NAME}...')
# Note: Render doesn't support direct code upload via API
# Must use Git repository
print('⚠️ Render API Limitations:')
print(' - Cannot upload code directly via API')
print(' - Requires GitHub/GitLab repository')
print(' - Blueprint API only works with git repos')
print()
print('📝 Solution: Use GitHub Repository')
print()
print('Quick Setup (2 minutes):')
print('1. Initialize git:')
print(' git init')
print(' git add .')
print(' git commit -m "Deploy bot"')
print()
print('2. Create GitHub repo:')
print(' → https://github.com/new')
print(' → Name: telegram-bot')
print(' → Click "Create repository"')
print()
print('3. Push code:')
print(' git remote add origin https://github.com/YOUR_USERNAME/telegram-bot.git')
print(' git branch -M main')
print(' git push -u origin main')
print()
print('4. Deploy on Render Dashboard:')
print(' → https://dashboard.render.com/create?type=web')
print(f' → Connect your repo')
print(f' → Name: {PROJECT_NAME}')
print(' → Build: pip install -r requirements.txt')
print(' → Start: python bot.py')
print()
print('Alternative: Use PythonAnywhere (already deployed there!)')
def main():
print('🎨 Render.com Direct Deployment\n')
# Verify authentication
owner_id = check_auth()
if not owner_id:
print('\n✗ Could not authenticate. Check your API key.')
return
# List existing services
services = list_services()
# Try to create service
create_web_service_direct(owner_id)
print('\n💡 Recommended: Your bot is already running on PythonAnywhere!')
print(' If you want better uptime, GitHub + Render is the way.')
if __name__ == '__main__':
main()