Releases: jessicarod7/XKCDAltTextBot
2.0.0
The Customization Update
After months of planning, version 2.0.0 is now live! This update makes the XKCDAltTextBot porgram a truly customizable program, with a new configuration file to replace the old method of hunting through the source code. It even works with Heroku, thanks to a new, smaller program packaged with the Twitter bot.
Note: this update is not compatible with previous versions of XKCDAltTextBot. It is strongly recommended to replace your current setup with the new bot for simplicity. Just replace the existing files with the new ones, no previous changes to the code need to be kept.
To learn more, check out the updated Wiki.
1.9.0
This is the latest (last?) attempt at a fix for the XKCDAltTextBot retweet issue. This time, the idea is to double-check that a Tweet is new. All updates are below:
- Add the following code before line 219 and tab all following code to the right:
new_tweet_check = None
for i in range(2):
- On the new line 229 replace
continue
withbreak
. - Add the following code before the new line 231 and tab all following code to the right:
if new_tweet_check is None: # Unverified new Tweet
new_tweet_check = original_tweet
print('Potential new comic. Waiting 15 seconds to verify...')
continue
elif new_tweet_check == original_tweet: # Confirmed new Tweet
1.8.2
1.8.2 updates the urllib3 library, which previously contained a security vulnerability. Current users should replace Pipfile.lock and requirements.txt as soon as possible.
1.8.1
This minor update catches a missing exception.
- Replace line 79 with the following:
except ValueError: # Supposedly valid comment
- Add the following after line 74:
try:
1.8.0
This update replaces the 1.7.0 duplicate Tweet fix with a more effective method. You will need to replace the Pipfile, Pipfile.lock, and requirements.txt files. Updates are as follows:
- Remove lines 7-9.
- Replace lines 75-100 (formerly 78-103):
if alt_replies.index(comic['statuses'][0]['id']) is not ValueError:
# This tweet has already been replied to
del alt_payload, comic_payload, alt_raw, comic_raw, alt, comic
return None # Sleep for 15 seconds
else: # Supposedly valid Tweet
return comic['statuses'][0] # Return comic Tweet
- Add after line 106 (formerly line 128):
if tweet.json()['errors'][0]['code'] == 187: # Duplicate Tweet
print('Duplicate Tweet detected, ending attempt.')
return None
- Remove blank line 237 (formerly 257).
1.7.2
Well, this is embarrassing. The final fix to the 1.7 update is below and painfully obvious:
Update line 98 to the following:
del alt_payload, comic_payload, alt_raw, comic_raw, alt
And add this line after line 99:
del comic
🤦
1.7.1
This minor update introduces time adjustments for UTC. The fixes are below.
- Replace line 95 with the following:
# Twitter API adds 3 hours for some painful reason
tweet_time = time.mktime(tweet_time_str.timetuple()) - 10800
- Replace lines 99-100, formerly lines 98-99:
if time.mktime(datetime.datetime.utcnow().timetuple()) - tweet_time > 43200:
return None # Cancel Tweet attempt
[BROKEN] 1.7.0
THIS UPDATE DOES NOT WORK, PLEASE DO NOT INSTALL.
This major update institutes a 12 hour limit on replies from the Twitter bot. This should reduce incidents of the bot replying to an old Tweet when the bot's own reply is not surfaced by Twitter search.
The following section will explain the necessary changes and should only be used if you are updating an existing bot.
You must replace the Pipfile, Pipfile.lock, and requirements.txt files, as the bot now uses the dateutil module. Then make the following changes in the bot code:
- Add the following imports:
import datetime # Cancels Tweet if older than 12 hours
import calendar # Converts calendar abbreviation to integer
from dateutil.tz import gettz # Switches to UTC in recent Tweet check
- Replace lines 84-86 (formerly lines 81-83) with the following code, replacing variable names as needed:
# This tweet does not appear in the search results, check if <12 hrs
tweet_time_str = datetime.datetime(
int(comic['statuses'][0]['created_at'][-4:]),
list(calendar.month_abbr).index(comic['statuses'][0]['created_at'][4:7]),
int(comic['statuses'][0]['created_at'][8:10]),
int(comic['statuses'][0]['created_at'][11:13]),
int(comic['statuses'][0]['created_at'][14:16]),
int(comic['statuses'][0]['created_at'][17:19]),
0,
gettz('UTC')
)
tweet_time = time.mktime(tweet_time_str.timetuple())
del alt_payload, comic_payload, alt_raw, comic_raw, alt, comic
if time.time() - tweet_time > 43200: # Cancel Tweet attempt
return None
else:
return comic['statuses'][0] # Return comic Tweet
1.6.0
This latest release adds support for regular tweets, by removing a check that your latest tweet is a reply. It also provides a fix for a bug requiring the bot to start on an account that already had a Tweet.
Remove line 67 and update line 66 to the following, modifying to your own variables:
if comic['statuses'][0]['id'] is None:
Then update lines 80-81 (formerly 81-82):
except (ValueError, NameError):
# This tweet has not been replied to or no tweets have been posted yet
1.5.1
This release fixes a bug that causes the bot to crash if it does not find a new Tweet. Replace lines 76-83 with the following, modifying as needed:
try:
if alt_replies.index(comic['statuses'][0]['id']) is not ValueError:
# This tweet has already been replied to
del alt_payload, comic_payload, alt_raw, comic_raw, alt, comic
return None # Sleep for 15 seconds
except ValueError:
# This tweet has not been replied to
del alt_payload, comic_payload, alt_raw, comic_raw, alt
return comic['statuses'][0] # Return comic Tweet