Random Joke to Google Spreadsheet

 import requests
import json
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
from abilities import acquire_user_oauth_tokens


def get_random_joke():
    response = requests.get("https://official-joke-api.appspot.com/random_joke")
    joke_data = json.loads(response.text)
    joke = f"{joke_data['setup']} - {joke_data['punchline']}"
    return joke


def create_new_spreadsheet(credentials):
    try:
        service = build("sheets", "v4", credentials=credentials)
        spreadsheet = {"properties": {"title": "Random Joke Spreadsheet"}}
        spreadsheet = service.spreadsheets().create(body=spreadsheet).execute()
        print(f"Created spreadsheet with ID: {spreadsheet.get('spreadsheetId')}")
        return spreadsheet.get("spreadsheetId"), spreadsheet.get("spreadsheetUrl")
    except HttpError as error:
        print(f"An error occurred: {error}")

About this template

This app fetches a random joke from an API, creates a new Google Spreadsheet, adds the joke to the new Google Spreadsheet, and responds back to the user with the URL to the new Google Spreadsheet using user's OAuth tokens for authentication.

Introduction to the Random Joke to Google Spreadsheet Template

Welcome to the step-by-step guide on how to use the Random Joke to Google Spreadsheet template. This template is designed to fetch a random joke from an online API and create a new Google Spreadsheet where the joke will be added. You will then receive a URL to access your new spreadsheet. This process is automated and requires minimal input from you, thanks to the Lazy platform.

To get started, simply click on "Start with this Template" on the Lazy platform. This will set up the template in your Lazy Builder interface.

External Integrations

Before you can use this template, you need to ensure that you have the following:

  • A Google account with access to Google Sheets.
  • Authorization tokens for OAuth 2.0 to authenticate with the Google Sheets API. These tokens will be acquired through the Lazy platform's built-in abilities module, so you don't need to worry about setting them up manually.

Once you have these prerequisites in place, you're ready to proceed with using the template.

Using the Test Button

After initializing the template with "Start with this Template," you can use the Test button to begin the deployment of the app. The Lazy CLI will launch, and you will be prompted to provide any required user input. In this case, the app will handle the OAuth tokens for you, so you won't need to input them manually.

When you use the Test button, if the code requires an API, Lazy will provide you with a dedicated server link to use the API. Since this template does not host a frontend or use FastAPI, you won't receive a docs link, and there's no need for additional integration steps.

How to Use the Interface

Once the app is deployed, you will interact with it through the Lazy CLI. The app will automatically fetch a random joke and proceed to create a new Google Spreadsheet. It will then add the joke to the spreadsheet and provide you with the URL to your new Google Spreadsheet.

If you encounter any issues or have questions, the Lazy customer support team is available to assist you. Enjoy your new app and the laughter that comes with your random jokes!

Remember, this template is designed to be easy to use, requiring minimal setup and no environment secrets or additional environment variables. Just follow the steps above, and you'll have your Random Joke to Google Spreadsheet app up and running in no time on the Lazy platform.

Category
Last published
July 26, 2024

More templates like this

SecureUserAuthenticator

Develop a secure User Authentication system for users to register, log in, and manage their profiles, laying the foundation for user-specific data management and permissions in the CMS.

Laravel
Python
Flask
Javascript

Simple Multiplayer Telegram game

This app is a simple frontend for a game where users can upvote and downvote the most popular word in their country, learn about the flags of other countries, and view what other people voted for on a leaderboard.

Telegram
Python
Javascript

MP3ify: Youtube to MP3 Converter

A web application that allows users to download YouTube videos from URLs and provides the option to convert them to MP3 format.

Python
Flask
Home
/
Random Joke to Google Spreadsheet