Skip to content

Commit

Permalink
Merge 40b9908 into 6278b01
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Oct 14, 2018
2 parents 6278b01 + 40b9908 commit 02171f7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
21 changes: 15 additions & 6 deletions everywordbot.py
Expand Up @@ -8,7 +8,8 @@ def __init__(self, consumer_key, consumer_secret,
access_token, token_secret,
source_file_name, index_file_name,
lat=None, long=None, place_id=None,
prefix=None, suffix=None, bbox=None):
prefix=None, suffix=None, bbox=None,
dry_run=False):
self.source_file_name = source_file_name
self.index_file_name = index_file_name
self.lat = lat
Expand All @@ -17,6 +18,7 @@ def __init__(self, consumer_key, consumer_secret,
self.prefix = prefix
self.suffix = suffix
self.bbox = bbox
self.dry_run = dry_run

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, token_secret)
Expand Down Expand Up @@ -60,10 +62,13 @@ def post(self):
if self.bbox:
self.lat, self.long = self._random_point_in(self.bbox)

self.twitter.update_status(status=status_str,
lat=self.lat, long=self.long,
place_id=self.place_id)
self._increment_index(index)
if self.dry_run:
print(status_str)
else:
self.twitter.update_status(status=status_str,
lat=self.lat, long=self.long,
place_id=self.place_id)
self._increment_index(index)


def _csv_to_float_list(csv):
Expand Down Expand Up @@ -109,12 +114,16 @@ def _get_comma_separated_args(option, opt, value, parser):
parser.add_option('--suffix', dest='suffix',
help="string to add to the end of each post "
"(if you want a space, include a space)")
parser.add_option('-n', '--dry_run', dest='dry_run', action='store_true',
help="Do everything except actually send the tweet or"
"update the index file")
(options, args) = parser.parse_args()

bot = EverywordBot(options.consumer_key, options.consumer_secret,
options.access_token, options.token_secret,
options.source_file, options.index_file,
options.lat, options.long, options.place_id,
options.prefix, options.suffix, options.bbox)
options.prefix, options.suffix, options.bbox,
options.dry_run)

bot.post()
17 changes: 17 additions & 0 deletions test/test_everywordbot.py
Expand Up @@ -181,6 +181,23 @@ def test__csv_to_float_list(self):
self.assertEqual(float_list,
[59.811225, 20.623165, 70.07531, 31.569525])

def test__dry_run(self):
# Arrange
bot = EverywordBot("consumer_key", "consumer_secret",
"access_token", "token_secret",
"test/test_source.txt", "test/test_index.txt",
dry_run=True)
stub = TwitterStub()
bot.twitter.update_status = stub.twitter_update_status
index_before = bot._get_current_index()

# Act
bot.post()

# Assert
index_after = bot._get_current_index()
self.assertEqual(index_before, index_after)


if __name__ == '__main__':
unittest.main()
Expand Down

0 comments on commit 02171f7

Please sign in to comment.