-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathsubmit-to-viberank.sh
More file actions
executable file
Β·82 lines (66 loc) Β· 2.11 KB
/
Copy pathsubmit-to-viberank.sh
File metadata and controls
executable file
Β·82 lines (66 loc) Β· 2.11 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
#!/bin/bash
# Submit ccusage data to Viberank
# Usage: ./submit-to-viberank.sh
set -e
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
echo -e "${YELLOW}π Viberank Submission Tool${NC}"
echo ""
# Check if ccusage is available
if ! command -v npx &> /dev/null; then
echo -e "${RED}Error: npx is not installed. Please install Node.js first.${NC}"
exit 1
fi
# Get GitHub username from git config
GITHUB_USER=$(git config user.name 2>/dev/null || echo "")
if [ -z "$GITHUB_USER" ]; then
echo -e "${YELLOW}Warning: Could not get GitHub username from git config${NC}"
echo -n "Please enter your GitHub username: "
read GITHUB_USER
fi
echo -e "GitHub username: ${GREEN}$GITHUB_USER${NC}"
echo ""
# Generate ccusage data
echo -e "${YELLOW}Generating usage data...${NC}"
npx ccusage@latest daily --json > cc.json
if [ ! -f "cc.json" ]; then
echo -e "${RED}Error: Failed to generate cc.json${NC}"
exit 1
fi
# Display summary
echo -e "${GREEN}β Generated cc.json successfully${NC}"
echo ""
echo "Summary:"
jq -r '.totals | " Total Cost: $\(.totalCost | round)\n Total Tokens: \(.totalTokens)\n Days Tracked: \(.daily | length)"' cc.json 2>/dev/null || echo " (install jq for summary)"
echo ""
# Submit to Viberank
echo -e "${YELLOW}Submitting to Viberank...${NC}"
RESPONSE=$(curl -s -X POST https://www.viberank.app/api/submit \
-H "Content-Type: application/json" \
-H "X-GitHub-User: $GITHUB_USER" \
-d @cc.json)
# Check if submission was successful
if echo "$RESPONSE" | grep -q '"success":true'; then
PROFILE_URL=$(echo "$RESPONSE" | grep -o '"profileUrl":"[^"]*' | cut -d'"' -f4)
echo -e "${GREEN}β Successfully submitted to Viberank!${NC}"
echo ""
echo -e "View your profile at: ${GREEN}$PROFILE_URL${NC}"
else
echo -e "${RED}Error: Failed to submit to Viberank${NC}"
echo "Response: $RESPONSE"
exit 1
fi
# Cleanup
echo ""
echo -n "Remove cc.json file? (y/N): "
read -n 1 REMOVE
echo ""
if [[ $REMOVE =~ ^[Yy]$ ]]; then
rm cc.json
echo -e "${GREEN}β Cleaned up cc.json${NC}"
fi
echo ""
echo -e "${GREEN}Done!${NC}"