PyMotivator: Elevate Your Day with Python-Powered Motivational WhatsApp Quotes

PyMotivator: Elevate Your Day with Python-Powered Motivational WhatsApp Quotes

ยท

5 min read

Introduction

In the hustle and bustle of modern life, staying motivated can be a challenge. Whether you're tackling a new project, pursuing personal goals, or simply navigating the ups and downs of everyday life, a little dose of inspiration can go a long way. That's where PyMotivator comes in. This Python project is designed to seamlessly integrate with WhatsApp, delivering daily motivational quotes right to your fingertips. But PyMotivator is more than just a tool for inspiration โ€“ it's also a fantastic opportunity to dive into Python programming, from the basics to advanced concepts.

Purpose

The primary goal of PyMotivator is twofold: to provide users with a daily dose of motivation and to serve as a learning platform for Python enthusiasts. By engaging with PyMotivator, users not only receive uplifting messages but also gain valuable experience in Python development and its integration with third-party services like WhatsApp.

Intended Audience

PyMotivator is perfect for anyone interested in learning Python or those seeking a daily source of motivation. Whether you're a novice programmer eager to expand your skills or someone in need of a daily pick-me-up, PyMotivator welcomes users of all levels and backgrounds.

Overall Description

At its core, PyMotivator consists of two main modules: one responsible for fetching motivational quotes from an external API and another for scheduling the delivery of these quotes via WhatsApp. Leveraging Python libraries such as Requests, Twilio, and APScheduler, PyMotivator seamlessly integrates these functionalities to provide users with a smooth and enriching experience.

System Features and Requirements: Functional Requirements:

  • Python 3.12-dev / 3.8 (for Heroku Deployment)

  • Requests: For making HTTP requests to the Quotes of the Day API.

  • Twilio: For sending WhatsApp messages programmatically.

  • APScheduler: For scheduling daily motivational messages.

External Interface Requirements:

  • Quotes of the Day API: Provides a source for fetching motivational quotes.

  • Twilio Dashboard for WhatsApp: Allows integration with WhatsApp for message delivery.

  • Visual Studio Code: An integrated development environment for Python programming.

  • GitHub: A platform for version control and collaborative development.

  • Heroku: A cloud platform for deploying and scaling applications.

System Features:

  1. get_quote_of_the_day: Fetches a motivational quote based on the specified category.

  2. set_twilio_connection: Establishes a connection with the Twilio API using account credentials.

  3. send_whatsapp_text: Sends a motivational quote via WhatsApp using the Twilio client connection.

  4. background_cron_job: Executes the sending of WhatsApp messages as a daily background task.

Assumptions and Dependencies

  • PyMotivator relies on third-party services for sending and receiving quotes, assuming their availability.

  • Python version compatibility is addressed, with considerations for deployment on Heroku.

  • Environment variables are used for storing sensitive information like API keys and passwords.

Other Non-Functional Requirements

  • Security: Sensitive data is stored as environment variables for enhanced security.

  • Quality: Adherence to code quality standards and PEP 8 guidelines for maintainability.

  • Performance: Deployment on Heroku ensures scalability, while the latest Python version and updated libraries enhance performance.

Industry Practices

  • Clean, modularized code promotes readability and ease of maintenance.

  • Consistent use of snake case follows PEP 8 conventions.

  • Separate configuration files enhance organization and security.

  • Comprehensive documentation aids in understanding and contributing to the project.

  • DRY (Don't Repeat Yourself) principle minimizes redundancy and promotes code reuse.

Steps to Implement PyMotivator

  1. Setting Up Environment:

    • Install Python 3.12-dev or 3.8 depending on deployment requirements.

    • Set up Visual Studio Code for Python development.

    • Create a GitHub repository for version control and collaboration.

  2. Installing Dependencies:

    • Install the required Python libraries: Requests, Twilio, and APScheduler.
    bashCopy codepip install requests twilio apscheduler
  1. Configuring Twilio:

    • Sign up for a Twilio account and obtain account SID, auth token, and phone number.

    • Set up a WhatsApp Sandbox in the Twilio Dashboard.

        import os
      
        account_sid = os.environ.get('TWILIO_ACCOUNT_SID')
        auth_token = os.environ.get('TWILIO_ACCOUNT_TOKEN')
        phone_number = os.environ.get('PHONE')
      

      Save your account_sid ,account_token and Phone_number inside your os using these commnads

        export TWILIO_ACCOUNT_SID = #Your sid of twilio account
        export TWILIO_ACCOUNT_TOKEN = #add your token from twilio account 
        export PHONE = #your phone number
      
  2. Fetching Quotes:

    • Create a Python function to fetch motivational quotes from the Quotes of the Day API.
    pythonCopy code# Motivator.py
    import requests

    def get_quotes_by_category(category):
        api_url = 'https://api.api-ninjas.com/v1/quotes?category={}'.format(category)
        api_key = 'lF2zJXZ5za9Zrr6CF4TEsg==4okhYQ3zybsFCUY2'

        response = requests.get(api_url, headers={'X-Api-Key': api_key})

        if response.status_code == requests.codes.ok:
            data = response.json()
            status = response.status_code
            if status == 200:
                quotes = [quote['quote'] for quote in data]
                return quotes  # Return quotes here
            elif status == 400:
                quotes = [quote['error'] for error in data]
                return quotes  # Return quotes here
        else:
            print("Error:", response.status_code, response.text)
  1. Sending WhatsApp Messages:

    • Define functions to establish a Twilio connection and send WhatsApp messages with motivational quotes.
    pythonCopy code# twilio_conn.py
    from twilio.rest import Client
    from config import account_sid, auth_token, phone_number

    def set_twilio_connection(account_sid, auth_token):
        client = Client(account_sid, auth_token)
        return client

    def send_whatsapp_text(client, quotes):
        message = client.messages.create(
            from_='whatsapp:+14155238886',
            body=quotes,
            to='+917583904034' #replace this with your phone number
        )
        return message.sid

    client = set_twilio_connection(account_sid, auth_token)
  1. Scheduling Daily Messages:

    • Implement a background cron job using APScheduler to schedule the sending of WhatsApp messages daily.
    pythonCopy code# cron.py
    from apscheduler.schedulers.background import BackgroundScheduler
    from Motivator import send_whatsapp_text, client, quotes
    import time

    scheduler = BackgroundScheduler(timezone="Asia/Kolkata")
    scheduler.start()

    job = scheduler.add_job(send_whatsapp_text, 'cron', [client, quotes], hour="09", minute="07")
    print(job)

    while True:
        time.sleep(1)
  1. Testing and Optimization:

    • Test the PyMotivator application thoroughly to ensure proper functionality.

    • Optimize code for performance and adherence to industry standards.

By following these steps and utilizing the provided code snippets, users can seamlessly implement PyMotivator to receive daily motivational quotes on WhatsApp.

Here is the Git hub Repository ๐Ÿ‘‰ Click here

PyMotivator Results -

Conclusion

With PyMotivator, embarking on a journey of Python programming while receiving daily doses of motivation has never been easier. Whether you're a budding coder or a seasoned developer, PyMotivator offers a unique blend of learning and inspiration, empowering users to start each day on a positive note. So why wait? Dive into PyMotivator today and elevate your mornings with the power of Python and motivation at your fingertips.

This blog aims to provide a comprehensive overview of PyMotivator, detailing its features, requirements, benefits, and step-by-step implementation process. By following the outlined steps and guidelines, users can embark on their Python learning journey while enjoying a daily boost of motivation delivered straight to their WhatsApp inbox.

ย