A file-based quote bot written in Python

Overview

Let's Write a Python Quote Bot!

This repository will get you started with building a quote bot in Python. It's meant to be used along with the Learning Lab intro to Python.

When complete, you'll be able to grab random quotes from the command line, like this:

$ python get-quote.py

Keep it logically awesome

$ python get-quote.py

Speak like a human

Start the Tutorial

You can find your next step in this repo's issues!

You might also like...
A Python Library to Make Quote Images
A Python Library to Make Quote Images

Quote2Image A Python Library to Make Quote Images How To Use? Download The Latest Package From Releases Extract The Zip File And Place Every File In I

An API which returns random AOT quote everytime it's invoked

An API which returns random AOT quote everytime it's invoked

Bagas Mirror&Leech Bot is a multipurpose Telegram Bot written in Python for mirroring files on the Internet to our beloved Google Drive. Based on python-aria-mirror-bot
Bagas Mirror&Leech Bot is a multipurpose Telegram Bot written in Python for mirroring files on the Internet to our beloved Google Drive. Based on python-aria-mirror-bot

- [ MAYBE UPDATE & ADD MORE MODULE ] Bagas Mirror&Leech Bot Bagas Mirror&Leech Bot is a multipurpose Telegram Bot written in Python for mirroring file

This bot is created by AJTimePyro and It accepts direct downloading url & then return file as telegram file.
This bot is created by AJTimePyro and It accepts direct downloading url & then return file as telegram file.

URL Uploader Bot This is the source code of URL Uploader Bot. And the developer of this bot is AJTimePyro, His Telegram Channel & Group. You can use t

Automate TikTok follower bot, like bot, share bot, view bot and more using selenium
Automate TikTok follower bot, like bot, share bot, view bot and more using selenium

Zefoy TikTok Automator Automate TikTok follower bot, like bot, share bot, view bot and more using selenium. Click here to report bugs. Usage Download

Slam Mirror Bot is a multipurpose Telegram Bot written in Python for mirroring files on the Internet to our beloved Google Drive.
Slam Mirror Bot is a multipurpose Telegram Bot written in Python for mirroring files on the Internet to our beloved Google Drive.

Slam Mirror Bot is a multipurpose Telegram Bot written in Python for mirroring files on the Internet to our beloved Google Drive.

Instagram-follower-bot - An Instagram follower bot written in Python

Instagram Follower Bot An Instagram follower bot written in Python. The bot follows the follower of which account you want. e.g. (You want to follow @

A group management bot written in python3 using the python-telegram-bot library.

Chika Fujiwara A modular telegram Python bot running on python3 with an sqlalchemy database. Originally a Marie fork, Chika was created for personal u

Botto - A discord bot written in python that uses the hikari and lightbulb modules to make this bot

❓ About Botto Hi! This is botto, a discord bot written in python that uses the h

Comments
  • Read from a file

    Read from a file

    Now we're ready to really build our quote bot. To test things out, we'll read all the quotes from a file and print the first one.

    First, you can remove our test quote, the print statement on line 2. You can either comment it out by adding a # at the start of the line, or remove it completely.

    Next, remove the other comments by deleting # from the start of the other four lines to get Python code like this:

      f = open("quotes.txt")
      quotes = f.readlines()
      f.close()
    
      print(quotes)
    

    Here we are opening the quotes.txt file, reading all the lines into a new variable called quotes, then closing the file (defined by the variable f). Finally, we print out the quotes.

    You can run this code and we'll get a dump of all the quotes in the quotes file. That's because Python stored them all in an array, which is a single variable that holds a list of values.

    Print the first element of an array

    Since we only want one quote, we need to edit our code to print only the first value in the quotes array.

    In your code, find the print line and add this special modifier [0] so that the line now reads: print(quotes[0])

    The square brackets tell Python that we want a specific item in the array. Since it starts counting at zero, we've grabbed the first item.

    Comment with the first quote

    Run your code and copy the value to your clipboard.

    Paste the quote as a comment here and I'll follow up with next steps!

    opened by github-learning-lab[bot] 5
  • Run your first Python program

    Run your first Python program

    Now you're ready to start coding. Let's get familiar with the files in our repo:

    • README.md: a markdown introduction to this project
    • get-quote.py: the file where we'll write our Python code
    • quotes.txt: a text file with a list of quotes

    Open up get-quote.py and comment out line 2 by removing the # from the beginning of the line. It will look like this:

      print("Keep it logically awesome.")
    

    The two spaces (or one tab) in front of the line is important. Python uses whitespace to organize code. This print line is part of the main() function. But more on that in the next step. First, let's try running that Python script.

    Use the Python 3 command to run the script. From the command line, type one of the following:

    • python get-quote.py
    • python3 get-quote.py

    You should see our first quote, the one hard-coded into line 2, printed out in your terminal: Keep it logically awesome.

    Push your changes

    You've edited your local code, so you have a more recent version than is stored in this repository. You can check that any time by running: git status

    It should show one file modified. Every time we want to send our local changes to GitHub, we need to perform three steps:

    1. Add the file(s) with changes: git add get-quote.py
    2. Commit the changes: git commit -m "Hello World"
    3. Push the changes: git push

    Once you've completed these steps, we'll write some more Python.

    opened by github-learning-lab[bot] 2
  • Prepare your environment

    Prepare your environment

    Before we can start writing Python, we need to make sure you have your environment set up. You just need a few things (some of which you might already have!)

    • [x] Check that Python is installed
    • [x] Check that Git is installed
    • [x] Clone this repository on your local machine

    Check that Python is installed

    Your machine may already have Python, or you might need to install it. We also want to check that the right version of Python is present. To find out, go to your command line terminal and type: python -V

    Make sure to use a capital -V or you'll get something very different. If you get an error or have a version less than 3, try this: python3 -V (again with the capital -V).

    If you see your Python version displayed, you’re all set. Otherwise, you’ll need to download Python for your operating system. Make sure it's Python 3, as previous versions are deprecated.

    Check that Git is installed

    We’ll use a similar approach to find out if you already have git installed. From your comment line, type: git --version

    If you see your Git version displayed, you’re good to go. Otherwise, you’ll need to download Git for your operating system.

    Clone this repository on your local machine

    Now we’re getting to the fun stuff. Let’s clone this repository to your local machine so that we can make some edits: git clone https://github.com/florentdemelezi/python-random-quote.git

    You can also download or clone the repo via SSH from the main repo page.

    Close this issue to continue

    With your environment ready, let’s get started.

    Close this issue and I’ll comment with your next steps!

    opened by github-learning-lab[bot] 2
  • Explore Python on your own

    Explore Python on your own

    Though you've completed this course, there's plenty more to learn. You can even use this program as a place to start.

    Here are some ideas for next steps:

    • [ ] #5
    • [ ] Print out more than one quote at a time
    • [ ] Remove that extra line (called a newline) when printing
    • [ ] Learn about file writing and add quotes programmatically

    Give one or more of those a shot, then when you're really ready to move on, close this issue.

    opened by github-learning-lab[bot] 1
A file-based quote bot written in Python

Let's Write a Python Quote Bot! This repository will get you started with building a quote bot in Python. It's meant to be used along with the Learnin

null 1 Oct 28, 2021
A file-based quote bot written in Python

Let's Write a Python Quote Bot! This repository will get you started with building a quote bot in Python. It's meant to be used along with the Learnin

null 1 Nov 1, 2021
A file-based quote bot written in Python

Let's Write a Python Quote Bot! This repository will get you started with building a quote bot in Python. It's meant to be used along with the Learnin

null 1 Dec 7, 2021
A file-based quote bot written in Python

Let's Write a Python Quote Bot! This repository will get you started with building a quote bot in Python. It's meant to be used along with the Learnin

Florent 1 Dec 17, 2021
A file-based quote bot written in Python

Let's Write a Python Quote Bot! This repository will get you started with building a quote bot in Python. It's meant to be used along with the Learnin

Jyoti prakash Rout 1 Jan 8, 2022
A file-based quote bot written in Python

Let's Write a Python Quote Bot! This repository will get you started with building a quote bot in Python. It's meant to be used along with the Learnin

null 1 Jan 15, 2022
A file-based quote bot written in Python

Let's Write a Python Quote Bot! This repository will get you started with building a quote bot in Python. It's meant to be used along with the Learnin

null 1 Jan 19, 2022
A file-based quote bot written in Python

Let's Write a Python Quote Bot! This repository will get you started with building a quote bot in Python. It's meant to be used along with the Learnin

null 1 Feb 3, 2022
A file-based quote bot written in Python

Let's Write a Python Quote Bot! This repository will get you started with building a quote bot in Python. It's meant to be used along with the Learnin

A . S . M . RADWAN 2 Apr 3, 2022
A file-based quote bot written in Python

Let's Write a Python Quote Bot! This repository will get you started with building a quote bot in Python. It's meant to be used along with the Learnin

null 1 Feb 23, 2022