def test_bot_1(): print("test_bot_1() <=== create a simple bot command and generate hash for command1") c1 = Bot(command1) c1.generate_hash() assert_equal(c1.command, "color") assert_equal(c1.data, "red") assert_equal(c1.hash, "5a2421317676")
def test_show_items_should_display_list_of_todo(self): bot = Bot() bot.todos.append(Todo('Тест 1', datetime.now())) bot.todos.append(Todo('Тест 2', datetime.now())) result = bot.show_items() self.assertEqual(result, 'Тест 1\nТест 2')
def test_bot_2(): print("test_bot_2() <=== create a simple bot command and generate hash for command2") c2 = Bot(command2) c2.generate_hash() assert_equal(c2.command, "xxxxxxxx") assert_equal(c2.data, "yyyyyyyyy") assert_equal(c2.hash, "5b92ee76ecdc285")
def test_bot_3(): print("test_bot_3() <=== create a simple bot command and generate hash for command3") c3 = Bot(command3) c3.generate_hash() assert_equal(c3.command, "daaaaaaaaaaaaaaaaaa") assert_equal(c3.data, "dl") assert_equal(c3.hash, "22cf35f16189ca")
def process_unseen_announcements(self): """ Process all unseen announcements """ if not self.unseen_announcements: return # public_companies = ["GWG", "GEWOFAG"] for unseen_announcement in self.unseen_announcements: apartment = unseen_announcement["resultlist.realEstate"] text = ImmoScout.prepare_apartment_notification_text(apartment) # If you are interested only in public companies uncomment the next instructions # is_public = False # if 'realtorCompanyName' in apartment: # company = apartment['realtorCompanyName'].upper() # for c in public_companies: # if company.find(c) != -1: # is_public = True # if is_public: db.insert_to_database({"hash": apartment["@id"]}, collection_name=ImmoScout.COLLECTION_NAME) bot = Bot() bot.push_notification(text=text)
def test_bot_1(): print( "test_bot_1() <=== create a simple bot command and generate hash for command1" ) c1 = Bot(command1) c1.generate_hash() assert_equal(c1.command, "color") assert_equal(c1.data, "red") assert_equal(c1.hash, "5a2421317676")
def test_bot_2(): print( "test_bot_2() <=== create a simple bot command and generate hash for command2" ) c2 = Bot(command2) c2.generate_hash() assert_equal(c2.command, "xxxxxxxx") assert_equal(c2.data, "yyyyyyyyy") assert_equal(c2.hash, "5b92ee76ecdc285")
def test_bot_3(): print( "test_bot_3() <=== create a simple bot command and generate hash for command3" ) c3 = Bot(command3) c3.generate_hash() assert_equal(c3.command, "daaaaaaaaaaaaaaaaaa") assert_equal(c3.data, "dl") assert_equal(c3.hash, "22cf35f16189ca")
def process_bayernheim_update(self): """ Update database and send notification for BayernHeim update """ db.update_in_database(self.db_obj["_id"], self.hash_obj, collection_name=BayernHeim.COLLECTION_NAME) text = BayernHeim.prepare_bayernheim_text() bot = Bot() bot.push_notification(text=text)
def create_app(config_class=Config): app = Flask(__name__) app.config.from_object(config_class) app.logger.setLevel(logging.INFO) if not config_class.TESTING and config_class.TG_TOKEN: from app.bot import Bot Bot(Config.TG_TOKEN, Config.BOT_USERS, app).start() else: print("App is not configured. Check config.py") return app
def create_app(config_class=Config): app = Flask(__name__) app.config.from_object(config_class) db.init_app(app) migrate.init_app(app, db) app.logger.setLevel(logging.INFO) if not config_class.TESTING and config_class.BOT_ENABLE and config_class.TG_TOKEN and config_class.TG_ADMIN_ID and config_class.YD_TOKEN: from app.bot import Bot Bot(Config.TG_TOKEN, Config.DOWNLOAD_FOLDER, Config.YD_TOKEN, Config.YD_DOWNLOAD_FOLDER, Config.TG_ADMIN_ID, app).start() elif config_class.SCANNER_ENABLE and config_class.YD_TOKEN: from app.uploader import Uploader Uploader(Config.YD_TOKEN, Config.YD_DOWNLOAD_FOLDER, Config.SCANNER_FOLDER, app).start() else: print("App is not configured. Check config.py") return app
def start_game(game, team_one=[], team_two=[]): g = json.loads(cache.get(game)) players = list(g['players'].keys()) for team in [team_one, team_two]: team_name = random.choice(TEAM_NAMES) g['teams'][team_name] = { 'points': 0, 'members': team, 'name': team_name } while (len(g['teams'][team_name]['members'])) < 2: bot = Bot(team=team_name) g['players'][bot.name] = {} g['teams'][team_name]['members'].append(bot.name) dealer = random.choice(players) g.update({ 'bid': {}, 'dealer': dealer, 'deck': list(CARDS.keys()), 'hands': {}, 'ok_with_next_round': [], 'play': { 'lead': [], 'played': {}, 'passed': [], 'tricks': [], }, 'play_again': [], 'played_cards': {}, 'state': 'DEAL', 'turn': dealer, }) for player in players: g['played_cards'][player] = [] cache.set(game, json.dumps(g)) return g['dealer'], g['teams']
def index(): return "OK" @app.route("/callback", methods=['GET']) def hello(): """ webhook 一開始的認證使用 """ challenge = request.args.get('hub.challenge', '') secret = request.args.get('hub.verify_token', '') print(challenge) print(secret) return challenge from app.bot import Bot bot = Bot(app) @celery.task def celery_handle_message(msg, sender, msgbody): """ 背景作業:處理每一個傳進來的訊息 """ with app.app_context(): try: # 先已讀 bot.intention_bot.bot_sender_action(sender, "mark_seen") # 然後處理 bot.handle_message(msg, sender, msgbody) except Exception as e: print(e)
from app.bot import Bot if __name__ == '__main__': Bot().run()
def run(): loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) bot = Bot(config, loop=asyncio.get_event_loop()) bot.run(config["discord"]["token"], bot=True)
"""Views used by the application""" from flask import jsonify # pylint: disable=import-error from flask import render_template from flask import request from app import APP # pylint: disable=cyclic-import from app.bot import Bot from app.forms import MessageFieldsForm from app.geo_code import GeoCode from app.parser import Parser from app.wiki_search import WikiSearch BOT = Bot() @APP.route("/", methods=["GET"]) def index(): """Landing page""" form = MessageFieldsForm() return render_template("index.html", form=form) @APP.route("/process", methods=["POST"]) def process(): """Process the user input""" content = {} if "message" in request.form and ":help" in request.form["message"]: # Display instructions if the user type :help content = BOT.instructions
from app import config from app import logging from app import util from app import NAMESPACE from app import conversation as conv FB_VERIFY_TOKEN = config.FB_VERIFY_TOKEN # broker = redis.Redis( # host=config.REDIS_HOST, # port=config.REDIS_PORT # ) broker = redis.from_url(os.environ['REDISCLOUD_URL']) bot = Bot(config.FB_ACCESS_TOKEN) log = logging.tracer(NAMESPACE) obapi = Obpy(base_url=config.OPENBIKES_API_URL) @app.route('/ping', methods=['GET']) def ping(): return jsonify({'ping': 'pong'}), 200 @app.route('/', methods=['GET']) def verify(): # When the endpoint is registered as a webhook, it must echo back # the 'hub.challenge' value it receives in the query arguments
def test_show_items_should_display_text_when_list_is_empty(self): bot = Bot() result = bot.show_items() self.assertEqual(result, 'Список пуст')
def print_botservers(): print("######## BOTSERVERS ########") for server in BOTSERVERS: print(server) print("##############################\n") print_cc_info() print_botservers() bots = [] for server in BOTSERVERS: bot = Bot(server) bots.append(bot) time.sleep(10) # Check if any bots alive while 1: cont = False for bot in bots: if bot.thread.isAlive(): cont = True if cont == False: break time.sleep(1)
def make_bot(bot_info, **kwargs): return Bot(config_file="../tests/config.yaml")
def test_ValueReturned(self): obj = Bot("bonjour") obj.stopWd() question = obj.stopWd() self.assertEqual(question, "bonjour")
import os from flask import url_for, redirect, render_template, request from app import app, db from app.bot import Bot, delete_group_by_id from app.models import Group bot = Bot(app.config['VK_AUTH_TOKEN']) @app.route('/') def index(): groups = Group.query.all() return render_template('index.html', title='index', groups=groups if groups != [] else None) @app.route('/group', methods=['POST']) def like(): group_id = request.form.get('group_id') count = request.form.get('count') bot.process_group(int(group_id), int(count)) return redirect('/') @app.route('/ungroup', methods=['POST']) def ungroup(): group_id = request.form.get('group_id') count = request.form.get('count')
import os import asyncio from dotenv import load_dotenv from app.bot import Bot from app.database import Database load_dotenv() TOKEN = os.getenv("TOKEN") database = Database( "dbname", "dbuser", "dbpassword" ) bot = Bot( database=database, command_prefix="!" ) if __name__ == "__main__": loop = asyncio.get_event_loop() loop.run_until_complete(database.open()) bot.run(TOKEN)
import random from app.config import NUMBER_OF_USERS, MAX_LIKES_PER_USER, MAX_POSTS_PER_USER from app.bot import Bot from app.user import User bot = Bot() users = [] posts = [] likes = [] def run(): global users, posts, likes print('STAGE: user creation') while len(users) < NUMBER_OF_USERS: userdata = bot.generate_userdata() data = bot.create_user(userdata).json() auth_data = bot.login_user(userdata).json() user = User(userdata | data, auth_data.get('token')) users += [user] print(user.data) print('-' * 50) print('STAGE: posts creation')
from app.bot import Bot bot = Bot() bot.run()