Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to work with Twitter API v2 #11

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ dist
*.shx
*.dbf
*.shp.xml
bots.yaml
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Updated to use Twitter API v2 endpoint for sending the tweet.
Now uses tweepy 4.0 and up.
twitter bot utils 0.14


# every lot bot

This library supports a Twitter bot that posts Google Streetview pictures of every property in an SQLite database.
Expand Down
2 changes: 1 addition & 1 deletion everylot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@

from . import everylot

__version__ = '0.3.1'
__version__ = '0.3.2'
__all__ = ['everylot']
25 changes: 22 additions & 3 deletions everylot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import twitter_bot_utils as tbu
from . import __version__ as version
from .everylot import EveryLot
import tweepy
from twitter_bot_utils.confighelper import configure


def main():
Expand All @@ -34,6 +36,16 @@ def main():

args = parser.parse_args()
api = tbu.api.API(args)

config = configure(args.screen_name)
consumer_key = config["consumer_key"]
consumer_secret = config["consumer_secret"]
access_token = config.get("token", config.get("key", config.get("oauth_token")))
access_token_secret = config.get("secret", config.get("oauth_secret"))
client = tweepy.Client(
consumer_key=consumer_key, consumer_secret=consumer_secret,
access_token=access_token, access_token_secret=access_token_secret
)

logger = logging.getLogger(args.screen_name)
logger.debug('everylot starting with %s, %s', args.screen_name, args.database)
Expand All @@ -55,17 +67,24 @@ def main():
# ("sv.jpg" is a dummy value, since filename is a required parameter).
image = el.get_streetview_image(api.config['streetview'])
media = api.media_upload('sv.jpg', file=image)

# compose an update with all the good parameters
# including the media string.
update = el.compose(media.media_id_string)
logger.info(update['status'])

if not args.dry_run:
logger.debug("posting")
status = api.update_status(**update)
response = client.create_tweet(
text=update['status'],
media_ids=[media.media_id_string]
)

# Extract the id from the response
tweet_id = response.data['id']

try:
el.mark_as_tweeted(status.id)
el.mark_as_tweeted(tweet_id)
except AttributeError:
el.mark_as_tweeted('1')

Expand Down
8 changes: 5 additions & 3 deletions everylot/everylot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/env python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of everylotbot
# Copyright 2016 Neil Freeman
Expand Down Expand Up @@ -69,7 +69,7 @@ def __init__(self, database,

def aim_camera(self):
'''Set field-of-view and pitch'''
fov, pitch = 65, 10
fov, pitch = 69, 10
try:
floors = float(self.lot.get('floors', 0)) or 2
except TypeError:
Expand All @@ -92,7 +92,9 @@ def aim_camera(self):

if floors >= 10:
fov, pitch = 90, 30


if floors >= 99:
fov, pitch = 130, -15
return fov, pitch

def get_streetview_image(self, key):
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
license='GPL-3.0',
include_package_data=False,
install_requires=[
'twitter_bot_utils>=0.11.5,<=0.12',
'twitter_bot_utils>=0.11.5,<=0.14', # Updated to 0.14
'tweepy>=4.0.0'
],

entry_points={
'console_scripts': [
'everylot=everylot.bot:main',
Expand Down