Skip to content
This repository has been archived by the owner on Nov 19, 2022. It is now read-only.

Core Changes

Cameron Rodriguez edited this page Jun 20, 2019 · 9 revisions

This page is maintained for legacy support, and only applies for programs on version 1.x.x. For the latest instructions, return to the homepage.


This page will give you the main changes required to run the bot.

Preparing your Dev Area

The following instructions are intended for development on Windows.

You will need to install Python, Git, and Pipenv to modify your bot. You will also need access to your account's environmental variables and the command line.

Steps:

  • Setup Git.
  • Create a folder suitable for development, open the command line and clone the source code with git clone https://github.com/cam-rod/XKCDAltTextBot.git.
  • Install the dependencies by running pipenv install.

You should read the Git Pro book, it's an excellent guide for getting started with Git.

Getting ready on Twitter

You will need to prepare a Twitter account for this bot by becoming a developer. Once your create your account, go to <dev.twitter.com> and apply for a developer account by following the instructions. You do not need to fill in the following: Callback URLs, Terms of Service URL, Privacy Policy URL. Take note of the handle of your Twitter account, and the name of the developer app; you will need these later. Also take note of the account you would like to target.

Once your account is setup, navigate to the Apps page and open Details. Under the Permissions tab, click Edit and change Access permission to Read and write and save. Finally, switch to the Keys and Tokens tab, and Regenerate/Generate your Consumer API keys and Access token & access token secret.

Saving your keys and tokens

It's not recommended to save your API keys and access tokens directly into your file for security reasons, so you will keep them in your environmental variables. Using this guide, you will save your keys and tokens here as the Variable value. Remember the Variable name in this specific order: API_KEY, API_SECRET_KEY, ACCESS_TOKEN, ACCESS_SECRET_TOKEN. (This is tedious, but you'll see why next.)

Modifying the program

In order to make the program work for your account, you will need to make the following changes. The indicated lines are accurate as of version 1.9.0. The following is the format of how to make changes:

  • The element to change: CHANGE (how it will be displayed in code examples)
    • Line number: code CHANGE code code

These are the changes to be made:

  • Your Twitter account: MYHANDLE
    • Line 25: alt_payload = {'q': 'from:MYHANDLE', 'result_type': 'recent', 'count': '10'}
  • Your Twitter developer app: MYAPPNAME
    • Line 26: comic_payload = {'q': 'from:TARGETTWITTER', 'result_type': 'recent', 'count': '1'}
  • Environmental variable names: APIKEY, APISECRET, ACCESSTOKEN, ACCESSSECRET (in the order designated earlier)
    • Lines 147-150:
key = [os.environ.get('APIKEY', None),
       os.environ.get('APISECRETKEY', None),
       os.environ.get('ACCESSTOKEN', None),
       os.environ.get('ACCESSSECRET', None)]

These are the bare minimum changes required to get your bot to target another account. However, it likely won't work due to the layout of the other account's Tweets, or of the website it accesses. The steps to fix this will be in the next section.

← Building your Own Bot // Different Websites →