This project provides a Python script that displays your Google AdSense earnings on the GNOME taskbar in Ubuntu, using the Argos extension. It allows you to monitor your AdSense earnings in real-time without needing to log into your AdSense account.
- Features
- Prerequisites
- Installation
- Usage
- Customization
- Troubleshooting
- Security Considerations
- Acknowledgments
- License
- Real-Time Earnings Display: Shows your current day's Google AdSense earnings directly on the GNOME taskbar.
- Automatic Updates: The script refreshes at a specified interval, ensuring your earnings are up-to-date.
- Secure Authentication: Uses OAuth 2.0 for secure access to your AdSense data.
- Customizable: Easily adjust the update frequency and display icons to suit your preferences.
- Ubuntu (or other Linux distribution) with the GNOME desktop environment.
- Python 3 installed.
- A Google AdSense account with API access.
- Argos GNOME Shell extension.
- Basic knowledge of using the terminal.
- Go to the Google Cloud Console.
- Click on Select a project > New Project.
- Enter a project name (e.g.,
AdSenseTaskbarDisplay) and click Create.
- In the Cloud Console, navigate to APIs & Services > Library.
- Search for AdSense Management API.
- Click on it and then click Enable.
- Go to APIs & Services > Credentials.
- Click Create Credentials > OAuth client ID.
- Select Desktop app as the application type.
- Enter a name (e.g.,
AdSenseTaskbarApp) and click Create. - Click Download JSON to get your
client_secret.jsonfile. - Save this file in a secure location (e.g.,
/home/yourusername/client_secret.json).
Note: If Google asks your for a consent app, create it first.
Open a terminal and run:
sudo pip3 install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib- Visit the Argos extension page on the GNOME Extensions website.
- Toggle the switch to ON to install it.
If you cannot install extensions from the browser, install the GNOME Shell integration package:
sudo apt install chrome-gnome-shellEventually follow official github install instructions to install Argos properly.
mkdir -p ~/.config/argosCreate a new file named adsense.1h.py in ~/.config/argos/:
nano ~/.config/argos/adsense.1h.pyPaste the following code into the file:
#!/usr/bin/env python3
import os
import datetime
import sys
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
import pickle
# Paths to your credentials
CLIENT_SECRETS_FILE = '/home/yourusername/client_secret.json' # Update with your actual path
TOKEN_PICKLE = '/home/yourusername/token.pickle' # Update with your actual path
# AdSense API scope
SCOPES = ['https://www.googleapis.com/auth/adsense.readonly']
def get_service():
creds = None
# Load credentials from the pickle file if it exists
if os.path.exists(TOKEN_PICKLE):
with open(TOKEN_PICKLE, 'rb') as token:
creds = pickle.load(token)
# If no valid credentials, let the user log in
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
CLIENT_SECRETS_FILE, SCOPES)
creds = flow.run_local_server(port=0)
# Save the credentials for next time
with open(TOKEN_PICKLE, 'wb') as token:
pickle.dump(creds, token)
service = build('adsense', 'v2', credentials=creds)
return service
def main():
try:
service = get_service()
# Get the AdSense account ID
accounts = service.accounts().list().execute()
account_id = accounts['accounts'][0]['name']
# Generate the report for today's earnings
report = service.accounts().reports().generate(
account=account_id,
dateRange='TODAY',
metrics=['ESTIMATED_EARNINGS']
).execute()
# Extract earnings from the report
earnings = report['totals']['cells'][0]['value']
currency_code = report['headers'][0]['currencyCode']
print(f"💰 AdSense Today: {earnings} {currency_code}")
except Exception as e:
# Handle exceptions and display errors in Argos dropdown
print("AdSense Earnings")
print("---")
print("Error fetching earnings:")
print(str(e))
if __name__ == '__main__':
main()Important:
- Replace
/home/yourusername/client_secret.jsonand/home/yourusername/token.picklewith the actual paths to yourclient_secret.jsonand desired location fortoken.pickle. - Ensure that the shebang line (
#!/usr/bin/env python3) points to the correct Python interpreter.
chmod +x ~/.config/argos/adsense.1h.pyThe first time you run the script, it needs to authenticate with your Google account.
~/.config/argos/adsense.1h.py- A browser window will open prompting you to log in to your Google account and grant permissions.
- After authentication, the script will save the credentials to
token.pickle.
- The script will display your AdSense earnings on the GNOME taskbar.
- Argos will automatically execute the script every hour, as indicated by
.1hin the script name. - To refresh the display manually, you can click on the Argos icon and select Refresh or reload GNOME Shell.
- Update Frequency: Change
.1hin the script name to.30mfor every 30 minutes,.5mfor every 5 minutes, etc.- For example, to refresh every 30 minutes, rename the script to
adsense.30m.py.
- For example, to refresh every 30 minutes, rename the script to
- Icon Customization: Edit the
printstatement in the script to change the icon or text.- Replace
💰with any other icon or text you prefer.
- Replace
- Script Not Displayed on Taskbar:
- Ensure the script is executable and located in
~/.config/argos/. - Verify that Argos extension is installed and enabled.
- Reload GNOME Shell by pressing
Alt + F2, typingr, and pressingEnter.
- Ensure the script is executable and located in
- Authentication Issues:
- Delete
token.pickleand rerun the script to re-authenticate.rm /home/yourusername/token.pickle ~/.config/argos/adsense.1h.py
- Delete
- API Errors:
- Ensure the AdSense Management API is enabled in your Google Cloud project.
- Verify that your AdSense account is active and has the necessary permissions.
- Script Displays Filename Instead of Earnings:
- Ensure the script outputs the earnings on the first line.
- Check that all file paths in the script are absolute and correct.
- Make sure all required Python libraries are installed system-wide.
- Python Dependencies Not Found:
- If the script works when run manually but not with Argos, ensure that the Python libraries are installed in the system's Python environment.
sudo pip3 install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib
- If the script works when run manually but not with Argos, ensure that the Python libraries are installed in the system's Python environment.
- Shebang Line Issues:
- Ensure the shebang line at the top of the script points to the correct Python interpreter.
- Use
#!/usr/bin/env python3for the system's default Python 3. - If using a virtual environment, provide the absolute path to the Python interpreter.
- Use
- Ensure the shebang line at the top of the script points to the correct Python interpreter.
- Protect Your Credentials:
- Keep
client_secret.jsonandtoken.picklein a secure location. - Ensure file permissions prevent unauthorized access.
- Keep
- Do Not Share Sensitive Information:
- Avoid committing
client_secret.jsonortoken.pickleto version control systems like GitHub. - Use placeholders or examples when sharing paths and account IDs.
- Avoid committing
- Argos Extension: Argos by Pablo Bortolameotti.
- Google APIs Client Library for Python: google-api-python-client.
- Google AdSense Management API: AdSense Management API v2.
This project is licensed under the MIT License - see the LICENSE file for details.
Notes:
- Using
picklefor Credentials:- The script uses
pickleto store OAuth 2.0 credentials. - Ensure that the
token.picklefile is stored securely.
- The script uses
- Python Interpreter Path:
- If you're using a specific Python environment (e.g., Anaconda), ensure the shebang line points to the correct interpreter.
- For example:
#!/home/yourusername/miniconda3/bin/python3
- For example:
- Adjust the shebang line accordingly if you encounter issues.
- If you're using a specific Python environment (e.g., Anaconda), ensure the shebang line points to the correct interpreter.
Example of Adjusted Shebang Line:
#!/home/yourusername/miniconda3/bin/python3- Replace
/home/yourusername/miniconda3/bin/python3with the path to your Python interpreter.
