Code Monkey home page Code Monkey logo

mysql-to-googlesheets-automation's Introduction

MySQL to Google Sheets Python Script

This script automates the process of fetching data from a MySQL database and dropping it into a Google Sheets document. The script makes use of pandas to convert the fetched data into a pandas DataFrame, allowing for further data manipulation if required.

Requirements

The script requires the following Python libraries:

  • pandas
  • mysql-connector-python
  • gspread
  • oauth2client

Install these dependencies with pip: pip install pandas mysql-connector-python gspread oauth2client

Google Sheets API Setup

Before using the script, you need to set up the Google Sheets API:

  • Go to the Google Cloud Console.
  • Create a new project.
  • Search for "Google Sheets API" in the library and enable it for your project.
  • Create credentials for the Sheets API. When asked which API are you using, choose "Google Sheets API". When asked where will you be calling the API from, choose "Web server (e.g. node.js, Tomcat)". When asked what data will you be accessing, choose "Application data".
  • Now create a Service Account. Download the JSON file and place it in the same folder as your script.
  • Share your Google Sheet with the client email in the downloaded JSON file. More info on this here.
  • This JSON file contains the private key and other details required for authorization. You should refer to this file in the ServiceAccountCredentials.from_json_keyfile_name() function in the script.

Usage

  1. The script is started by running the main() function.
  2. Modify the MySQL host, database, user, and password in the connect_to_mysql() function, and the Google Sheets URL in the drop_data_to_google_sheets() function.
  3. Provide your query as the query string in the main() function.

Warning

Ensure that sensitive data such as your MySQL and Google Sheets credentials are secured and not exposed in your script. Use environment variables or external configuration files to keep these details safe.

Contributions

Contributions, issues, and feature requests are welcome. Feel free to check issues page if you want to contribute.

mysql-to-googlesheets-automation's People

Contributors

dtavizondykstra avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.