-
Notifications
You must be signed in to change notification settings - Fork 2
Different Websites
Once you have the main changes prepared, there are still a few changes that need to be made in order to get the bot working with another Twitter account and website. For optimal performance, this bot works best on another bot that only posts automatically, that links to a website with a consistent layout of photos.
The XKCDAltTextBot account searches for the most recent Tweet, and then grabs the first link in the Tweet body and uses that to access the website. If the account you are following sends the link to the website that you need after 1 or more other links, make the following change on line 233:
[body, num_tweets] = retrieve_text(original_tweet['entities']['urls'][X]['expanded_url'])where X represents one less than the position of the required link. For more information, view the Twitter API documentation for search.
By default, the XKCDAltTextBot access the alt/title text from the first image with title text. However, some sites may have multiple photos which fit this description. To specify the photo to use, you will need to determine where it always falls.
Ensure that BeautifulSoup and Requests are installed on your system, and then open the command line. With an example webpage of the format you expect as SITE, enter the following commands:
html_raw = requests.get(SITE)
html = BeautifulSoup(html_raw.text, 'html.parser')
html.find_all('img', title=True)This command will output a list of photos with title text. Once you find the image you would like to use, note its location within the list. Then, open up the source code for the bot, and with X as one less than that position, make the following change on line 190:
comic = html.find_all('img', title=True)and on line 195:
title = comic[X]['title']The bot will now use the title text from this photo. For more information, view the BeautifulSoup documentation
Your bot is now operational for your website and account. Next, we'll change how it appears to users. If there are other modifications you'd like to make, you might find some tips in the next section as well.