Skip to content

Instantly share code, notes, and snippets.

@MarcoBuster
Created July 27, 2017 09:31
Show Gist options
  • Save MarcoBuster/a17f19e9100049fe78d3e1a1c526aaf6 to your computer and use it in GitHub Desktop.
Save MarcoBuster/a17f19e9100049fe78d3e1a1c526aaf6 to your computer and use it in GitHub Desktop.
# Copyright (c) 2017 Marco Aceti. All rights reserved.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import config
import twitter
import botogram
import redis
api = twitter.Api(
consumer_key=config.CONSUMER_KEY,
consumer_secret=config.CONSUMER_SECRET,
access_token_key=config.ACCESS_TOKEN_KEY,
access_token_secret=config.ACCESS_TOKEN_SECRET
)
bot = botogram.create(config.BOT_TOKEN)
r = redis.StrictRedis(
host=config.REDIS_HOST,
port=config.REDIS_PORT,
db=config.REDIS_DB,
password=config.REDIS_PASSWORD
)
user_id = api.GetUsersSearch(config.TWITTER_USERNAME)[0].id
tweets = api.GetUserTimeline(user_id)
def send(tweet):
bot.chat(config.CHAT).send(tweet.text)
def check(tweet):
last_id = int(r.get("last_tweet_ultimora").decode("utf-8"))
if last_id != tweet.id:
send(tweet)
r.set("last_tweet_ultimora", int(tweet.id))
if __name__ == "__main__":
check(tweets[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment