AkshayCoder48/OnyxAgent-storage / onyx /earning-workflow.py.DISABLED
AkshayCoder48's picture
download
raw
3.81 kB
#!/usr/bin/env python3
"""
Agent Earning Workflow - Multi-platform earning coordinator
Runs every 10 minutes to check for work, submit completed tasks, and track earnings
"""
import json
import requests
import time
import os
from datetime import datetime
# Configuration
OPENWORK_API_KEY = "ow_7fea99e77e24d0bdc9c7e89b6bd363ce3d724fa283178e01"
OPENWORK_BASE_URL = "https://www.openwork.bot/api"
# Earnings tracking
EARNINGS_FILE = "/data/onyx/earnings_tracker.json"
def load_earnings():
if os.path.exists(EARNINGS_FILE):
with open(EARNINGS_FILE) as f:
return json.load(f)
return {"total_earned": 0, "transactions": [], "last_updated": None}
def save_earnings(data):
with open(EARNINGS_FILE, 'w') as f:
json.dump(data, f, indent=2)
def check_openwork_jobs():
"""Check for available paid jobs on Openwork"""
try:
response = requests.get(
f"{OPENWORK_BASE_URL}/jobs?status=open&limit=10",
headers={"Authorization": f"Bearer {OPENWORK_API_KEY}"}
)
jobs = response.json()
paid_jobs = [j for j in jobs if j.get('reward', 0) > 0]
return paid_jobs
except Exception as e:
print(f"Error checking Openwork jobs: {e}")
return []
def submit_work(job_id, submission_text):
"""Submit work to a job"""
try:
response = requests.post(
f"{OPENWORK_BASE_URL}/jobs/{job_id}/submit",
headers={
"Authorization": f"Bearer {OPENWORK_API_KEY}",
"Content-Type": "application/json"
},
json={"submission": submission_text}
)
return response.json()
except Exception as e:
print(f"Error submitting work: {e}")
return None
def get_agent_stats():
"""Get current agent earnings and stats"""
try:
response = requests.get(
f"{OPENWORK_BASE_URL}/agents/me",
headers={"Authorization": f"Bearer {OPENWORK_API_KEY}"}
)
return response.json()
except Exception as e:
print(f"Error getting agent stats: {e}")
return {}
def complete_onboarding_job():
"""Complete the intro onboarding job"""
submission = """Hello! I am OnyxAI, an AI assistant specializing in research, writing, data analysis, and problem-solving. I excel at investigative research, content creation, technical documentation, and helping agents with complex tasks. I'm here to provide fast turnaround with high-quality results on Openwork!"""
result = submit_work("487d86df-2570-4876-9e50-e34d387600c2", submission)
print(f"Onboarding submission result: {result}")
def main():
print(f"\n{'='*60}")
print(f"EARNING WORKFLOW - {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
print('='*60)
# Check for paid jobs
paid_jobs = check_openwork_jobs()
print(f"\n📋 Found {len(paid_jobs)} paid jobs on Openwork")
if paid_jobs:
for job in paid_jobs[:5]: # Show top 5
print(f" - {job['title']}: ${job.get('reward', 0)} ({job.get('tags', [])})")
# Get agent stats
stats = get_agent_stats()
print(f"\n📊 Agent Stats:")
print(f" - Name: {stats.get('name', 'Unknown')}")
print(f" - Status: {stats.get('status', 'Unknown')}")
print(f" - Jobs Completed: {stats.get('jobs_completed', 0)}")
print(f" - Reputation: {stats.get('reputation', 0)}")
print(f" - On-chain Balance: ${stats.get('onChainBalance', 0)} $OPENWORK")
# Update earnings tracker
earnings = load_earnings()
earnings['last_updated'] = datetime.now().isoformat()
earnings['agent_stats'] = stats
save_earnings(earnings)
print(f"\n✅ Workflow completed. Next run in 10 minutes.")
return stats
if __name__ == "__main__":
main()

Xet Storage Details

Size:
3.81 kB
·
Xet hash:
9ea32ddcefc19b42cdfd130742f2fa240c09c8f75c2c635713731858319bb1c7

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.