Code style guidelines and development standards for building Twitter cryptocurrency bots with Python, including naming conventions, imports, type annotations, error handling, and environment setup.
A comprehensive style guide for developing Twitter cryptocurrency bots in Python, covering naming conventions, code organization, error handling, and environment management.
Follow these coding standards when developing Twitter crypto bots:
```python
def calculate_returns():
daily_price = 1000
crypto_symbol = "BTC"
class CryptoTracker:
pass
class TwitterBot:
pass
```
Organize imports in three sections with blank lines between each:
1. Standard library imports
2. Third-party library imports
3. Local/project imports
```python
import os
from datetime import datetime, timedelta
import pandas as pd
import tweepy
import requests
from config.api_keys import TwitterCredentials
from config.constants import Emojis
```
Use type annotations for all function parameters and return values:
```python
def format_price(price: float) -> str:
return f"{int(price):,}"
def get_historical_data() -> pd.DataFrame:
# Implementation
pass
def send_tweet(message: str, api_client: tweepy.API) -> bool:
# Implementation
pass
```
Write descriptive docstrings for all classes and functions:
```python
def function_name(param1: type, param2: type) -> return_type:
"""Short description of what the function does.
Args:
param1: Description of param1
param2: Description of param2
Returns:
Description of return value
Raises:
ExceptionType: When and why this exception is raised
"""
```
Use loguru for comprehensive logging:
```python
from loguru import logger
logger.debug("Detailed information for debugging")
logger.info("Bot started successfully")
logger.warning("API rate limit approaching")
logger.error("Failed to fetch crypto data")
logger.critical("Bot cannot continue - missing API credentials")
```
```python
try:
# Bot operations
crypto_data = fetch_crypto_prices()
tweet_content = format_tweet(crypto_data)
send_tweet(tweet_content)
logger.info("Tweet sent successfully")
except requests.RequestException as e:
logger.error(f"API request failed: {e}")
except tweepy.TweepError as e:
logger.error(f"Twitter API error: {e}")
except Exception as e:
logger.critical(f"Unexpected error: {e}")
```
```bash
conda create -n bitcoin_twitter python=3.9
conda activate bitcoin_twitter
pip install -r requirements.txt
```
Common packages for crypto Twitter bots:
```python
tweepy>=4.0.0
pandas>=1.3.0
requests>=2.25.0
loguru>=0.5.0
python-dotenv>=0.19.0
schedule>=1.1.0
```
Organize your crypto bot project:
```
twitter_crypto_bot/
├── main.py # Bot entry point
├── config/
│ ├── api_keys.py # API credentials
│ └── constants.py # Bot constants
├── src/
│ ├── crypto_data.py # Crypto data fetching
│ ├── tweet_formatter.py
│ └── bot_logic.py
├── tests/
├── requirements.txt
└── .env
```
```bash
python main.py
python main.py --debug
python main.py --test
```
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/python-twitter-crypto-bot-development-guidelines/raw