def setUpClass(cls): if (os.environ["TRAVIS_SECURE_ENV_VARS"] == "true"): cls.test_api = True API_KEY_TEST = os.environ["API_KEY_TEST"] API_SECRET_TEST = os.environ["API_SECRET_TEST"] ACCESS_TOKEN_TEST = os.environ["ACCESS_TOKEN_TEST"] ACCESS_TOKEN_SECRET_TEST = os.environ["ACCESS_TOKEN_SECRET_TEST"] cls.test_string = "Test string: " + datetime.now().isoformat() cls.bot_test = TwitterBot("", [[cls.test_string]], API_KEY_TEST, API_SECRET_TEST, ACCESS_TOKEN_TEST, ACCESS_TOKEN_SECRET_TEST) else: cls.test_api = False
""" A simple web server to execute the bot functions """ import os from flask import Flask, jsonify from flask_httpauth import HTTPTokenAuth from hashlib import blake2b from twitter import get_api from bot import TwitterBot bot = TwitterBot(get_api()) app = Flask(__name__) auth = HTTPTokenAuth(scheme='Token') @auth.verify_token def verify_token(token): token_hash = blake2b(bytes(token, encoding='utf8')).hexdigest() return token_hash == os.environ['TOKEN_HASH'] @app.route('/') def index(): """ Return total number of tweets bot has tweeted so far """ return jsonify({ 'num_tweets': bot.get_num_tweets(),
def main(): bot = TwitterBot() bot.run()
## %cd ~/twitter-bots-smw-2016/ import re from bot import TwitterBot bot1 = TwitterBot('test1') def strip_links(text): text = re.sub(r"http\S+", "", text, flags=re.MULTILINE) return text.encode('ascii', 'ignore').lower().strip() tl = tw.GetUserTimeline(screen_name='KanyeWest', count=200) f = open('data/kanye/tweets.txt', 'ab') while len(tl) > 1: for t in tl: max_id = t.id print max_id f.write(strip_links(t.text)) f.write('\n') tl = tw.GetUserTimeline(screen_name='KanyeWest', count=200, max_id=max_id)
from bot import TwitterBot from message import Message from config import * from pathlib import Path from timer import Timer import os import subprocess MAX_SIZE = 3072 bot = TwitterBot(API_KEY, API_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET) os.chdir('media') # Delete any '.DS_Store files' subprocess.run(["find", ".", "-name", ".DS_Store", "-delete"]) for gif in os.listdir('.'): # Get the size of the file gif_size = (Path(gif).stat().st_size) // 1000 print("{} ({} kb)".format(gif, gif_size)) if os.path.isdir(gif): print("Not a .GIF, skipping.") elif gif_size > MAX_SIZE: print("File size is over limit by {} kb".format(gif_size - MAX_SIZE)) # Move file to Resize folder. print("Moving {:s} to resize directory\n".format(gif)) os.rename(gif, os.path.join("resize", gif)) else: bot.tweet(Message().body, gif)
from bot import TwitterBot bot = TwitterBot(cashtag=["bitcoin"]) bot.run()