The cache module manages persistent storage for YouTube/Twitter accounts and affiliate marketing products in the .mp folder.
Cache Path Functions
get_cache_path
Gets the path to the main cache folder.
def get_cache_path() -> str
Returns
str - Path to the .mp cache folder
Example
from cache import get_cache_path
print(get_cache_path()) # /path/to/project/.mp
get_afm_cache_path
Gets the path to the Affiliate Marketing cache file.
def get_afm_cache_path() -> str
Returns
str - Path to .mp/afm.json
Gets the path to the Twitter accounts cache file.
def get_twitter_cache_path() -> str
Returns
str - Path to .mp/twitter.json
get_youtube_cache_path
Gets the path to the YouTube accounts cache file.
def get_youtube_cache_path() -> str
Returns
str - Path to .mp/youtube.json
get_provider_cache_path
Gets the cache path for a supported account provider.
def get_provider_cache_path(provider: str) -> str
Parameters
Provider name - must be "twitter" or "youtube"
Returns
str - Provider-specific cache file path
Raises
ValueError - If provider is not “twitter” or “youtube”
Example
from cache import get_provider_cache_path
path = get_provider_cache_path("youtube")
print(path) # /path/to/project/.mp/youtube.json
get_results_cache_path
Gets the path to the scraper results cache file.
def get_results_cache_path() -> str
Returns
str - Path to .mp/scraper_results.csv
Account Management
get_accounts
Retrieve all accounts for a specific provider from cache.
def get_accounts(provider: str) -> List[dict]
Parameters
Provider name - "twitter" or "youtube"
Returns
List[dict] - List of account dictionaries. Returns empty list if cache file doesn’t exist or has no accounts.
Example
from cache import get_accounts
# Get all YouTube accounts
youtube_accounts = get_accounts("youtube")
for account in youtube_accounts:
print(f"{account['nickname']}: {account['niche']}")
# Get all Twitter accounts
twitter_accounts = get_accounts("twitter")
for account in twitter_accounts:
print(f"{account['nickname']}: {account['topic']}")
YouTube Account Structure
{
"id": "uuid-string",
"nickname": "My Channel",
"firefox_profile": "/path/to/profile",
"niche": "Tech Reviews",
"language": "en",
"videos": []
}
Twitter Account Structure
{
"id": "uuid-string",
"nickname": "My Twitter",
"firefox_profile": "/path/to/profile",
"topic": "AI & Technology",
"posts": []
}
add_account
Add a new account to the cache.
def add_account(provider: str, account: dict) -> None
Parameters
Provider name - "twitter" or "youtube"
Account data dictionary with required fields for the provider
Returns
None - Appends account to cache file
Example
from cache import add_account
from uuid import uuid4
# Add YouTube account
youtube_account = {
"id": str(uuid4()),
"nickname": "Tech Channel",
"firefox_profile": "/home/user/.mozilla/firefox/profile",
"niche": "Technology",
"language": "en",
"videos": []
}
add_account("youtube", youtube_account)
# Add Twitter account
twitter_account = {
"id": str(uuid4()),
"nickname": "AI Bot",
"firefox_profile": "/home/user/.mozilla/firefox/profile2",
"topic": "Artificial Intelligence",
"posts": []
}
add_account("twitter", twitter_account)
remove_account
Remove an account from the cache by ID.
def remove_account(provider: str, account_id: str) -> None
Parameters
Provider name - "twitter" or "youtube"
UUID of the account to remove
Returns
None - Removes account from cache file
Example
from cache import remove_account, get_accounts
# Get accounts and remove the first one
accounts = get_accounts("youtube")
if accounts:
remove_account("youtube", accounts[0]["id"])
print(f"Removed account: {accounts[0]['nickname']}")
Product Management (Affiliate Marketing)
get_products
Retrieves all affiliate products from the cache.
def get_products() -> List[dict]
Returns
List[dict] - List of product dictionaries. Creates cache file if it doesn’t exist.
Example
from cache import get_products
products = get_products()
for product in products:
print(f"Product: {product['affiliate_link']}")
print(f"Twitter Account: {product['twitter_uuid']}")
Product Structure
{
"id": "uuid-string",
"affiliate_link": "https://example.com/affiliate/12345",
"twitter_uuid": "twitter-account-uuid"
}
add_product
Adds an affiliate product to the cache.
def add_product(product: dict) -> None
Parameters
Product data dictionary containing id, affiliate_link, and twitter_uuid
Returns
None - Appends product to cache file
Example
from cache import add_product, get_accounts
from uuid import uuid4
# Get a Twitter account to link to the product
twitter_accounts = get_accounts("twitter")
if twitter_accounts:
product = {
"id": str(uuid4()),
"affiliate_link": "https://amazon.com/affiliate/xyz",
"twitter_uuid": twitter_accounts[0]["id"]
}
add_product(product)
print("Product added successfully")
Usage in Main Application
The cache module is heavily used throughout main.py for managing accounts:
from cache import get_accounts, add_account, remove_account
from uuid import uuid4
# Check for existing YouTube accounts
cached_accounts = get_accounts("youtube")
if len(cached_accounts) == 0:
# Create new account
account_data = {
"id": str(uuid4()),
"nickname": "My Channel",
"firefox_profile": "/path/to/firefox",
"niche": "Gaming",
"language": "en",
"videos": []
}
add_account("youtube", account_data)
else:
# Display existing accounts
for account in cached_accounts:
print(f"{account['nickname']} - {account['niche']}")