Skip to content
This repository has been archived by the owner on Jul 4, 2018. It is now read-only.
/ rjokes Public archive

Telegram bot to send the best jokes from r/Jokes

Notifications You must be signed in to change notification settings

thecsw/rjokes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rjokes

Telegram bot that queries subreddit r/Jokes from Reddit (reddit.com/r/Jokes) for the best jokes of the day (can be modified) and then sends these jokes via telegram chat with a user.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

What things you need to install the software and how to install them

sudo pip install telepot
sudo pip install praw

OR

You can install them by using requirements file

pip install -r requirements.txt

telepot is a python framework for Telegram Bot API. This package will be used to connect to Telegram API and to communicate with users over the internet.

praw is Python Reddit API Wrapper. This will be the main and only package to connect to Reddit's API and extract desired data.

Installing

Nothing too complicated. The source code is written in python, so no worries.

The only thing that needs to be done before execution is the config profile. In the config profile you should fill your Reddit API details and Telegram Bot's unique API key.

For that please follow these steps

git clone https://github.com/thecsw/rjokes
cd rjokes
mv example.config.py config.py
nano config.py

Now here, you can use any text editor you like. When opening the file you will see this

#This is for reddit
client_id = 'take it from your account\'s preferences'
client_secret = 'take it from your account\'s preferences'
username = 'username'
password = 'password'
user_agent = 'something'
#This is for telegram
token = 'YOUR TELEGRAM API KEY'

So what will you need to do now is to get your Reddit API details from here and your Telegram API token from BotFather

After filling out the keys, save and exit.

Deployment

Config file is ready and you are good to go!

Just run this

python rjokes.py

That is everything. The script now just runs and any user that is connected to your Telegram bot can request a joke via the /joke command.

Source code

I know that the script is little bit messy, I tried. Simple and small, but it works!

Now, I want to give little insight on the code. If you want to take posts from any other subreddit, in the main source file rjokes.py, change this variable's value to any subrreddit you like

sub = 'Jokes' # Means it will extract posts from reddit.com/r/Jokes

Also, this script takes only the best jokes of the last 24 hours and updates them every hour. If you want to change the source of jokes, change this line

hot_python = subreddit.top('day', limit=LIMIT)

LIMIT is the amount of posts to extract

Well and also the time interval is in seconds

time.sleep(3600)

Built With

  • telepot - python framework for Telegram Bot API.
  • praw - Python Reddit API Wrapper.

Authors

  • Sagindyk Urazayev - Initial work - thecsw

License

This project is licensed under the The GNU General Public License - see the LICENSE.md file for details

About

Telegram bot to send the best jokes from r/Jokes

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages