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

Forking and Contributing to XKCDAltTextBot

Cameron Rodriguez edited this page Apr 18, 2020 · 7 revisions

This is the section for modifying and adding to the source code of the project, for personal use and public improvement.

Forks

Feel free to fork this project and modify it for your own Twitter bot. This software is made available for unlimited modification and redistribution under the MIT License, provided that original attribution remains. The full text of the license can be found here.

Contributing

If you want to contribute to the project, open a pull request with your branch. (For reference, this is the pull request template.) If your changes modify the core function of the bot, you will need to ensure that it continues to work as expected. Below is a suggested (but not mandatory) list of functions:

Regular operation:

  • The bot successfully retrieves API keys from environmental variables and constructs the OAuth header necessary for Twitter API requests.
  • The bot successfully searches for the last applicable Tweet from itself, and from the target account, iterating through results as necessary. The accounts should not be modified for pull requests to this source code.
    • If no Tweet is found, the bot sleeps for no less than 15 seconds.
  • The bot extracts the correct website from the tweet, retrieves the HTML raw code, and converts to a usable Python format. (This requires the use of Requests and BeautifulSoup.)
  • The bot locates the alt/title text, constructs a Tweet body, and determines the number of Tweets necessary.
    • If one Tweet is necessary, the bot posts one Tweet as a reply to the target account.
    • If multiple Tweets are necessary, the bot posts multiple Tweets as replies to each other and the target account.

OAuth/HTML/Twitter API Error Handling (This is basic error handling, feel free to expand on these appropriately.):

  • A failed Twitter search or Tweet posting (HTTP status codes 420, 429 or higher) should be followed by a 5 minute wait, up to 5 attempts, and then initializing the app crash sequence.
    • Any other error in the Twitter class (ex. other HTTP status codes except 200, no Tweets found by search) should initialize the app crash sequence.
    • Additional guidance can be found in the Twitter API documentation.
  • If OAuth keys are not retrieved from environmental variables, it should initialize the app crash sequence.
  • When retrieving the HTML of a website and the HTTP status code is not 200, the app should make a total of 6 attempts with 10 second delays, followed by 4 attempts with 60 second delays, followed by starting the app crash sequence.

Bot Crash Handling:

  • Immediately return 'crash' (with the quotation marks) from the failed function (as defined in the previous section).
  • After each function is called, the main process should check if the returned value is 'crash'. If so, call teh crash() function.
  • The crash function must include the following before entering the log protection mode: print('Entering log protection mode.')
  • The crash function pings a website over a time interval less than 30 minutes, to keep the app from being disabled due to inactivity.

Make sure your bot handles everything as above, to reduce efforts needed to integrate updates in pull requests.

← Running Your Bot

Clone this wiki locally