Skip to content
This repository has been archived by the owner on Dec 23, 2023. It is now read-only.

Commit

Permalink
Use a configured name for a variable location with no Twitter place
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianMitchL committed Apr 22, 2018
1 parent e725755 commit e8a5ef9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -61,7 +61,7 @@ The language as well as the text used for all tweets can be edited or added in `

### Variable Location
Enable variable location to have the location for weather change. The Twitter username in the variable location user setting will be used to determine this location. The specified user must tweet with location fairly regularly (at least every 20 tweets, not including retweets), or the manually entered location will be used. The most recent tweet with a location will be used to get the location for weather.
For example, say the given user tweets from Minneapolis, MN one day. Minneapolis will be used as the location indefinitely until a new tweet with location is posted or if 20 new tweets have been posted that do not contain a location. weatherBot checked the user's timeline every 30 minutes for updated in location.
For example, say the given user tweets from Minneapolis, MN one day. Minneapolis will be used as the location indefinitely until a new tweet with location is posted or if 20 new tweets have been posted that do not contain a location. weatherBot checks the user's timeline every 30 minutes for updates in location.
The human readable Twitter location will also be added to the beginning of each tweet. For example, in the same case as earlier, "Minneapolis, MN: " would be prefixed to every tweet.

## Deploying to [Heroku](https://www.heroku.com/)
Expand Down
3 changes: 3 additions & 0 deletions weatherBot.conf
Expand Up @@ -45,6 +45,9 @@
[variable location]
;enabled = no
;user = BrianMitchL
# some locations have coordinates but do not contain any Twitter place information
# this will be used as a fallback
;unnamed-location-name = The Wilderness

[log]
# write log to file
Expand Down
10 changes: 8 additions & 2 deletions weatherBot.py
Expand Up @@ -65,7 +65,8 @@ def load_config(path):
name=conf['default location'].get('name', 'Morris, MN')),
'variable_location': {
'enabled': conf['variable location'].getboolean('enabled', False),
'user': conf['variable location'].get('user', 'BrianMitchL')
'user': conf['variable location'].get('user', 'BrianMitchL'),
'unnamed_location_name': conf['variable location'].get('unnamed-location-name', 'The Wilderness')
},
'log': {
'enabled': conf['log'].getboolean('enabled', True),
Expand Down Expand Up @@ -179,7 +180,11 @@ def get_location_from_user_timeline(username, fallback):
if tweet.coordinates is not None:
lat = tweet.coordinates['coordinates'][1]
lng = tweet.coordinates['coordinates'][0]
name = tweet.place.full_name
name = CONFIG['variable_location']['unnamed_location_name']
# sometimes a tweet contains a coordinate, but is not in a Twitter place
# for example, https://twitter.com/BrianMitchL/status/982664157857271810 has coordinates, but no place
if tweet.place is not None:
name = tweet.place.full_name
logging.debug('Found %s: %f, %f', name, lat, lng)
return models.WeatherLocation(lat=lat, lng=lng, name=name)
# if the location is a place, not coordinates
Expand Down Expand Up @@ -429,6 +434,7 @@ def main(path):
api.send_direct_message(screen_name=api.me().screen_name,
text=str(random.randint(0, 9999)) + traceback.format_exc())


if __name__ == '__main__':
parser = argparse.ArgumentParser(description='weatherBot')
parser.add_argument('conf', metavar='conf', type=str, help='The configuration file')
Expand Down

0 comments on commit e8a5ef9

Please sign in to comment.